css样式集
css样式
# 设置边框有阴影(立体感)
width: 200px;
height: 200px;
border: 2px solid #ccc;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
# 让元素居中对齐,并具有换行效果
margin-left: 5%;
margin-top: 1%;
height: 10vh;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
/* width: 51%; */
/* align-content: space-around; */
# 元素居中对齐
margin: 0 auto;
# 元素背景图片全屏适配
height: 100vh;
width: 100%;
background-image: url("图片地址");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
overflow: hidden;
# 禁止文字换行
width: auto;
white-space: nowrap;
# 相对定位
.relative-box {
position: relative;
top: 20px;
left: 30px;
background-color: red;
width: 200px;
height: 100px;
}
# 固定定位
.fixed-box {
position: fixed;
top: 0;
right: 0;
background-color: lightcoral;
width: 150px;
height: 80px;
}
# 让按钮固定在当前页面的最下面
.dialog_body {
height: 50vh;
position: relative; // 1.设置元素相对定位
.button_area {
background-color: antiquewhite;
width: 100%;
position: absolute; // 2.绝对定位
bottom: 2px;
}
}
# 布局常用样式属性
width 设置元素(标签)的宽度,如:width:100px;
height 设置元素(标签)的高度,如:height:200px;
background 设置元素背景色或者背景图片,如:
background:gold; 设置元素的背景色,
background: url(images/logo.png); 设置元素的背景图片-图片来源于本地。
background-image : url("图片地址"); 设置元素的背景图片-图片来源于url
border 设置元素四周的边框,如:border:1px solid black; 设置元素四周边框是1像素宽的黑色实线
以上也可以拆分成四个边的写法,分别设置四个边的:
border-top 设置顶边边框,如:border-top:10px solid red;
border-left 设置左边边框,如:border-left:10px solid blue;
border-right 设置右边边框,如:border-right:10px solid green;
border-bottom 设置底边边框,如:border-bottom:10px solid pink;
# 文本常用样式属性
color 设置文字的颜色,如: color:red;
font-size 设置文字的大小,如:font-size:12px;
font-family 设置文字的字体,如:font-family:'微软雅黑';为了避免中文字不兼容,
一般写成:font-family:'Microsoft Yahei';
font-weight 设置文字是否加粗,如:font-weight:bold; 设置加粗 font-weight:normal 设置不加粗
line-height 设置文字的行高,如:line-height:24px; 表示文字高度加上文字上下的间距是24px,
也就是每一行占有的高度是24px
text-decoration 设置文字的下划线,如:text-decoration:none; 将文字下划线去掉
text-align 设置文字水平对齐方式,如text-align:center 设置文字水平居中
text-indent 设置文字首行缩进,如:text-indent:24px; 设置文字首行缩进24px
white-space: nowrap; 设置文字不换行
# 可进行上下拖动改变容器高度
.dialogSearchIncomeChangeBody {
position: relative;
#myChart {
height: 500px;
min-height: 200px;
max-height: 800px;
resize: vertical;
overflow: hidden;
}
.resize-handle {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 10px;
background-color: #ccc;
cursor: ns-resize;
z-index: 100;
}
}
#myChart 是一个固定宽高但可垂直缩放的容器,高度默认 500px,允许用户上下拖动调整其高度,且内容超出时隐藏。
.resize-handle 是位于容器底部的可拖动区域,外观为浅灰色条,提示用户可通过该条上下拖动改变容器高度。
选择标签
# 一、 :first-child 选择第一个子元素
# :first-child 选择第一个子元素 ;选中每个 <tr>中的第一个 <td>和第一个 <th>
td:first-child,
th:first-child {
position: sticky;
left: 0;
background-color: #FFFFFF;
z-index: 1;
}
# 示例
<table>
<tr>
<td>固定列</td> <!-- 被选中 -->
<td>可滚动列</td>
<td>可滚动列</td>
</tr>
<tr>
<td>固定列</td> <!-- 被选中 -->
<td>可滚动列</td>
<td>可滚动列</td>
</tr>
</table>
# 二、 :nth-child() 选择特定位置的子元素
# :nth-child() 选择特定位置的子元素;选择父元素内第n个子元素(n从1开始计数)
# :nth-child(2):选中每个 <tr>中的第二个单元格
# :nth-child(3):选中每个 <tr>中的第三个单元格
th:nth-child(2),
td:nth-child(2) {
width: 50px;
min-width: 40px;
}
th:nth-child(3),
td:nth-child(3) {
width: 100px;
min-width: 40px;
}
# 示例
<table>
<tr>
<td>固定列</td>
<td>宽度50px</td> <!-- :nth-child(2) -->
<td>宽度100px</td> <!-- :nth-child(3) -->
</tr>
</table>
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。
文章标题:css样式集
本文作者:伟生
发布时间:2024-08-25, 22:01:12
最后更新:2025-10-12, 15:31:56
原始链接:http://yoursite.com/2024/08/25/qianduan_10_css/版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。