css summaty 3-样式表的重叠

样式表的重叠

1.加边框->留下右边框,拉长边框
在这里插入图片描述

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
  <style>
   #navigation{text-align: center;}
  .item{
    text-align:center;
    color:black;
    border-right:solid 1px #32CD32;
     padding:0 15px;
   }
   
  </style>
 </head>
 <body>
  <div id="navigation">
   <a href="#" class="item">首页</a>
   <a href="#" class="item">餐厅</a>
   <a href="#" class="item"></a>
   <a href="#" class="item"></a>
   <a href="#" class="item" style="border: none;">i lic </a>
 
  </div>
 </body>
</html>

或者

   <a href="#" class="item" style="border: none;">i lic </a>不这么写
     这么写
    #navigation .item .last{border:nonr;}在style内
    
     <class="item last"> 代替上句
   

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
  <style>
   #navigation{text-align: center;}
  .item{
    text-align:center;
    color:black;
    border-right:solid 1px #32CD32;
     padding:0 15px;
     
    
   }
  #navigation .item.last{
   border: none;
  } 
   
  </style>
 </head>
 <body>
  <div id="navigation">
   <a href="#" class="item">首页</a>
   <a href="#" class="item">餐厅</a>
   <a href="#" class="item"></a>
   <a href="#" class="item"></a>
   <a href="#" class="item last">i lic </a>
 
  </div>
 </body>
</html>

在实际开发过程中,作用于同一个元素上的多个样式产生冲突的情况下不可避免的经常发生
当多个样式发生重叠时,优先级别高的样式会生效–》层叠样式法

选择器的权重

!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>优先级</title>
  <style>
   a{color:yellow;}
   div a{color:green;}
   .demo a{color: black;}
   #demo1 a{color:orange;}
   div #demo1 a{color:red;}
   
  </style>
 </head>
 <body>
  <a href="">应该是黄色</a>       <!-- first -->
  
  <div class="demo">
   <a href="">应该是黑色</a>     <!--前三个-->   
  </div>
  
  <div id="demo1">
   <a href="">应该是红色</a>    <!--1,2,4,5-->
  </div>
 </body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值