簡體   English   中英

不應用CSS類?

[英]Not applying CSS class?

似乎無法識別或應用在文檔開頭定義的CSS類。 知道我缺少什么,還是做錯了?

JS小提琴

 <html> <head> <title>EXAMPLE</title> <style> .show_x { visibility: visible; } // .hide_x { visibility: hidden; } </style> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <span class="hide_x glyphicon glyphicon-warning-sign text-danger"></span> <span class="glyphicon glyphicon-warning-sign text-danger" style="visibility: hidden;"></span> </body> </html> 

我希望看不到任何警告信號,但是我看到第一個警告信號。 第二個已正確隱藏。

內聯注釋在CSS中不起作用,因此您擁有

      .show_x
      {
          visibility: visible;
      }
      // <-- invalid CSS
      .hide_x
      {
          visibility: hidden;
      }

這可能會使瀏覽器停止處理該CSS塊,很方便地就在這兩個CSS塊中的可見度更高(或更不可見)之前……反正一個在應用時更容易看到它,因為它隱藏了東西……您明白我的意思了。

在CSS中,我們只能使用塊注釋/**/ ,這是一個簡單的錯誤。

 <html> <head> <title>EXAMPLE</title> <style> .show_x { visibility: visible; } .hide_x { visibility: hidden; } </style> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body> <span class="hide_x glyphicon glyphicon-warning-sign text-danger"></span> <span class="glyphicon glyphicon-warning-sign text-danger" style="visibility: hidden;"></span> </body> </html> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM