CSS condition comments and css comments

Source: Internet
Author: User

CSS condition comments and css comments

Different browser versions have different interpretations of some elements in CSS. You can select different CSS codes for different browser versions,
In fact, we can also use the condition annotation method to achieve a similar goal. What is the condition annotation? Here we will briefly introduce it, nothing more than if judgment, however, these judgments are not executed in scripts, but directly executed in html code. The following describes how to use them.

<! -- [If XXX]>
Here is the normal html code
<! [Endif]->
Here XXX is a few specific things. Here we will detail their meanings:
<! -[If IE]>/if the browser is IE/
<! -[If IE 5]>/if the browser version is IE 5/
<! -[If IE 6]>/if the browser version is IE 6/
<! -[If IE 7]>/if the browser version is IE 7/

The above are several commonly used syntax used to determine the version of IE browser. Next we will introduce the few logical judgment parameters:
There are several parameters: lte, lt, gte, gt, and!
The detailed explanations are as follows:
Lte: Short for Less than or equal to, that is, Less than or equal.
Lt: Short for Less than, that is, Less.
Gte: Short for Greater than or equal to, that is, Greater than or equal.
Gt: Short for Greater than, that is, Greater.

Example:

<! -- [If gt IE 5.5]>/if the IE version is later than 5.5/
<! -[If lte IE 6]>/if the IE version is less than or equal to 6/
<! -[If! IE]>/If the browser is not IE/

I believe that everyone understands the usage of the conditional annotation. OK. Let's take an example:
<! -- First use the css.css style sheet -->
<Link rel = "stylesheet" type = "text/css" xhref = "css.css"/>
<! -- [If! IE]>
<! -Use the 1.css style sheet for non-ie-based access.->
<Link rel = "stylesheet" type = "text/css" xhref1_1_1.css "/>
<! [Endif]->
<! -[If lt IE 6]>
<! -If the IE browser is less than 6, use the 2.css style sheet.->
<Link rel = "stylesheet" type = "text/css" xhref1_1_2.css "/>
<! [Endif]->

Defines what content is displayed in a browser.
This dropmenu (drop-down menu) model comes from cssplay, which is made after many researches and repeated tests by the author. I want to use this model to illustrate the principle of conditional annotation.
First look at a simple model
The following is xhtm:

Html code
  1. <Div class = "menu">
  2. <Ul>
  3. <Li> <a class = "drop" xhref = "../menu/index.html"> DEMOS
  4. <! -- [If IE 7]> <! ->
  5. </A>
  6. <! -<! [Endif]->
  7. <! -Display in IE7 </a> label->
  8. <Table> <tr> <td>
  9. <Ul>
  10. <Li> <a xhref = "../menu/zero_dollars.html" title = "The zero dollar ads page"> zero dollars advertising page </a> </li>
  11. <Li> <a xhref = "../menu/embed.html" title = "Wrapping text around images"> wrapping text around images </a> </li>
  12. <Li> <a xhref = "../menu/form.html" title = "Styling forms"> styled form </a> </li>
  13. <Li> <a xhref = "../menu/nodots.html" title = "Removing active/focus borders"> active focus </a> </li>
  14. <Li> <a class = "drop" xhref = ".. /menu/hover_click.html "title =" Hover/click with no active/focus borders "> hover/click with no borders </li>
  15. <Li class = "upone"> <a xhref = "../menu/shadow_boxing.html" title = "Multi-position drop shadow"> shadow boxing </a> </li>
  16. <Li> <a xhref = "../menu/old_master.html" title = "Image Map for detailed information"> image map for detailed information </a> </li>
  17. <Li> <a xhref = "../menu/bodies.html" title = "fun with background images"> fun with background images </a> </li>
  18. <Li> <a xhref = "../menu/fade_scroll.html" title = "fade-out scrolling"> fade scrolling </a> </li>
  19. <Li> <a xhref = "../menu/em_images.html" title = "em size images compared"> em image sizes compared </a> </li>
  20. </Ul>
  21. </Td> </tr> </table>
  22. <! -[If lte IE 6]>
  23. </A>
  24. <! [Endif]->
  25. </Li>
  26. <! -Display in IE6 </a> label->
  27. </Ul>
  28. </Div>

 

 

CSS

Html code
  1. <Link rel = "stylesheet" media = "all" type = "text/css" xhref = "final_drop.css"/>
  2. <! -- [If lte IE 6]>
  3. <Link rel = "stylesheet" media = "all" type = "text/css" xhref?#final_drop_ie.css "/>
  4. <! [Endif]->

 


Bytes
First, let's see how css is defined in non-ie.

Html code
  1. . Menu ul li ul {
  2. Display: none;
  3. }
  4. /* Specific to non IE browsers */
  5. . Menu ul li: hover {
  6. Color: # fff;
  7. Background: # bd8d5e;
  8. }
  9. /* Define the mouse over style */
  10. . Menu ul li: hover ul {
  11. Display: block;
  12. Position: absolute;
  13. Top: 3em;
  14. Margin-top: 1px;
  15. Left: 0;
  16. Width: 150px;
  17. }

 

 

In non-IE mode, the ul contained in li is displayed when the mouse slides over, because these browsers support li: hover usage.
Css in IE

Html code
  1. . Menu ul li a: hover {
  2. Color: # fff;
  3. Background: # bd8d5e;
  4. }
  5. /* Ul display included in li when the mouse slides */
  6. . Menu ul li a: hover ul {
  7. Display: block;
  8. Position: absolute;
  9. Top: 3em;
  10. Left: 0;
  11. Background: # fff;
  12. Margin-top: 0;
  13. Marg \ in-top: 1px;
  14. }

 


The final_drop.css style of the inheritance class. When there is no mouse time, the ul contained by li is not displayed.
Because
<! -- [If lte IE 6]>
</A>
<! [Endif]->

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.