search
HomeWeb Front-endCSS TutorialLittle-known CSS usage tips

Little-known CSS usage tips

Aug 09, 2017 pm 03:50 PM
css

1.                                                                                                                                                                 
url(
url address) repeat-x left top}1) You can see that the first definition of background is a color value, which means that the color will take effect when the background image is disabled. 2) The quotation marks in the url brackets are not necessary, we can not write the quotation marks 2.                             Regarding the way to write Border, if you want to define div The four sides of have different colors but the same thickness and style. You can write like this:

DIV.special
{
border
:1px
solid
; border-color:color1 color2 color3 color4}The four colors are the top, right, bottom and left colors at one time 3.           In order to be compatible with all browsers The writing method of translucent effect can be displayed on all devices.
.tranparent
{
progid:DXImageTransform.Microsoft.Alpha(opacity=50)
;
##            -moz-opacity:
0.5
;                                                                                                                                                                     #50%;
##          position:absolute;/*
Note Must be absolute*/##                                                                                           :100px;
}
4.
         _height, The role of _widthUse _height to solve the problem of float div not closing. You can remove the _height attribute to achieve the effect. #wrap{ border:
6px
#ccc solid; overflow:
auto
; _height:1%;}
.column_left {
float
:
left
; width:
20%
;
padding
:10px;}
.column_right{ float:right; width:75%; padding:10px; border-left:6px #eee solid;}
div id="wrap ">
##div class="column_left">
##h1>Float lefth1>
div>
div class="column_right">
h1>Float righth1>
##
div>
div>
5.
Use min-height min -width solves the problem of fixed height of div or span
Sometimes we need to set a fixed height of an element, but only the height is set under firefox or opera. When the content is not enough, it does not meet expectations. At this time, we can use min-height
6.
Use !important to change the priority of the style
The so-called style priority It means that the browser always applies the style based on the proximity principle when applying styles. Suppose we have a definition of a certain element in three places on a page, one is in an external css file, and the other is in the file. Inline css is defined in the head tag, and the other is within the tag of this element. Then according to the proximity principle, the final style used by this element is the style defined in the tag. If we need to break this rule, we can use it! important directive
a.test
{color:red!important}This way even If color is defined in the A element, it will not be applied, but the above definition will be applied. and screen display css
link type="text/css" rel ="stylesheet" href="url " media="screen" charset="utf-8" />
link type ="text/css" rel="stylesheet" href="url" media="print" charset="utf-8" />
8.      > symbol (currently not supported by IE)
We can use DIV A to define the styles of all A tags inside the div, including those below the div div in span; if we only want to define the A tag of the one-level child node below the DIV, we can use the ">" symbol, for example:
DIV>A{color:red}
Now only the color of the label A that is the direct child node of DIV is red
9. :first-child :last-child In non-IE browsers, you can use these two indicators to get the first element or the last element of the parent element
20070412 21:05 Added
10. :Hover and other pseudo-classes can be used like this
##h1>Buy widgetsh1>
16. In order to prevent different browsers from interpreting different tags Different interpretations of padding and margin can be defined in front of the style sheet

*{}{ margin:0px;padding:0px;}
Added at 20070422 12:00
17. Turn off the input method state so that users can only enter characters in English state, similar to entering passwords
input {}{ime-mode: disabled ; }

20070423 09:08
18. Excerpt (author)
1) white-space:nowrap; overflow: hidden; width: 17em !important ; width: 18em;
Note: white-space does not support td, th, etc.
2) Use .fixTable{ table-layout: fixed; overflow:hidden; } and add the nobr tag to hide
The nobr tag is non-standard.
20070426 0848
19. Change the image size year-on-year
img.style.zoom = 0.5;
    {}{}
    .menu ul
{}{display:none}
    .menu:hover
{}{}
    .menu:hover ul
{}{display:block}
    
 
ul>
li class="menu">
##                                                                                                                                                             #ul
>##           
li
>firstli>##               ##
li
>
lastli>        ul
>
 ​ li
>
##ul>
In this way we can make a menu controlled only by css and pass the test under ie6, ie7, firefox1.5, opera9.0 11. We can use page-break-after, page-break-
before to control paging during printing

20070413 12:1312. * The function of html{} is to be compatible with IE versions below 6.0. For the selection of html nodes, other browsers consider the html tag to be the root node of the document, while ie6 The following IE version thinks that there is a root node above the html tag---Thankscalmzeal
for the explanation
13. The css class can have multiple values, we Just separate multiple values ​​​​with spaces
14. For the abbreviation of color, we can abbreviate #ff0033 to #f03

15. Use text-indent to display the picture and hide it Text (this practice is said to help SEO)
h1 {}{ background: url(widget-image.gif) no-repeat; height: image height text-indent: -2000px }

The above is the detailed content of Little-known CSS usage tips. For more information, please follow other related articles on the PHP Chinese website!

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
Iterating a React Design with Styled ComponentsIterating a React Design with Styled ComponentsApr 21, 2025 am 11:29 AM

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Oh, the Many Ways to Make Triangular Breadcrumb Ribbons!Apr 21, 2025 am 11:26 AM

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG Properties in CSS GuideSVG Properties in CSS GuideApr 21, 2025 am 11:21 AM

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

A Few Functional Uses for Intersection Observer to Know When an Element is in ViewA Few Functional Uses for Intersection Observer to Know When an Element is in ViewApr 21, 2025 am 11:19 AM

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

Revisting prefers-reduced-motionRevisting prefers-reduced-motionApr 21, 2025 am 11:18 AM

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

How to Get a Progressive Web App into the Google Play StoreHow to Get a Progressive Web App into the Google Play StoreApr 21, 2025 am 11:10 AM

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

The Simplest Ways to Handle HTML IncludesThe Simplest Ways to Handle HTML IncludesApr 21, 2025 am 11:09 AM

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

Change Color of SVG on HoverChange Color of SVG on HoverApr 21, 2025 am 11:04 AM

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,

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

Video Face Swap

Video Face Swap

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

Hot Tools

MantisBT

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.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools