Getting Started with CSS

Source: Internet
Author: User

In the previous section, html,html is used to implement elements that are added to the page. But through HTML we can't specify the location, size, font color, etc. of the element's placement. To implement these things, you need to use CSS styles to implement

When using CSS styles, wrap the elements in <div></div> before you need to add a style. So that the style we design can take effect. Add the Style keyword to the <div> tag to set the syntax: style = ' key1:value1;key2:value2; '

For example, the code to print the

<! DOCTYPE html>

The results of the operation are as follows:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7A/F4/wKiom1bCyq6BfJGFAABEipu4_0Y116.jpg "title=" Qq20160216150658.jpg "alt=" Wkiom1bcyq6bfjgfaabeipu4_0y116.jpg "/>

This method is modified directly in the <div> tab. But a webpage may have dozens of or even hundreds of elements. Many of these elements use the same style. It's a waste of time if every <div> changes so much. So CSS can also provide a similar approach to a face object. We call it the selector. There are many types of selectors, specific examples are as follows:

Tag Selector

Used to add attributes to all specified tags, such as adding a background color to all <div> tag inclusions

div{background-color:red;} <div > </div>


Class Selector

Used to add attributes to content with the same class value

. bd{background-color:red;} <div class= ' bd ' > </div>

ID Selector

To add a style to the specified ID, be aware that the value of the ID in each page must be unique

#idselect {background-color:red;} <div id= ' Idselect ' > </div>


Association Selector

Represents a hierarchical relationship, such as adding a style only to the <p> tag under a label with an ID value of Idselect. and other labels are unaffected

#idselect p{background-color:red;}

<div id= ' idselect ' > <p>p label Test </p> 

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7A/F8/wKioL1bD19LDI5UeAABe_ZQ41Tc100.jpg "title=" Qq20160217101338.jpg "alt=" Wkiol1bd19ldi5ueaabe_zq41tc100.jpg "/>


Combo Selector

To add styles to multiple labels at the same time

a,div,p{color:red;}

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7A/F8/wKioL1bD1trD1HpeAABWRJEHvRY249.jpg "title=" Qq20160217100934.jpg "alt=" Wkiol1bd1trd1hpeaabwrjehvry249.jpg "/>


Property Selector

Adds a style that represents the content that conforms to an attribute condition in the specified label, such as adding an element of type text in the input label

Width and Height styles

Input[type= ' text ']{width:100px; height:200px;}


Pseudo-selector and pseudo-element selectors

A:link{color: #FF0000}/* Normal link state style */a:visited{color: #0000FF}/* After access to the style */a:hover{color: #00FF00}//mouse over style */A: Active{color: #FF00FF}/* Hyperlink activated style */

With the combination of these selectors, we can efficiently configure styles for various elements



There are many different styles of elements, and the following is a description of the long-term inoculation style


Position 0.0 position indicates the upper-left corner of the picture

Dig a hole to see the picture


Margin padding

Margins and inner margins


Padding

The inner margin is the value of increasing the width of your own height.

<body> <div style= "background-color:red;height:100px;border:3px solid blue" > <div style= "Back ground-color:green;height:20px;padding-top:10px; " ></div> </div></body>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7A/F9/wKioL1bD6IaQJbamAAA8w2N15jI104.png "title=" Image.png "alt=" Wkiol1bd6iaqjbamaaa8w2n15ji104.png "/>

margin

The margin is to adjust the distance from the boarder border.

<body> <div style= "background-color:red;height:100px;border:3px solid blue" > <div style= "Back ground-color:green;height:20px;margin-top:10px; " ></div> </div></body>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7A/F9/wKioL1bD6OmCA1osAAA7ccEt2oA080.png "title=" Image.png "alt=" Wkiol1bd6omca1osaaa7ccet2oa080.png "/>

Margin can be adjusted to center

Center margin:0 Auto



position

The default absolute absolute positioning relative to the entire screen

Fixed-fix in browser window position never move

Relative-must be a absolute with a absolute tag positioned relative to the interior of the box defined by the relative

Absolute-

<div style = "Position:relative"

<div style = "Postion:absolute"

<div/>

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/E/U261/LANG/ZH-CN /images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "spacer.gif"/>

<body>    <a style= "position:  fixed;left: 30px;top: 30px "> Back Top </a>    <div id=" content "  Style= "Height: 2000px;background-color: aqua" >         <div style= "position: relative;background-color: aliceblue;width:300px;margin: 0  auto;height: 300px;  ">             

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7A/F9/wKioL1bD-1-RM0U3AAMaTzHa3Dc553.png "title=" Image.png "alt=" Wkiol1bd-1-rm0u3aamatzha3dc553.png "/>

Display three properties

None hidden does not show

Blocks become block-level labels

Inline becomes inline label

Float

<body> <div style= "background-color:red" > <div style= "float:left" >111</div> < ;d IV style= "Float:left" >222</div> <!--must clear otherwise float without background color--<div style= "Clear:both" ></div> </div></body>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7A/F9/wKioL1bD_E6ge1zHAAAvrPtF1nA102.jpg "title=" Qq20160217124921.jpg "alt=" Wkiol1bd_e6ge1zhaaavrptf1na102.jpg "/>

Overflow Roller effect

If the Overflow:hidden will cause the department to hide out of the display height

<div style= "overflow:hidden;background-color: red;height: 50px;width: 100px" >         dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>        dasdadads <br/>        dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/></div>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7A/FA/wKiom1bD_8-BX_zWAABHChfQ_yY118.jpg "title=" Qq20160217130306.jpg "alt=" Wkiom1bd_8-bx_zwaabhchfq_yy118.jpg "/>

If the Overflow:auto exceeds the display height, the drop-down roller is added to the right

<div style= "overflow:auto;background-color: red;height: 50px;width: 100px" >         dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>        dasdadads <br/>        dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>         dasdadads<br/>        dasdadads<br/>         dasdadads<br/>         Dasdadads<br/>  &nbSp;     dasdadads<br/>        dasdadads <br/>        dasdadads<br/>         dasdadads<br/></div>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7A/FA/wKiom1bEAEiBG3L4AABLx4btWIc510.jpg "title=" Qq20160217130801.jpg "alt=" Wkiom1beaeibg3l4aablx4btwic510.jpg "/>


Transparency

Filter:alpha (opacity=50) IE syntax

-moz-opacity:0.5 the syntax of Firefox

opacity:0.5 Chrome's syntax

Z-index Number of layers

Z-index:

<body>    adadadadadaddasdadad    <div style= "Height:  2000px; " >        <input type= "button"  value= "Submit data"/>         <div style= "Z-index: 1;opacity: 0.5;position:  fixed;left: 0;right: 0;top: 0;bottom: 0;background-color: black "></div >        <div style= "z-index: 2;position: fixed; left: 50%;top: 50%;margin-left: -150px;margin-top: -50px; " >            <div style= " background-color: white;width: 300px;height: 100px; " >                <input/ >                <input/>                 <input/>                 <input/>            </div>         </div>    </div></body></ Html>

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7A/FA/wKiom1bEAdngRd15AADlnupdDmg751.jpg "title=" Qq20160217131326.jpg "alt=" Wkiom1beadngrd15aadlnupddmg751.jpg "/>




Page Split layout

<! Doctype html>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7A/FA/wKioL1bEAoyA2DquAAGyJ6bBlSw438.png "title=" Image.png "alt=" Wkiol1beaoya2dquaagyj6bblsw438.png "/>















This article from "Thunderbolt Tofu" blog, declined reprint!

Getting Started with 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.