? @copyright:wangchao
内联样式表
内部样式表
内联样式 不推荐
<p class="paragraph" id="para1"> Lorem </p>
标签选择器
p{
color:red;
}
类选择器
.paragraph{
color:red;
}
ID选择器,id是唯一的
#para1{
color:red;
}
全局选择器 *
*{
color:bule;
}
组合选择器
p .firstPar{
color:green;
}
继承选择器
h1 strong{
color:bule;
}
子选择器
body>p{
color:bule;
}
相邻兄弟选择器: 只有一个,相邻(向下)
.active + p{
color:bule;
}
通用兄弟选择器:当前选中的元素的向下的所有兄弟元素
.active~p{
color:bule;
}
未访问链接(link)、已访问链接(visited)、激活链接(active)、鼠标停留在连接上(hover)。
选择ul标签的第一个子元素
ul li:first-child{
background:##ff0000;
}
选择ul标签的最后一个子元素
ul li:last-child{
background:##ff0000;
}
定位父元素,选择当前第n个元素
选择当前p元素的父级元素,选中父级元素的第一个,并且是当前元素才生效
p:nth-child(n){
background:##ff0000;
}
选择父元素,下的p元素的第二个,类型
p:nth-of-type(n){
background:##ff0000;
}
-----------------------------------------------------------------------
Odd 和 even 是可用于匹配下标是奇数或偶数的子元素的关键词(第一个子元素的下标是 1)。
在这里,我们为奇数和偶数 p 元素指定两种不同的背景色:
p:nth-child(odd)
{
background:#ff0000;
}
p:nth-child(even)
{
background:#0000ff;
}
-----------------------------------------------------------------------
使用公式 (an + b)。描述:表示周期的长度,n 是计数器(从 0 开始),b 是偏移值。
在这里,我们指定了下标是 3 的倍数的所有 p 元素的背景色:
p:nth-child(3n+0)
{
background:#ff0000;
}
-----------------------------------------------------------------------
选择包含id属性的元素
a[id]{
background:#ff0000;
}
选择id等于first的元素
a[id=first]{
background:#ff0000;
}
选择a标签中class为links的元素
= 绝对等于
*= 包含等于
a[class*="links"]{
background:#ff0000;
}
^= 以这个开头
a[herf^=http]{
background:#ff0000;
}
$= 以这个结尾
a[herf$=pdf]{
background:#ff0000;
}
字体样式
font-family:楷体;
字体大小
font-size:50px;
em(1em等于一个字 体大小的缩进)
字体粗细
font-weight:bold;
字体颜色
color:#a13d30;
-------------------------
font:oblique bolder 12px "楷体";
或者
font:bolder 12px "楷体";
设置颜色
color:rgba(0,255,255,0.9);
排版:居中
text-align:center;
首行缩进
text-indent:2em;
行高,和 块的高度一致,就可以上下居中
text-height:300px
划线
下划线
text-decoration:underline;
中划线
text-decoration:line-through;
上划线
text-decoration:overline;
超链接去下划线
a{
text-decoration:none;
}
文本图片水平对齐
img,span{
vertical-align:middle;
}
鼠标悬浮的颜色
a:hover{
color:roange;
}
鼠标按住未释放的状态
a:active{
color:green;
}
文本阴影
阴影颜色,水平偏移,垂直偏移,阴影半径
text-shadow:#3cc7f5 10px 10px 10px;
none:去掉圆点
circle:空心圆
decimal:有序列表
square:正方形
list-style:none;
ul li{
height:30px;
list-style:none;
text-indent:1em;
}
背景:默认平铺
background-image:url("images/tx.jpg");
水平平铺
background-repeat:repeat-x;
垂直平铺
background-repeat:repeat-y;
不平铺
background-repeat:no-repeat;
---------------------------------------
颜色,图片,图片位置,平铺方式
background-image:red url("images/tx.jpg") 270px 10px no-repeat;
background-color: #D9AFD9;
background-image: linear-gradient(0deg, #D9AFD9 0%, #97D9E1 100%);
属性设置一个元素所有外边距的宽度,或者设置各边上外边距的宽度
margin:10px 5px 15px 20px; 上右下左
margin:10px 5px 15px; 上左右下
margin:10px 5px; 上下左右
margin:10px; 上下左右
--------------------------------------------------------
妙用:盒子居中
margin:0 auto;
padding 简写属性在一个声明中设置所有内边距属性。
padding:10px 5px 15px 20px; 上右下左
padding:10px 5px 15px; 上左右下
padding:10px 5px; 上下左右
padding:10px; 上下左右
可以按顺序设置如下属性:
初始化:body总有一个默认的外边距margin:0 常见操作
h1,ul,li,a,body{
margin:0;
padding:0;
text-decoration:none;
}
-------------------------------------------------------------------
border 简写属性在一个声明设置所有的边框属性。
p{
border:5px solid red;
}
border-style:
none 定义无边框。
hidden 与 "none" 相同。不过应用于表时除外,对于表,hidden 用于解决边框冲突。
dotted 定义点状边框。在大多数浏览器中呈现为实线。
dashed 定义虚线。在大多数浏览器中呈现为实线。
solid 定义实线。
double 定义双线。双线的宽度等于 border-width 的值。
border-style:dotted solid double dashed; 上右下左
border-style:dotted solid double; 上左右下
border-style:dotted solid; 上下左右
border-style:dotted; 上下左右
margin + border + padding + 内容宽度
左上,右上,右下,左下,顺时针方向
圆圈:圆角 = 半径!
扇形:
div{
width:100px;
height:50px;
margin:30px;
background:red;
border-radius:50px,50px,0,0;
}
div{
width:50px;
height:50px;
margin:30px;
background:red;
border-radius:50px,0,0,0;
}
x偏移量,y偏移量,便宜半径,阴影颜色
box-shadow:10px 10px 1px yellow;
h1 - h6 p div 列表
span a img strong ...
行内元素可以包含在块级元素中,反之则不行
块元素
display:block;
行内元素
display:inline;
保持块元素和行内元素的特性
display:inline-block;
消除
display:none;
这个也是一种实现行内元素排列的方式,但是我们很多情况都是用float
右侧不允许浮动
clear:right;
左侧不允许浮动
clear:left;
两侧不允许浮动
clear:both;
clear:none;
解决方案:
增加父级元素高度
#father{
border:1px #000 solid;
height:800px;
}
增加一个空的div标签,清除浮动
<div class="clear"></div>
.clear{
clear:both;
margin:0;
padding:0;
}
overflow
在父级元素中增加一个 overflow:hidden;
-----------------------------------------------------
visible 默认值。内容不会被修剪,会呈现在元素框之外。
hidden 内容会被修剪,并且其余内容是不可见的。
scroll 内容会被修剪,但是浏览器会显示滚动条以便查看其余的内容。
auto 如果内容被修剪,则浏览器会显示滚动条以便查看其余的内容。
inherit 规定应该从父元素继承 overflow 属性的值。
父类增加一个伪类:after(最好的方案)
#father:after{
content:‘‘;
display:block;
clear:both;
}
小结:
浮动元素后面增加新的div
设置父元素的高度
overflow
父类增加一个伪类:after(推荐)
display
方向不可以控制
float
浮动起来的话会偏离标准文档流,所以要解决父级塌陷的问题!
position:relative;
相对于原来的位置,进行指定的偏移,相对定位的话,它任然在标准文档流中!原来的位置会被保留
top:-20px;
left:20px;
bottom:-10px;
right:20px;
定位:基于xxx定位,上下左右~
没有父级元素定位的前提下,相对于浏览器定位
假设父级元素存在定位,我们通常会相对于父级元素进行偏移~
在父级元素返回内移动
相对于父级或浏览器的位置,进行指定的偏移,绝对定位的话,它不在标准文档流中!原来的位置不会被保留
方块定位联系
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#box{
width: 300px;
height: 300px;
padding: 10px;
border: 2px solid red;
margin: 0 ;
}
a{
width: 100px;
height: 100px;
text-decoration: none;
background: #E0C3FC;
line-height: 100px;
text-align: center;
color: white;
display: block;
}
a:hover{
background: #FFDEE9;
}
.a2{
position: relative;
left: 200px;
top: -100px;
}
.a3{
position: relative;
left: 100px;
top: -100px;
}
.a4{
position: relative;
top: -100px;
}
.a5{
position: relative;
left: 200px;
bottom: 200px;
}
</style>
</head>
<body>
<div id="box">
<a class="a1" href="#">链接1</a>
<a class="a2" href="#">链接2</a>
<a class="a3" href="#">链接3</a>
<a class="a4" href="#">链接4</a>
<a class="a5" href="#">链接5</a>
</div>
</body>
</html>
z-index: 999: 层级
opacity: 0.4 透明度
position: absolute 绝对定位
浮起来,合在一起才可以进行设置层级
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="content">
<ul>
<li><img src="image/渐变.png" ></li>
<li class="tipText">学习Linux</li>
<li class="tipBg"></li>
<li>时间:2020-08-16</li>
</ul>
</div>
</body>
</html>
#content{
width: 380px;
padding: 0px;
margin: 0px;
overflow: hidden;
font-size: 12px;
line-height: 25px;
border: #000;
}
ul,li{
padding: 0px;
margin: 0px;
list-style: none;
}
/*父级元素相对定位*/
#content ul{
position: relative;
}
.tipText, .tipBg{
position: absolute;
width: 370px;
height: 25px;
top: 0px;
}
.tipText{
color: white;
z-index: 999;
}
.tipBg{
background: #000;
opacity: 0.4;
filter: alpha(opacity=50);
}
指定的系列名称:具体字体的名称,比如:"times"、"courier"、"arial"。
通常字体系列名称:比如:"serif"、"sans-serif"、"cursive"、"fantasy"、"monospace"
p{
font-family:"Times New Roman",Georgia,Serif;
}
font-size:16px; 设置字体大小
color:颜色 设置文字颜色
------------------------------------------------------------------------------
font-weight:normal; 设置字重
normal 默认值。定义标准的字符。
bold 定义粗体字符。
bolder 定义更粗的字符。
lighter 定义更细的字符。
-----------------------------------------------------------------------------
font:bold 16px "Times New Roman",Georgia,Serif;
文本排列属性是用来设置文本的水平对齐方式。
文本可居中或对齐到左或右,两端对齐.
当text-align设置为"justify",每一行被展开为宽度相等,左,右外边距是对齐(如杂志和报纸)。
h1 {text-align:center;}
p.date {text-align:right;}
p.main {text-align:justify;}
文本转换属性是用来指定在一个文本中的大写和小写字母。
可用于所有字句变成大写或小写字母,或每个单词的首字母大写。
------------------------------------------------------------------------------------------
p.uppercase {text-transform:uppercase;}
p.lowercase {text-transform:lowercase;}
p.capitalize {text-transform:capitalize;}
文本缩进属性是用来指定文本的第一行的缩进。
p {text-indent:50px;}
letter-spacing:1em; 字母之间的间距
word-spacing:2em; 单词间距
外层用一个div包裹整个大的div,从而设置里面div的大小的位置
body{
background-color:颜色; 网页背景颜色
}
background-color:颜色; div背景颜色
color:文字颜色
width:80% 设置宽度
margin:auto; 设置水平居中
原文:https://www.cnblogs.com/StayPositive/p/14034040.html