Tips for CSS

Source: Internet
Author: User

A few days ago to see the "CSS Secret" This book, the first feeling is how the CSS can be so thick a book, but carefully think, with good CSS can really achieve a lot of desired effect, save a lot of JS code.

Tips for summarizing several CSS:

1, center all elements vertically

1 html, Body{2 Height:100%;3 margin:0;4}5 6 Body{7 -webkit-align-items:Center;8 -ms-flex-align:Center;9 Align-items:Center;Ten Display:-webkit-flex; One Display:Flex; A}

IE11, Firefox, Chrome, and Opera support Align-items properties.

The Align-items property is not supported for Safari, IE 9, and previous versions. IE 10 requires a prefix of-ms-.

Any container can be specified as a flex layout. Inline elements can also use the flex layout. (display: inline-flex;)

WebKit the kernel browser, you must -webkit prefix it.

2, table cell width:

1{2  table-layout: fixed;  3 }

3, use the property selector for empty links:

When a element does not have a text value, but the href attribute has a link, the link is displayed:

1{2  content: attr (href);  3 }

4. Detect mouse Double-click:

Html:

ReadOnly: Input field is read-only
1 <Divclass= "Test3">2   <span><inputtype= "text"value=" "ReadOnly= "true" />3   <ahref= "Http://renpingjun.com">Double Click Me</a></span>4 </Div>

Css:

1 . Test3 span{2 position:relative;3}4 . Test3 span a{5 position:relative;6 Z-index:2;7}8 . Test3 span a:hover,. test3 span a:active{9 Z-index:4;Ten} One . test3 span Input{ A background:Transparent; - Border:0; - cursor:Pointer; the position:Absolute; - Top:-1px; -  Left:0; - width:101%;/*hacky*/ + Height:301%;/*hacky*/ - Z-index:3; +} A . Test3 span Input:focus{ at background:Transparent; - Border:0; - Z-index:1; -}

5,css Write a triangle:

Use border to write triangle code and be compatible with IE6.

1 /*Create an arrow this points up*/2 div.arrow-up{3 width:0px;4 Height:0px;5 Border-left:5px Solid Transparent;/*Left Arrow Slant*/6 Border-right:5px Solid Transparent;/*Right Arrow Slant*/7 Border-bottom:5px Solid #2f2f2f;/*bottom, add background color here*/8 font-size:0px;9 Line-height:0px;Ten} One   A /*Create an arrow this points down*/ - Div.arrow-down{ - width:0px; the Height:0px; - Border-left:5px Solid Transparent; - Border-right:5px Solid Transparent; - Border-top:5px Solid #2f2f2f; + font-size:0px; - Line-height:0px; +} A   at /*Create an arrow this points left*/ - Div.arrow-left{ - width:0px; - Height:0px; - Border-bottom:5px Solid Transparent;/*Left Arrow Slant*/ - Border-top:5px Solid Transparent;/*Right Arrow Slant*/ in Border-right:5px Solid #2f2f2f;/*bottom, add background color here*/ - font-size:0px; to Line-height:0px; +} -   the /*Create an arrow this points right*/ * Div.arrow-right{ $ width:0px;Panax Notoginseng Height:0px; - Border-bottom:5px Solid Transparent;/*Left Arrow Slant*/ the Border-top:5px Solid Transparent;/*Right Arrow Slant*/ + Border-left:5px Solid #2f2f2f;/*bottom, add background color here*/ A font-size:0px; the Line-height:0px; +}

6, Text gradient:

1 H2[data-text]{2 position:relative;3}4 H2[data-text]::after{5 content:attr (Data-text);6 Z-index:Ten;7 Color:#e3e3e3;8 position:Absolute;9 Top:0;Ten  Left:0; One -webkit-mask-image:-webkit-gradient (linear, left top, left bottom, from (Rgba (0,0,0,0)), Color-stop (50%, Rgba (0,0,0,1)), to (Rgba ( 0,0,0,0 )));}

7, disable mouse events:

CSS3 new pointer-events lets you disable mouse events for an element, such as a connection that cannot be clicked if the following style is set.

1{ pointer-events: none;}

8, Fuzzy text:

1{2   color: transparent; text-shadow: 0 0 5px Rgba ( 0,0,0,0.5); 3 }

Tips for CSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.