css:层叠样式表
css书写规范:
选择器{ 属性名:属性值; 属性名:属性值; } |
(尽量使用外部样式(简洁、清楚、易查询))
1.命名.css 2.在css中写入内容 div{ ... } 3.引入html中
|
标签选择器:选择当前页面中所有符合的标签 id选择器,#id值 类选择器,class(类),·class类名 *通配符选择器,选中所有元素 |
Document
/* 子代选择器 */
ul>li{
background-color: aliceblue;
}
/* 后代选择器 */
ul li{
background-color: aliceblue;
}
div,
p,
h1{
background-color: aliceblue;
}
/* 设相同属性,将元素逗号隔开 */
/* type为text的input */
input[type="text"]{
background-color: aliceblue;
}
/* 具有name属性的 */
input[name]{
background-color: aliceblue;
}
/* type中包含e的 */
input[type*="e"]{
background-color: aliceblue;
}
/* type中以p开头的 */
input[type^="p"]{
background-color: aliceblue;
}
/* type中以l结尾的 */
input[type$="l"]{
background-color: aliceblue;
}
/* 1.未访问的链接样式 */
a:link{
color: aliceblue;
}
/* 2.访问后的样式 */
a:visited{
color: aliceblue;
}
/* 3.鼠标悬停时的样式 */
a:hover{
color: aliceblue;
}
/* 4.点击之后按住鼠标不松 */
a:active{
background-color: aliceblue;
}
/* 获取焦点时的样式<按住tab键> */
a:focus{
color: aliceblue\;
}
/* 通过鼠标悬停ac从而改变div的样式
+表示下一个
~表示之后所有兄弟元素*/
a:hover+div{
color: pink;
}
/* ul在li上的第7个孩子 */
ul li:nth-child(7){
background-color: aliceblue;
}
/* 最后一个孩子 */
ul li:last-child{
background-color: aliceblue;
}
/* 第一个孩子 */
ul li:first-child{
background-color: aliceblue;
}
/* 顺序为奇数的孩子 */
ul li:nth-child(2n+1){
background-color: aliceblue;
}
/* 顺序为偶数的孩子 */
ul li:nth-child(2n){
background-color: aliceblue;
}
/* 1.父亲 2.排序 3.儿子 */
.father.son:nth-child(2){
background-color: aliceblue;
}
/* 1.父亲 2.儿子 3.排序 */
.father.son:nth-of-type(2){
background-color: aliceblue;
}
/* 在p前添加内容及颜色 */
p::before{
content: "";
color: aliceblue;
}
/* 对提示语的改变 */
input::placeholder{
color: aliceblue;
}
/* 选中后颜色的改变 */
div::selection{
color: aliceblue;
}
p{
/* 字体大小/字号 */
font-size: 12px;
/* 字体类型 */
font-family: "宋体";
/* 字体的粗细:normal/400(正常),bold/700(加粗) */
font-weight: 400;
/* 字体样式(倾斜) */
font-style: italic;
/* 复式写法 style weight (size family)必要 */
font:italic 700 20px '宋体';
}
span{
/* 文本的对齐方式:水平居中 */
text-align: center;
/* 显示形式转化成行内块元素(才能进行上述的对其方式) */
display: block;
}
/* 文本的修饰 none(不修饰),line-through(删除线),underline(下划线),overline(上边线) */
a{
text-decoration: none;
}
/* 小写转大写uppercase,大写转小写lowercase */
ul li:nth-child(1){
text-transform: uppercase;
}
/* 可通过设置行高进行垂直居中的操作,(单行文本借助行高垂直居中) */
p{
line-height: 50px;
}
div{
width: 200px;
height: 200px;
background-color: aliceblue;
/* Y轴滚轮 */
overflow: auto;
/* 隐藏滚轮 */
overflow: hidden;
/* Y+X轴的滚轮均有 */
overflow: scroll;
/* 单行文本加省略号 */
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
body{
width: 200px;
height: 200px;
background-color: aliceblue;
/* 平铺背景图片(可重复) */
background-image: url(./...);
/* 不重复平铺 */
background-repeat: no-repeat;
/* 固定不动 */
background-attachment: fixed;
/* 沿右下角显示图片 */
background-position: right bottom;
/* 强行占满 */
background-size: cover;
/* 复合要求非强制性的顺序 */
background: pink url(./...) no-repead fixed right bottom;
}
/* 建立无序列表(十行)简写:ul>li*10{li$} */
li{
/* 去掉默认形式 */
list-style: none;
/* 数字 */
list-style: decimal;
/* 小圆点 */
list-style: disc;
/* 空心小圆点 */
list-style: circle;
/* 实心正方形 */
list-style: square;
}
input{
/* *******轮廓线的形式(取消轮廓线)******* */
outline-style: none;
/* 双划线double,虚线dash,点状轮廓dotted */
/* 轮廓线的颜色 */
outline-color: aqua;
/* 轮廓线的厚度(加厚) */
outline-width: thick;
/* 常用写法 */
outline: none;
}
div{
width: 200px;
height: 200px;
background-color: aliceblue;
/* 边框宽度 */
border-width: 3px;
/* 边框颜色 */
border-color: aliceblue;
/* 边框样式 */
border-style: solid;
/* 边框角的弧度(百分比/数字) */
border-top-left-radius: 50%;
}
table{
/* 合并相邻边框 */
border-collapse: collapse;
}
/* 前景色(字体颜色) */
p{
/* 普通版 */
color: red;
/* 三原色调色版 */
color:rgb(rgb(150, 94, 94), rgb(94, 153, 94), blrgb(75, 75, 127)
}
/* 背景色(高级版):三原色调色,alpha(透明通道)0~1 */
div{
background-color: rgba(rgb(199, 133, 133), rgb(121rgb(88, 88, 174)9, 121), blue, 0.1);
opacity: 0.3;/* 透明度调节(0-1)隐藏后保留原位 */
}
/* 1.设置透明度隐藏(保留原来的位置) */
opacity:0;
/* 2.display控制元素的显示与隐藏(也可用来转化元素的显示方式)(不保留原来的位置) */
display : none ;
/* 3.visibility:hidden;(保留原来的位置) */
visibility:hidden;
textarea{
/* 文本防拖拽 */
resize: none;
/* 鼠标样式(手指) */
cursor:pointer
}
绝对定位会放弃原来的位置,子代逐级查找父级元素是否有相对定位,如果有,以父亲为参考,如果没有,继续向上查找 father -->grandfather -->浏览器 绝对定位将元素固定在相对于其位置最近的祖先 |
.son{
/* 绝对定位,放弃原来位置,脱离文档流 */
position: absolute;
top: 50px;
background-color: aliceblue;
}
.father{
/* 相对定位 */
position: relative;
}
盒子大小:由content内容、padding外边距、border边框决定
Document
1
(内容距离边框的距离)
Document
1
Document
我是盒子的内容区域,你是谁?
我是盒子的内容区域,你是谁?
我是盒子的内容区域,你是谁?