search
HomeWeb Front-endCSS Tutorial24 well-organized CSS techniques_Experience exchange

Although this aspect has been mentioned many times in many documents, there are still many friends who make mistakes on these issues. Let’s take a look at these CSS techniques today. Read them carefully. Maybe you don’t fully understand them. You can search and expand the knowledge you want. I believe you will gain a lot!

1. The ul tag has a padding value by default in Mozilla, but in IE only 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 to define a label in CSS. If the definitions are repeated, the definition made by the id selector is valid because the weight of id is greater than that of class.
3. A stupid way to adjust compatibility (IE and Mozilla):
Beginners may encounter such a situation: the attribute of the same label is normal when set to A in IE, but must be displayed in Mozilla It must be set to B to display normally, or the two are reversed.
Temporary solution: The selector {attribute name: B !important; attribute name: A} may not work sometimes. You can search for more BUG solutions at jb51.net.
IV. If some spacing is required between a group of nested tags, leave it to the margin attribute of the tag located inside instead of defining the padding of the tag located outside
5. li tag It is recommended to use background-image instead of list-style-image for the previous icons.
6. IE cannot distinguish the difference between inheritance relationship and father-son 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. Also a word of caution, don’t go too crazy.
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. Because the images are lost, the text remains readable.
9. When defining the four states of a link, pay attention to the order: Link Visited Hover Active
10. Please use background for pictures that have nothing to do with the content. Always remember to separate presentation from content.
11. The definition of color can be abbreviated as #8899FF=#89F
12. Table is still useful in some aspects. When encountering a data table, don't hate it.
13. <script> does not have the language attribute. It should be written like this: <script type=”text/javascript”> <br> 14. Perfect single-pixel outline table (in IE5, IE6, IE7 and FF1. 0.4 or above can pass the test) <br> table{ border-collapse:collapse; } <br> td{ border:#000 solid 1px; } <br> You can also refer to: <br> CSS related to table borders Syntax <br><br> CSS removes the default spacing of table td and creates a 1px thin line table <br><br> Implements a thin line table that complies with Web standards <br><br> 15. Negative margin values ​​can be used in tags Absolute positioning plays the role of relative 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. <br> 16. 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. <br> 17. 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 <br> <DIV STYLE=”width:120px;height:50px;border: 1px solid blue;overflow:hidden;text-overflow:ellipsis"> <br> <NOBR> is, for example, a line of text that is very long and cannot be displayed in one line in the table. <br> 18. In IE, it may be due to the comment band When the text is repeated, you can change the comment to: <br> <!–[if !IE]>Put your commentary in here…<![endif]–> <br> 19. How to call external fonts with CSS <br> Syntax: <br> @font-face{font-family:name;src:url(url);sRules} <br> Value: <br> name: font name. Any possible value of the font-family attribute <br> url (url): Use absolute or relative url address to specify the OpenType font file <br> sRules: Style sheet definition <br> 20. How to make a text box in a form Is the text vertically centered? <br> If using row height and height groups has no effect in FF, the way is to define upper and lower padding to achieve the desired effect. <br> 21. Small issues to note when defining the A tag: <br> When we define a{color:red;}, it represents the four states of A. If we want to define a mouse position For the above state, you only need to 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! <br> 22. Not all styles need to be abbreviated: <br> When the style sheet is defined such as p{padding: 1px 2px 3px 4px}, another style is added in the subsequent project with a padding of 5px on the top and a padding of 5px on the bottom. Filler 6px. We don't necessarily have to write p.style1{padding:5px 6px 3px 4px}. It can be written as p.style1{padding-top:5px;padding-right:6px;}. You may feel that writing it this way is not as good as the original one, but have you ever thought about it? Your writing method repeatedly defines the style. In addition, You don’t have to find out what the original lower and left padding values ​​are! If the previous style P changes in the future, the style of p.style1 you defined will also change. <br> 23. The larger the website, the more CSS styles there are. Before starting, please make full preparations and plans, including naming rules. Page block division, internal style classification, etc. <br> 24. Fixed-width Chinese character truncation: overflow: hidden; text-overflow: ellipsis; white-space: nowrap; (However, it can only handle truncation of text on one line, not multiple lines.) (IE5 and above) FF can't, it only hides. <br><br> If you don’t understand a lot, it doesn’t matter, record these skills and come to jb51.net often, you will definitely gain something. You can also enter the content you are interested in in the search box on the left to search. You are welcome to leave comments and add CSS tips. <br></script>

Statement
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
How much specificity do @rules have, like @keyframes and @media?How much specificity do @rules have, like @keyframes and @media?Apr 18, 2025 am 11:34 AM

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Can you nest @media and @support queries?Can you nest @media and @support queries?Apr 18, 2025 am 11:32 AM

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

Quick Gulp Cache BustingQuick Gulp Cache BustingApr 18, 2025 am 11:23 AM

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

In Search of a Stack That Monitors the Quality and Complexity of CSSIn Search of a Stack That Monitors the Quality and Complexity of CSSApr 18, 2025 am 11:22 AM

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Datalist is for suggesting values without enforcing valuesDatalist is for suggesting values without enforcing valuesApr 18, 2025 am 11:08 AM

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

Front Conference in ZürichFront Conference in ZürichApr 18, 2025 am 11:03 AM

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

Building a Full-Stack Serverless Application with Cloudflare WorkersBuilding a Full-Stack Serverless Application with Cloudflare WorkersApr 18, 2025 am 10:58 AM

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

Creating Dynamic Routes in a Nuxt ApplicationCreating Dynamic Routes in a Nuxt ApplicationApr 18, 2025 am 10:53 AM

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

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.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor