This article brings you practical tips about CSS web page layout. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. The ul tag has a padding value by default in Mozilla, but in IE only the margin has a value.
2. The same class selector can appear repeatedly in a document, but the id selector can only appear once; use both class and id for a label in CSS definition. If the definition is repeated, the id The definition of the selector is valid because the weight of ID is greater than CLASS.
3. A stupid way to adjust compatibility (IE and Mozilla): Beginners may encounter such a situation: it is normal for the same label attribute to be displayed as A in IE, but it must be displayed in Mozilla. It must be set to B to display normally, or the two are reversed.
Temporary solution: Selector {Attribute name: B !important; Attribute name: A}
4. If there is some spacing between a group of tags to be nested, then Leave it to the margin attribute of the label located inside, instead of defining the padding
of the label located outside. 5. It is recommended to use background-image instead of list-style-image for the icon in front of the li tag.
6. IE cannot distinguish the difference between inheritance relationship and parent-child relationship. They are all inheritance relationships.
7. When adding selectors to your tags, don’t forget to add comments to the selectors in CSS. You'll know why you do this when you modify your CSS later.
8. If you set a dark background image and bright text effect for a label. It is recommended to set a darker background color for your label at this time.
9. Pay attention to the order when defining the four states of a link: Link Visited Hover Active
10. Please use background for pictures that have nothing to do with the content
11. You can define colors Abbreviation #8899FF=#89F
12. Table performs much better than other tags in some aspects. Please use it where column alignment is required.
13. <script> does not have the language attribute. It should be written like this: </script>
The following is a quotation fragment:
<script type=”text/javascript”>
14. The title is the title, and the text of the title is the title. Text. Sometimes the title does not necessarily need to display text, so the following is a quotation fragment:
Title content
Change toTitle content< ;/h1>
15. Perfect single-pixel outline table (can pass the test in IE5, IE6, IE7 and FF1.0.4 or above) The following is a quoted fragment:
table{border-collapse:collapse;}
td{border:#000 solid 1px;}16. Negative margin values can play a role in relative positioning when the label uses absolute positioning. When the page is centered, the left:XXpx attribute is not suitable for layers using absolute positioning. It's a good idea to place this layer next to a label that needs to be positioned relatively, and then use negative values for margin.
17. When using absolute positioning, using margin value positioning can achieve positioning relative to its own position, which is different from the positioning of attributes such as top and left relative to the edge of the window. The advantage of absolute positioning is that it allows other elements to ignore its existence.
18. If the text is too long, change the long part into an ellipsis and display it: IE5, FF are invalid, but can be hidden, IE6 is valid
<DIV STYLE=”width:120px;height:50px;border:1px solid blue;overflow:hidden;text-overflow:ellipsis”>
19. When there may be text duplication problems caused by comments in IE, you can change the comments to:
Put your commentary in here…
20. How to use CSS to call external fonts
Syntax:
@font-face{font-family :name;src:url(url);sRules} Value:
name: font name. Any possible value of the font-family attribute
url (url): Specify the OpenType font file using an absolute or relative url address
sRules: Style sheet definition
21. How Center text vertically in a text box in a form?
If using row height and height grouping has no effect in FF, the way is to define upper and lower padding to achieve the desired effect.
22. Small issues to pay attention to when defining the A tag:
When we define a{color:red;}, it represents the four states of A. If you want to To define a mouse-over state, just define a:hover. The other three states are the styles defined in A.
When only one a:link is defined, be sure to remember to define the other three states!
23. Not all styles need to be abbreviated:
When p{padding:1px 2px 3px 4px} is defined before the style sheet,
In subsequent projects Another style has been added with 5px upper padding and 6px lower padding.
We don’t necessarily have to write p.style1{padding:5px 6px 3px 4px}.
can be written as p.style1{padding-top:5px;padding-right:6px;},
You may feel that writing this way is not as good as the original, but have you ever thought about it? ,
Your writing method repeatedly defines the style, and you don’t have to find the original values of the bottom padding and left padding!
如果以后前一个样式P变了话,你定义的p.style1的样式也要变。
24、网站越大,CSS样式越多,开始做前,请做好充分的准备和策划,包括命名规则。页面区块划分,内部样式分类等。
25、几个常用到的CSS样式:
1)中文字两端对齐:text-align:justify;text-justify:inter-ideograph;
2)固定宽度汉字截断:overflow:hidden;text-overflow:ellipsis;white-space:nowrap;(不过只能处理文字在一行上的截断,不能处理多行。)(IE5以上)FF不能,它只隐藏。
3)固定宽度汉字(词)折行:table-layout:fixed; word-break:break-all;(IE5以上)FF不能。
4)文字用鼠标放在前面的文字上看效果。这个效果在国外的很多网站都可以看到,而国内的少又少。
5)图片设为半透明:。halfalpha { background-color:#000000;filter:Alpha(Opacity=50)}在IE6及IE5测试通过,FF未通过,这是因为这个样式是IE私有的东西;
6)FLASH透明:选中swf,打开原代码窗口,在前输入 以上是针对IE的代码。
针对FIREFOX 给
7)在做网页时常用到把鼠标放在图片上会出现图片变亮的效果,可以用图片替换的技巧,也可以用如下的滤镜:
.pictures img {
filter: alpha(opacity=45); }
.pictures a:hover img {
filter: alpha(opacity=90); }以上就是对CSS网页布局实用小技巧的全部介绍,如果您想了解更多有关CSS3教程,请关注PHP中文网。
The above is the detailed content of Experts share 25 practical tips for CSS web page layout. For more information, please follow other related articles on the PHP Chinese website!
Explain the concept of BEM (Block Element Modifier) naming convention in CSSJul 24, 2025 am 04:06 AMBEM is a CSS naming specification that improves code readability, reduces conflicts and facilitates maintenance. 1.Block is a separate component, such as .btn; 2.Element is an integral part of Block, such as .nav\_\_link; 3.Modifier represents a state or variant, such as .btn--large. The naming formats are .block, .block\_\_element, .block--modifier or .block\_\_element--modifier respectively. Using BEM can avoid class name conflicts, improve maintainability, and facilitate team collaboration. Notes include: avoiding too deep levels, using Modifier reasonably,
Explain CSS specificity and how it is calculatedJul 24, 2025 am 04:03 AMCSS refers to the weighting mechanism used by the browser to determine which style rules are preferred. When multiple rules act on the same element, a high-weight rule takes effect. For example, #mainp is more specific than p, and will cover the color blue. The calculation method is based on the selector type and is divided into four levels: a is the number of inline styles, b is the number of ID selectors, c is the number of classes, attributes, and pseudo-classes, and d is the number of elements and pseudo-elements. Compare bit by bit when comparing, and compare a→b→c→d in sequence like a phone number. Common misunderstandings include abuse!important, over-necking selectors, dependency ID selectors, etc. It is recommended to use clear structure and unified class name naming to reduce conflicts, and you can check the style coverage through the developer tool and adjust the selector rights.
How to create a custom cursor with CSS?Jul 24, 2025 am 04:03 AMThere are four ways to customize mouse pointers using CSS: 1. Use the cursor attribute to set built-in styles, such as pointer, text, etc.; 2. Specify the custom picture as the cursor through url() and set alternate styles; 3. Add coordinate values after url() to adjust the hot spot position of the cursor; 4. Use JavaScript to hide the native cursor and use elements to simulate dynamic effects. Each method is suitable for different scenarios, and needs to pay attention to compatibility, performance and user experience details.
What is the difference between `id` and `class` selectors?Jul 24, 2025 am 03:56 AMThe role of id and class in CSS is different, and the usage scenarios are also different. 1.id is a unique identifier, used for style design of a single unique element, such as #main-content; 2.class can be reused and is suitable for multiple elements to apply the same style, such as .button; 3.id's selector priority is higher than class, which will affect style overwrite; 4. id is used in HTML, class is used in class, 5. id is used in CSS, and class is used in class. 6. It is recommended to avoid excessive use of id for style design, because it is not easy to cover; 7.
How do you center an element horizontally and vertically with CSS?Jul 24, 2025 am 03:55 AMTo center elements horizontally and vertically, the most common methods include using Flexbox, Grid and absolute positioning to match transform. 1. Use Flexbox: Set the container to flex layout, and set it to center through justify-content and align-items, which is suitable for modern browsers and is simple and efficient; 2. Use Grid: Use display:grid and place-items:center to achieve centering, which is concise and clear; 3. Absolute positioning and transform: suitable for old browsers, set it to 50% by left and top and use transform to move half of its width and height back to achieve centering. It is commonly used
How to change the font color in CSS?Jul 24, 2025 am 03:51 AMTo change the text color in a web page, use the color attribute of CSS. This property controls the foreground color of the text and supports color name, hexadecimal value, RGB or HSL format, such as: p{color:red;} or h1{color:#00ff00;}, which can be applied to label selector, class or ID; commonly used methods include: 1. Color name (such as red); 2. Hexadecimal (such as #ff0000); 3. RGB (such as rgb(255,0,0)); 4. HSL (such as hsl(0,100%,50%)); If the color does not take effect during debugging, it may be overwritten by other rules, insufficient contrast or wrong format. It is recommended to use browser developer tools to check and debug in real time to ensure the effect
Explain techniques for image replacement using CSSJul 24, 2025 am 03:49 AMImagereplacementinCSSinvolveshidingrealtextanddisplayinganimageorstyledversioninstead,ensuringaccessibilityandSEObenefitswhileallowingvisualcustomization.1.Theclassicmethodusestext-indenttomovetextoff-screenwhileshowingabackgroundimage,requiringsetel
What are CSS Logical Properties and Values?Jul 24, 2025 am 03:48 AMCSSLogicalProperties and Values provides a layout based on writing mode, using inline, block, start, end and other logical directions to replace the traditional left, right, top, bottom. 1. It enables the style to automatically adapt to LTR, RTL and vertical layout without additional adjustments; 2. Common attributes include margin-inline-start, padding-block-end, inline-size and block-size; 3. Applicable to international websites, component library development and responsive design; 4. Be careful about compatibility when using it, and some browsers may need to fall


Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.








