H5 CSS Learning

Source: Internet
Author: User

P{text-indent:2em;} Empty two grids before paragraph
    • Paragraph layout--line spacing (row height) p{line-height:1.5em;}
    • Paragraph typesetting--the spacing between characters, letter spacing h1{letter-spacing:20px; }
    • Paragraph layout-aligning h1{
      Text-align:center/left/right;
      }
CSS element Categories:
  •   in CSS, tag elements in HTML are broadly divided into three different types: block elements , inline elements (also called inline elements) and inline block elements .

    common block elements are:

    <div>, <p>,

    commonly used inline elements are:

    <a>, <span>, <br>, <i>, <em>, <strong>, <label>, <q>, <var>, <cite>, <code>

    commonly used inline block elements are:

    , <input>
  • Element Classification--block-level element

    What is a block-level element? In HTML <div>, <p>, Display:block is the display of elements as block-level elements. The following code converts an inline element a to a block element , so that the a element has a block element feature.

     A{display:block;} 

    block-level element features:

    1, each block-level element starts from the new line, and the subsequent element also begins a row. (True overbearing, one block-level element exclusive row)

    2, the height, width, row height, and top and bottom margins of the element can be set.

    3, the element width is not set, is its own parent container of 100% (and the width of the parent element), unless a width is set.
  • Element classification--inline elements

    ,<span>, <a>, <label>, <strong>, and <em> are typical inline elements in HTML (inline elements ) (inline) element. Of course, block elements can also display:inline be coded to set elements as inline elements . The code below is to convert the block element div into an inline element , so that the DIV element has an inline element feature.

    div{     Display:inline;} ......<div> I want to become an inline element </div>

    Inline element Features:

    1, and other elements are on one line;

    2, the height of the element, the width and the top and bottom margin is not set;

    3. The width of the element is the width of the text or Picture it contains, and it cannot be changed.
  • Block-level elements have a single row, and by default, their width is automatically filled with the width of their parent element.
    The inline element does not have a single row, the adjacent inline elements are arranged in the same row, and the line is not wrapped until one row, and the width varies with the contents of the element.
    Block-level elements can set the Width,height property. The inline element setting width,height property is not valid.
    Block-level elements, even if the width is set, are still exclusive. Block-level elements can set the margin and padding properties.

    The margin and padding properties of the elements in the row, horizontal padding-left,padding-right,margin-left,margin-right all produce margin effects, but the vertical direction of the padding-top, Padding-bottom,margin-top,margin-bottom does not produce a margin effect.
  • Block-level elements correspond to display:block. Inline elements correspond to display:inline.
  • Element classification-inline block elements

    Inline block elements (inline-block) are features that have inline elements, block elements, and code that display:inline-block sets elements as inline block elements. (css2.1 New),, <input> tag is this inline block tag.

    Inline-block Elemental Features:

    1, and other elements are on one line;

    2, the height of the element, width, row height, and the top and bottom margin can be set.
  • Margin margin internal margin padding (top/left/right/bottom) border
  • Box model--border (i):

    The border of the box model is the line around the content and the filter, which you can set its thickness, style and color (border three properties).

    The following code is div to set the border thickness to 2px, the style is solid, the color is red border:

    div{    border:2px  solid  Red;}

    The above is an abbreviated form of the border code, which can be written separately:

    div{    border-width:2px;    Border-style:solid;    border-color:red;}

    Attention:

    1. Border-style (border Style) common styles are:

    Dashed (dashed line) | Dotted (point line) | Solid (solid line).


    2. Colors in Border-color (border color) can be set to hexadecimal colors, such as:

    Border-color: #888;//Don't forget the well in front.


    3, the width of the border-width (border width) can also be set to:

    Thin | Medium | Thick (but not very common), most often with pixels (px).
  • Box model--border (two)

    Now there is a question, what if you want to set the bottom border separately for the P tag, while the other three sides don't set the border style? CSS styles allow styles to be set only for one direction of the border:

    div{border-bottom: 1px solid red;}

    You can also use the following code to implement other three-side (top, right, left) border settings:

    border-top:1px solid red;
    border-right:1px solid red;
    border-left:1px solid red;
  • Box model--width and height

    The width and height of the box model is not the same as the width and height of the object we normally speak of, the width (width) and high (height) defined within the CSS, which refers to the content range filled in.

    So the actual width of an element (width of box) = left border + Left box + Left padding + content width + right padding + right Border + right edge.

    The height of the element is also the same.

    Like what:

    CSS code:

    div{    width:200px;    padding:20px;    border:1px solid red;    margin:10px;    }

    HTML code:

    <body>   <div> text content </div></body>

    The actual length of the element is: 10px+1px+20px+200px+20px+1px+10px=262px. The element box model can be viewed under Chrome browser, such as:

  • Box Model--fill

    You can set the distance between the element content and the border, which is called "padding". Fills can also be divided into top, right, bottom, and left (clockwise). The following code:

    div{padding:20px 10px 15px 30px;}

    The order must not be confused. You can write the above code separately:

    div{   padding-top:20px;   padding-right:10px;   padding-bottom:15px;   padding-left:30px;}

    If the top, right, bottom, and left fills are 10px; you can write this.

    div{padding:10px;}

    If the upper and lower fills are the same as 10px, about the same as 20px, you can write:

    div{padding:10px 20px;}
  • Box model--boundary

    The distance between the element and other elements can be set using the boundary (margin). The boundary can also be divided into upper, right, lower and left. The following code:

    div{margin:20px 10px 15px 30px;}

    You can also write separately:

    div{   margin-top:20px;   margin-right:10px;   margin-bottom:15px;   margin-left:30px;}

    If the upper-right bottom-left boundary is 10px, you can write this:

    div{margin:10px;}

    If the upper and lower bounds are the same as 10px, and about the same 20px, you can write:

    div{margin:10px 20px;}
    Summary: The difference between padding and margin, padding in the border, margin outside the border.
  • See Chapter CSS12

H5 CSS Learning

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.