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------------- -------------------------------------------------- -------------------------------------------------- ------------body tag: default margin: 8px;
-
dl tag, p tag: default margin-top:1em;margin-bottom:1em;
- ##dd tag: default margin-left:40px;
-
##fieldset tag: default margin-left:2px;margin-right:2px;padding :0.35em 0.75em 0.625em;
-
##legend tag: Default padding-left:2px;
padding-right :2px; ##textarea tag: default padding: 2px ;
button tag: default padding: 1px 6px;
##hr tag: default margin-top:0.5em;margin-bottom:0.5em;\
- ##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; } <!--以上标签为最常用的,其余若需要则再额外添加-->
2. Website font style
## 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倍行距,字体样式为‘微软雅黑’或者‘宋体’ 字体颜色由网站风格决定 -->3. Remove the table label margins and merge them together
table { border-collapse:collapse; border-spacing:0; } <!-- 默认:border-collapse:separate;//设置单元格边框是否合并 border-spacing:2px;//相邻单元格边框间的距离 -->4. Eliminate the font style
i,em{
font-style:normal;
}
<!--
默认是斜体(italic)
-->
b,strong{
font-weight:normal;
}
<!--
默认是粗体(bold)
-->
ul,ol{
list-style:none;
}
<!--
默认是:initial(默认值)
-->
a{
text-decoration:none;
color:inherit;
}
<!--
text-decoration:默认是underline(下划线)
color:默认是-webkit-link;颜色值为#00e;
-->
7. Clear the border and vertical alignment of the Img tag
img{ border:none; verticla-align:middle; } <!-- border:ie默认有边框 verticla-align:默认是baseline(基线) -->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 javascriptHow 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!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
