6257rv7 发表于 2024-6-30 11:08:03

CSS 认识一下


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS <span style="color: black;">认识</span>一下。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">1、CSS 的<span style="color: black;">哪些</span>事</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS(Cascading Style Sheets)译「层叠样式表」,我的理解是:<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> CSS,<span style="color: black;">便是</span>穿着“国王的新衣”,在裸奔!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> HTML 的衣服,CSS 为 HTML 元素<span style="color: black;">供给</span>了一种样式描述,定义其<span style="color: black;">表示</span>方式,TA 能够对网页中元素进行像素级精确<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>赘述,先<span style="color: black;">认识</span>几种引入方式以及其区别。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">2、<span style="color: black;">外边</span>样式</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>单独<span style="color: black;">创立</span>一个扩展名为 .css 的样式表,在 head 标签中采用 link 方式引入,<span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">运用</span> import 方式引入:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;">// link 引入
      <span style="color: black;">&lt;</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;">type</span><span style="color: black;">=</span><span style="color: black;">"text/css"</span> <span style="color: black;">href</span><span style="color: black;">=</span><span style="color: black;">"css/style.css"</span> <span style="color: black;">/&gt;</span>
      // @import 引入
      <span style="color: black;">&lt;</span><span style="color: black;">style</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"text/css"</span><span style="color: black;">&gt;</span>
      <span style="color: black;">@</span><span style="color: black;">import</span> <span style="color: black;">url</span><span style="color: black;">(</span><span style="color: black;">"css/style.css"</span><span style="color: black;">)</span><span style="color: black;">;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">style</span><span style="color: black;">&gt;</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> link 方式引入,import 新手慎用。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">3、内嵌样式</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> &lt;style&gt; 标签在页面中编辑样式:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">&lt;</span><span style="color: black;">style</span><span style="color: black;">&gt;</span>
      <span style="color: black;">.</span><span style="color: black;">title</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;">&lt;/</span><span style="color: black;">style</span><span style="color: black;">&gt;</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>法用于其他页面,&lt;style&gt;标签<span style="color: black;">能够</span>放在任意位置,<span style="color: black;">意见</span>放在 head 中。</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">4、行内样式</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">行内样式是在 HTML 页面中的某个元素上直接对其直接定义,以 p 元素为例:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">style</span><span style="color: black;">=</span><span style="color: black;">"color: red"</span><span style="color: black;">&gt;&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</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>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">引用样式最好是采用<span style="color: black;">第1</span>种 link 方式引入,分离 HTML 页面代码与 CSS 样式,方便项目的<span style="color: black;">守护</span>管理,以及<span style="color: black;">加强</span> CSS 样式的复用性。</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><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;">5、CSS <span style="color: black;">选取</span>器</h2>
    <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> 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>用 CSS 对 HTML 页面中的元素实现一对一,一对多<span style="color: black;">或</span>多对一的<span style="color: black;">掌控</span>,离不开 CSS <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>器大概有这些:</p>通用<span style="color: black;">选取</span>器标签<span style="color: black;">选取</span>器class <span style="color: black;">选取</span>器(类<span style="color: black;">选取</span>器)id <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 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>器。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 5.1 通用<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>于所有标签,<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;">例:</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;">font-size</span><span style="color: black;">:</span> <span style="color: black;">18</span><span style="color: black;">px</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>
    </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>为 18px,颜色为红色。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 5.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>器<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;">例:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">p</span> <span style="color: black;">{</span>
      <span style="color: black;">font-size</span><span style="color: black;">:</span> <span style="color: black;">16</span><span style="color: black;">px</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>
    </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 标签中的字体<span style="color: black;">体积</span>为 16px,颜色为蓝色。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5.3 class <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;">class <span style="color: black;">选取</span>器<span style="color: black;">能够</span>选中带有特定类名的标签进行样式定义,<span style="color: black;">亦</span><span style="color: black;">便是</span>一对多,书写时以 . 开头,跟上 class 名<span style="color: black;">叫作</span>,<span style="color: black;">而后</span>编写样式,在对应的标签中用 class="" 引用。</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;">例:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;">// css 样式
      .title{
      bac<span style="color: black;">公斤</span>round-color: red
      }
      // html 页面
      <span style="color: black;">&lt;</span><span style="color: black;">div</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"title"</span><span style="color: black;">&gt;</span>语文课<span style="color: black;">表率</span><span style="color: black;">&lt;/</span><span style="color: black;">div</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">div</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"title"</span><span style="color: black;">&gt;</span>数学课<span style="color: black;">表率</span><span style="color: black;">&lt;/</span><span style="color: black;">div</span><span style="color: black;">&gt;</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>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">5.4 id <span style="color: black;">选取</span>器</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">id <span style="color: black;">选取</span>器以 # 开头,后面跟上 id 名,<span style="color: black;">而后</span>书写样式。在对应的标签中<span style="color: black;">运用</span> id="" 引用,其 id 名<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;">例:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;">// css 样式
      #title{
      bac<span style="color: black;">公斤</span>round-col</div>




j8typz 发表于 2024-10-15 08:27:47

认真阅读了楼主的帖子,非常有益。

4zhvml8 发表于 2024-10-26 22:51:56

外贸B2B平台有哪些?
页: [1]
查看完整版本: CSS 认识一下