前端三件套--CSS
<h2 style="color: black; text-align: left; margin-bottom: 10px;">1.CSS简介--层叠样式表(CascadingStyleSheets,CSS)</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">网页<span style="color: black;">实质</span>上是一个多层的结构,<span style="color: black;">经过</span>CSS<span style="color: black;">能够</span>分别为网页的每一个层来设置样式,而<span style="color: black;">最后</span><span style="color: black;">咱们</span>能看到只是网页的最上边一层。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS修改元素样式的方式大致<span style="color: black;">能够</span>分为3种:</p>内联样式(行内样式)内部样式表<span style="color: black;">外边</span>样式表<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">内联样式:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在标签内部<span style="color: black;">经过</span>style属性来设置元素的样式</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><</span><span style="color: black;">p</span> <span style="color: black;">style</span><span style="color: black;">=</span><span style="color: black;">"color:red;font-size:60px;"</span><span style="color: black;">></span>内联样式(行内样式)<span style="color: black;"></</span><span style="color: black;">p</span><span style="color: black;">></span></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">问题:<span style="color: black;">运用</span>内联样式,样式只能对一个标签生效。<span style="color: black;">倘若</span><span style="color: black;">期盼</span>影响到多个元素,<span style="color: black;">必要</span>在每一个元素中都复制一遍;并且当样式<span style="color: black;">出现</span>变化时,<span style="color: black;">咱们</span><span style="color: black;">必要</span>要一个一个的修改,非常的不方便。(<span style="color: black;">重视</span>:<span style="color: black;">研发</span>时绝对不要<span style="color: black;">运用</span>内联样式)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">内部样式表:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在head中的style标签里编写样式,<span style="color: black;">经过</span>css的<span style="color: black;">选取</span>器选中元素设置样式。内部样式表更加方便对样式进行复用</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><</span><span style="color: black;">style</span><span style="color: black;">></span>
<span style="color: black;">p</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span><span style="color: black;">green</span><span style="color: black;">;</span>
<span style="color: black;">font-size</span><span style="color: black;">:</span><span style="color: black;">50</span><span style="color: black;">px</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
<span style="color: black;"></</span><span style="color: black;">style</span><span style="color: black;">></span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">问题:<span style="color: black;">咱们</span>的内部样式表只能对一个网页起<span style="color: black;">功效</span>,它里边的样式<span style="color: black;">不可</span>跨页面进行复用</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">外边</span>样式表:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将css样式编写到一个<span style="color: black;">外边</span>的CSS文件中,<span style="color: black;">而后</span><span style="color: black;">经过</span>link标签来引入<span style="color: black;">外边</span>的CSS文件,<span style="color: black;">能够</span>在<span style="color: black;">区别</span>页面之间进行复用</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;"><</span><span style="color: black;">link</span> <span style="color: black;">rel</span><span style="color: black;">=</span><span style="color: black;">"stylesheet"</span> <span style="color: black;">href</span><span style="color: black;">=</span><span style="color: black;">"./style.css"</span><span style="color: black;">></span></div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将样式编写到<span style="color: black;">外边</span>的CSS文件中,<span style="color: black;">能够</span><span style="color: black;">运用</span>到浏览器的缓存机制,从而加快网页的加载速度,<span style="color: black;">加强</span>用户的体验。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">2.CSS基本语法</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">(1)注释</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS中的注释<span style="color: black;">没</span>论单行、多行只能<span style="color: black;">运用</span>/*和*/包裹。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">HTML中的注释<span style="color: black;">没</span>论单行、多行只能<span style="color: black;">运用</span><!--和-->包裹。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">JS中的注释单行注释<span style="color: black;">运用</span>//。多行注释<span style="color: black;">运用</span>/*和*/包裹。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">(2)<span style="color: black;">选取</span>器</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">选取</span>器权重:</p><span style="color: black;">选取</span>器权重内联样式1,0,0,0ID样式0,1,0,0类和伪类<span style="color: black;">选取</span>器0,0,1,0元素<span style="color: black;">选取</span>器0,0,0,1通配<span style="color: black;">选取</span>器0,0,0,0继承的样式<span style="color: black;">无</span>优先级在某个样式后面添加!important最高优先级<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS<span style="color: black;">经过</span><span style="color: black;">选取</span>器选中页面中的指定元素。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">通配符<span style="color: black;">选取</span>器:<span style="color: black;">选取</span>页面中的所有元素。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">*</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">元素<span style="color: black;">选取</span>器:<span style="color: black;">亦</span>叫标签<span style="color: black;">选取</span>器,<span style="color: black;">按照</span>标签名<span style="color: black;">叫作</span>来<span style="color: black;">选取</span>元素。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h1</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">green</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">类<span style="color: black;">选取</span>器:<span style="color: black;">按照</span>class名<span style="color: black;">叫作</span>来<span style="color: black;">选取</span>元素。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">.</span><span style="color: black;">left</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">blue</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ID<span style="color: black;">选取</span>器:<span style="color: black;">按照</span>id属性值选中一个元素。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">#</span><span style="color: black;">red</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">属性<span style="color: black;">选取</span>器:<span style="color: black;">按照</span>元素的属性值选中一组元素。</p>语法1:[属性名] <span style="color: black;">选取</span>含有指定属性的元素语法2:[属性名=属性值] <span style="color: black;">选取</span>含有指定属性和属性值的元素语法3:[属性名^=属性值] <span style="color: black;">选取</span>属性值以指定值开头的元素语法4:[属性名$=属性值] <span style="color: black;">选取</span>属性值以指定值结尾的元素语法5:[属性名*=属性值] <span style="color: black;">选取</span>属性值中含有某值的元素<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">复合<span style="color: black;">选取</span>器:</p>交集<span style="color: black;">选取</span>器:选中<span style="color: black;">同期</span>复合多个<span style="color: black;">要求</span>的元素。<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">.</span><span style="color: black;">a</span><span style="color: black;">.</span><span style="color: black;">b</span><span style="color: black;">.</span><span style="color: black;">c</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">blue</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>并集<span style="color: black;">选取</span>器:<span style="color: black;">运用</span>逗号分隔。<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">h1</span><span style="color: black;">,</span><span style="color: black;">span</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">green</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">关系<span style="color: black;">选取</span>器:</p>子元素<span style="color: black;">选取</span>器:选中指定父元素的子元素。<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">div</span><span style="color: black;">.</span><span style="color: black;">box</span> <span style="color: black;">></span> <span style="color: black;">p</span> <span style="color: black;">></span> <span style="color: black;">span</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">orange</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>后代<span style="color: black;">选取</span>器:<span style="color: black;">选取</span>指定元素内的指定后代元素。<div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">div</span> <span style="color: black;">span</span><span style="color: black;">{</span>
<span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">skyblue</span><span style="color: black;">;</span>
<span style="color: black;">}</span>
</div>兄弟元素<span style="color: black;">选取</span>器:<span style="color: black;">选取</span>兄弟元素<div style="color: black; text-align: left; margin-bottom: 10px;">p + span{
color: red;
}
p ~ span{
color: red;
}</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">伪类<span style="color: black;">选取</span>器:<span style="color: black;">选取</span>指定伪类元素。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">伪类(不存在的类),用来描述一个元素的特殊状态,<span style="color: black;">例如</span>:<span style="color: black;">第1</span>个子元素,被点击的元素,鼠标移入的元素,<span style="color: black;">运用</span>:开头。</p>:first-child <span style="color: black;">第1</span>个子元素:last-child 最后一个子元素:nth-child() 选中第n个子元素n:第n个,n的范围0到正<span style="color: black;">没</span>穷2n或even:选中偶数位的元素2n+1或odd:选中奇数位的元素:link 未<span style="color: black;">拜访</span>的链接:visited 已<span style="color: black;">拜访</span>的链接 <span style="color: black;">因为</span>隐私的<span style="color: black;">原由</span>,<span style="color: black;">因此</span>visited这个伪类只能修改链接的颜色:hover 鼠标悬停的链接:active 鼠标点击的链接<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">伪元素<span style="color: black;">选取</span>器:表</p>
论坛外链网http://www.fok120.com/ 我完全同意你的看法,期待我们能深入探讨这个问题。
页:
[1]