Home Web Front-end CSS Tutorial A detailed discussion of css style initialization

A detailed discussion of css style initialization

Mar 19, 2018 am 09:17 AM
css initialization

This time I will bring you a detailed discussion of css style initialization, css style initializationWhat are the precautions, the following is a practical case, let's take a look.

When writing a website, because many tags have default styles, such as the margins of the P tag, the underline of the a tag, etc., we usually remove these default styles to avoid It will cause many changes in subsequent writing.

1. Tags with default inner and outer margins

## Some people will save trouble and clear the inner and outer margins directly Use *{margin:0;padding:0;} to write it like this. When the project is small, you will feel nothing. Once the project is large, writing like this will consume the performance of the website and reduce the website's performance. Loading speed.

So we need to understand which tags will have inner and outer margins by default, and then initialize the style according to the usage:

-------------- -------------------------------------------------- ----------------------------------Commonly used tags------------- -------------------------------------------------- -------------------------------------------------- ------------

  1. body tag: default margin: 8px;

  2. dl tag, p tag: default margin-top:1em;margin-bottom:1em;

  3. ##dd tag: default margin-left:40px;

  4. ##ul, ol tags: default margin-top:1em;margin-bottom:1em;padding-left:40px;
  5. h1 tag~h6 tag: default margin-top:0.67em;margin-bottom:0.67em;
  6. form tag: default margin-top:0em;
  7. ##fieldset tag: default margin-left:2px;margin-right:2px;padding :0.35em 0.75em 0.625em;
  8. ##legend tag: Default padding-left:2px;

    padding-right
  9. :2px;
  10. input tag: default padding: 1px 0px;

  11. ##textarea tag: default padding: 2px ;

  12. button tag: default padding: 1px 6px;

  13. ##hr tag: default margin-top:0.5em;margin-bottom:0.5em;\

  14. ##pre tag: default margin:1em 0px 1em;

    body,dl,dd,ul,ol,p,h1,h2,h3,h4,h5,h6,form,input,textarea,button{
        margin:0;
        padding:0;
    }
    <!--以上标签为最常用的,其余若需要则再额外添加-->
    Copy after login
  15. 2. Website font style

  16. ## Generally we will write the overall font style of the website in the body tag. Then if the local text style needs to be modified, modify it separately

body,button,input,textarea,select{
    font:12px/1.5 'Microsoft YaHei','arial','tahoma';
    color:#666;
}
<!--
    
    一般设置字体大小12px,字体行高为1.5倍行距,字体样式为‘微软雅黑’或者‘宋体’
    字体颜色由网站风格决定
-->
Copy after login
3. Remove the table label margins and merge them together

table {
    border-collapse:collapse;
    border-spacing:0;
}
<!--
    默认:border-collapse:separate;//设置单元格边框是否合并
           border-spacing:2px;//相邻单元格边框间的距离
-->
Copy after login
4. Eliminate the font style

i,em{
  font-style:normal;  
}
<!--
    默认是斜体(italic)
-->
b,strong{
  font-weight:normal;  
}
<!--
    默认是粗体(bold)
-->
Copy after login

5. Eliminate the identifier before the list tag

ul,ol{
  list-style:none;  
}
<!--
    默认是:initial(默认值)
-->
Copy after login

6. Eliminate the underline of the a tag and unify the font style

a{
  text-decoration:none;
  color:inherit;    
}
<!--
    text-decoration:默认是underline(下划线)
    color:默认是-webkit-link;颜色值为#00e;
-->
Copy after login
7. Clear the border and vertical alignment of the Img tag

img{
  border:none;
  verticla-align:middle;    
}
<!--
    border:ie默认有边框
    verticla-align:默认是baseline(基线)
-->
Copy after login
Note: The above are the most commonly used ones. The style initialization of other tags will be added as appropriate.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:

What are the steps for jest to test react native components

Detailed explanation of implicit calls in javascript

How to use React component refs

The above is the detailed content of A detailed discussion of css style initialization. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles