zoukankan      html  css  js  c++  java
  • CSS样式覆盖规则

    有一下问题, 想让下面的border生效 ,#比. 优先级高,

        #navigator {  
            height: 100%;  
             200;  
            position: absolute;  
            left: 0;  
            border: solid 2 #EEE;  
        }  
          
        .current_block {  
            border: solid 2 #AE0;  
        }  
    

     有2种方法

    1.

    #navigator {  
        height: 100%;  
         200;  
        position: absolute;  
        left: 0;  
    }  
      
    .block {  
        border: solid 2 #EEE;  
    }  
      
    .current_block {  
        border: solid 2 #AE0;  
    } 
    

    2.

        #navigator {  
            height: 100%;  
             200;  
            position: absolute;  
            left: 0;  
            border: solid 2 #EEE;  
        }  
          
        .current_block {  
            border: solid 2 #AE0 !important;  
        }  
    

     

    规则一:由于继承而发生样式冲突时,最近祖先获胜。

    显示蓝色

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>Document</title>
      
    <style>
    
    body
     {color:black;}
    
    p
     {color:blue;}
    </style>
     </head>
     <body>
      <p>welcome
     to <strong>gaodayue的网络日志</strong></p>
     </body>
    </html>
    

    规则二:继承的样式和直接指定的样式冲突时,直接指定的样式获胜。

    显示红色

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>Document</title>
      
    <style>
    body
     {color:black;}
    p
     {color:blue;}
    strong
     {color:red;}
    </style>
     </head>
    <body> <p>welcome to
       <strong>gaodayue的网络日志</strong>
    </p> </body> </html>

    规则三:直接指定的样式发生冲突时,样式权值高者获胜。

    CSS选择器权值
    标签选择器 1
    类选择器 10
    ID选择器 100
    内联样式 1000
    伪元素(:first-child等) 1
    伪类(:link等) 10

    可以看到,内联样式的权值>>ID选择器>>类选择器>>标签选择器,除此以外,后代选择器的权值为每项权值之和,比如”#nav .current a”的权值为100 + 10 + 1 = 111。

    规则四:样式权值相同时,后者获胜。显示蓝色

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>Document</title>
      
        <style>
    .byline
     a {color:red;}
    
    p
     .email {color:blue;}
    </style>
     </head>
     <body>
    <p class="byline">Written by 
    	<a  class="email"  href="mailto:jean@cosmofarmer.com">Jean Graine de Pomme</a>
    </p>
    
     </body>
    </html>
    

    规则五:!important的样式属性不被覆盖。

     显示红色

    <!doctype html>
    <html lang="en">
     <head>
      <meta charset="UTF-8">
      <meta name="Generator" content="EditPlus®">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
      <title>Document</title>
      
    <style>
    
    
    
    .byline
     a {color:red !important;}
    
    p
     .email {color:blue;}
    
    </style>
     </head>
     <body>
     
    
    <p class="byline">Written by 
    	<a class="email" href="mailto:jean@cosmofarmer.com">
    		Jean Graine de Pomme
    	</a>
    </p>
    
     </body>
    </html>
    
  • 相关阅读:
    PHP 大小写转换、首字母大写、每个单词首字母大写转换相关函数
    【论文学习4】BiSample: Bidirectional Sampling for Handling Missing Data with Local Differential Privacy
    【论文学习3】Local Differential Privacy for Deep Learning
    【论文学习2】 Differential Privacy Reinforcement Learning
    深度学习中的优化算法
    Spatial crowdsourcing
    “pip install tensorflow ”出现错误
    python或pip'不是内部或外部命令”
    pip install torch出现错误
    打不开gitHub的解决方法
  • 原文地址:https://www.cnblogs.com/wujixing/p/5810414.html
Copyright © 2011-2022 走看看