Get the App
SLTechnology News&Howtos  ›  Development  › 

How to avoid underlining when naming css layout

Shulou Source: shulou.com Published: 2022-06-01 06:28:15 10月05日 Update

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.

Tags: Underlining layout code content knowledge parts delimiters styles articles results tests for this personal value just only most often easy to operate articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL Redmi Apple Huawei