CSS can be simpler with the CSS redundant code removed

Source: Internet
Author: User

This article is suitable for beginners of css. For those who have mastered css, you can also use this article to review the knowledge.

Through practice, the author believes that in some cases, css code can be more concise. In most cases, it is caused by the fact that new users cannot simplify the writing of element code with multiple attributes.

Simplified code is of great benefit to web pages, which improves the access speed of visitors and allows search engines to capture key content of web pages. Let's take a look at the simplified code I have summarized below:

Reference content is as follows:

1. Margin & Padding

Example 1:

. Div {

Margin-top: 10px;

Margin-right: 5px;

Margin-bottom: 30px;

Margin-left: 0px;

}

The simplified code is as follows:

Reference content is as follows:

. Div {margin: 10px 5px 30px 0 ;})

Example 2:

. Div {

Margin-top: 10ox;

Margin-right: 20px;

Margin-bottom: 0;

Margin-left: 20px;

}

Simplified code:

Reference content is as follows:

. Div {

Margin: 10px 20px 0;

}

Example 3:

. Div {

Margin-top: 0;

Margin-right: auto;

Margin-bottom: 0;

Margin-left: auto;

}

Simplified code:

Reference content is as follows:

. Div {

Margin: 0 auto;

}

Example 4:

. Div {

Margin-top: 50px;

Margin-right: 50px;

Margin-bottom: 50px;

Margin-left: 50px;

}

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next Page

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.