Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to avoid underlining when naming css layout

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the css layout naming when how to avoid underlining related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you read this css layout naming when how to avoid underlining article will have a harvest, let's take a look.

Friends who have used csshack should know that naming with an underscore is also a kind of hack. If you use a name like "_ style", you can make most browsers outside ie ignore the definition of this style, so it is not standard to use "_" as the delimiter when naming. There will be an error when doing a css check, so avoid using underscore naming.

To do this, we have to find a standard symbol that can replace the underscore. Of course, we don't have to use this kind of separator, it's just a matter of personal habit.

Do a small test and replace the underscore with "~", "$", "`", "&" and "-" respectively. As a result, only the "-" sign can be used, and the support for js is normal. Take a look at the test:

The following is the referenced content:

Css section:

The code is as follows:

. try-a {color:#00f;}

.try ~ a {color:#00f;}

.try`a {color:#00f;}

.try & a {color:#00f;}

.try $a {color:#00f;}

. try-b {color:#f00;}

.try ~ b {color:#f00;}

.try`b {color:#f00;}

.try & b {color:#f00;}

.try $b {color:#f00;}

Html section:

The code is as follows:

Try1

Try2

Try3

Try4

Try5

Js section:

The code is as follows:

Functionb () {

Document.getelementbyid ("a"). Classname= "try-b"

Document.getelementbyid ("b"). Classname= "try~b"

Document.getelementbyid ("c"). Classname= "try`b"

Document.getelementbyid ("d"). Classname= "try&b"

Document.getelementbyid ("e"). Classname= "try$b"

}

The result is that "try1" turns red and appears normal. However, in the definition of css, the id selector is often used. If you use "_" in the id naming of the page, you will inevitably have an underscore "_" in the css style, so you should also pay attention to avoid using an underscore in the naming of id.

This is the end of the article on "how to avoid underlining when naming css layouts". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to avoid underlining as far as possible in css layout naming". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report