Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the skills of writing CSS easily

Shulou Source: shulou.com Published: 2022-06-02 16:28:08 10月04日 Update

This article introduces you to easily write CSS skills, the content is very detailed, interested friends can refer to, hope to be helpful to you.

8 simple and practical skills for writing CSS

This article mainly helps friends who have just come into contact with CSS, through this article, we can help you understand CSS better.

1. structure

Keeping the CSS structure clear not only helps to keep the CSS file simple, but also helps to check and change it later.

This is not recommended:

BODY

{margin-top:5px; font-family:Arial,Helvetica, sans-serif;font-size:14px;color:#3b5f83;}

This is the recommended way to write:

BODY

{margin-top:5px; font-family:Arial,Helvetica,sans-serif; font-size:14px; color:#3b5f83;}

two。 Keep it simple.

Keeping the code concise can significantly reduce the size of the CSS file.

Not recommended:

Padding-top:10px; padding-right:5px

Can be abbreviated to:

Padding:10px5px00

3.Paddingvs.Margin

Margin is the least compatible attribute for browsers. Therefore, the Padding attribute should be used whenever possible, as long as conditions permit.

4. Integration

In the following example, a common Class is defined to replace the same code used in different places: color:grey.

. header-content {font-size;12px; color:grey;} .body _ content {font-size:12px; color:grey;} .footer _ content {font-size:11px; color:grey;}

In fact, it can be like this:

* {color:grey;} .body _ content {font-size:12px;} .footer _ content {font-size:11px;}

5. Annotation

Adding a simple comment in the right place will not only help you understand the code, but others can also understand your code well.

/ * the URL www.zdbase.com*/ is defined here.

6. Verification

* validate the CSS file that has been created, which can help you find errors in the file.

7. Avoid using styles in XHTML

Do not use styles in Xhtml code, which will not only increase the size of the web page file, but also confuse and complicate the code. For example, the following are not recommended:

This method of using style is not good h3 > div >

8. Naming

Use standard ID and Class names that can be understood literally, not just code names.

The following are not recommended:

.a1 {color:grey;} .b1 {font-size:11px;}

This is the recommended way to write:

Body _ content {color:grey;} .foot _ content {font-size:11px;} skills about easy writing CSS are shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Code recommendations files help techniques styles simplicity content writing size attributes more comments articles structure validation different good complex practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL OPPO Reno MariaDB Redmi NVidia