Web—02-轻松理解css

<div class="markdown-here-wrapper" data-md-url="https://i.cnblogs.com/EditPosts.aspx?opt=1"&gt;
<h3 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em">CSS基本语法以及页面引用
<h5 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">CSS基本语法
<p style="margin: 0px 0px 1.2em !important">css的定义方法是:


<p style="margin: 0px 0px 1.2em !important">选择器 { 属性:值; 属性:值; 属性:值;}


<p style="margin: 0px 0px 1.2em !important">选择器是将样式和页面元素关联起来的名称,属性是希望设置的样式属性每个属性有一个或多个值。代码示例:

div{
width:100px;
height:100px;
color:red
}

<h5 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">CSS页面引入方法
<p style="margin: 0px 0px 1.2em !important">1、外联式:通过link标签,链接到外部样式表到页面中。



font-size 设置文字的大小,如:font-size:12px;

font-family 设置文字的字体,如:font-family:'微软雅黑';

font-style 设置字体是否倾斜,如:font-style:'normal'; 设置不倾斜,font-style:'italic';设置文字倾斜

font-weight 设置文字是否加粗,如:font-weight:bold; 设置加粗 font-weight:normal 设置不加粗

line-height 设置文字的行高,设置行高相当于在每行文字的上下同时加间距, 如:line-height:24px;


<p style="margin: 0px 0px 1.2em !important">通过CSS中的line-height属性来设置行高,行高类似于在每行文字的上下同时加间距,行与行直接的距离被拉开。

text-decoration 设置文字的下划线,如:text-decoration:none; 将文字下划线去掉

text-indent 设置文字首行缩进,如:text-indent:24px; 设置文字首行缩进24px 行高示例图片

text-align 设置文字水平对齐方式,如text-align:center 设置文字水平居中


<h3 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em">CSS颜色表示法


<p style="margin: 0px 0px 1.2em !important">css颜色值主要有三种表示方法:

2、rgb表示,比如:rgb(255,0)表示红色

3、16进制数值表示,比如:#ff0000 表示红色,这种可以简写成 #f00


<h3 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em">CSS选择器
<h5 id="1-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">1、标签选择器
<p style="margin: 0px 0px 1.2em !important">标签选择器,此种选择器影响范围大,建议尽量应用在层级选择器中。举例:

....

<div id="box">....


<h5 id="3-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">3、类选择器

<div class="red">....

<h1 class="red big mt10">....
<p class="red mt10">....



<h5 id="4-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">4、层级选择器
<p style="margin: 0px 0px 1.2em !important">主要应用在选择父元素下的子元素,或者子元素下面的子元素,可与标签元素结合使用,减少命名,同时也可以通过层级,防止命名冲突。举例:

<div class="box">
....
<a href="#" class="red">....

<h3 class="red">....

<h5 id="5-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">5、组选择器
<p style="margin: 0px 0px 1.2em !important">多个选择器,如果有同样的样式设置,可以使用组选择器。举例:

<div class="box1">....

<div class="box2">....

<div class="box3">....


<h5 id="6-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">6、伪类及伪元素选择器
<p style="margin: 0px 0px 1.2em !important">常用的伪类选择器有hover,表示鼠标悬浮在元素上时的状态,伪元素选择器有before和after,它们可以通过样式在元素中插入内容。

<div class="box1">....

<div class="box2">....
<div class="box3">....

<h3 id="css-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1.3em">CSS盒子模型
<h5 id="-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">盒子模型解释
<p style="margin: 0px 0px 1.2em !important">元素在页面中显示成一个方块,类似一个盒子,CSS盒子模型就是使用现实中盒子来做比喻,帮助我们设置元素对应的样式。盒子模型示意图如下:<a href="http://www.runoob.com/css/css-boxmodel.html"&gt;CSS盒子模型把元素叫做盒子,设置对应的样式分别为:盒子的宽度(width)、盒子的高度(height)、盒子的边框(border)、盒子内的内容和边框之间的间距(padding)、盒子与盒子之间的间距(margin)。


<h5 id="-" style="margin: 1.3em 0px 1em; padding: 0px; font-weight: bold; font-size: 1em">设置宽高



    盒子的真实尺寸