Details about Div + CSS attributes 7

Source: Internet
Author: User

Layout attributes


In the previous HTML, the positions of elements can only be arranged in sequence. In CSS, you can locate elements more accurately. Netscape once proposed layer tag, which is good for precise layout, but not recognized by W3C. W3C proposed a function similar to layer tag in CSS.

 

Position attribute:

The position attribute is used to determine the position type of an element. For details, refer to the attribute:

Attribute name: 'position'
Attribute Value: absolute | relative | static
Initial Value: static
Target objects: All elements
Inherit?: No
Percentage remarks: forbidden
The attribute values are:
Absolute: the absolute position on the screen.
Relative: Relative Position on the screen.
Static: inherent position.

Direction attributes:

The direction attribute determines the arrangement direction of the box. For details, refer to the attributes:

Property name: 'direction'
Attribute Value: LTR | RTL
Initial Value: LTR
Target objects: All elements
Inherit?: Yes
Percentage remarks: forbidden

Float and clear attributes:

You can select a float location for an image in HTML. Currently, you can select a float location for a box object through CSS. Change the float attribute of the box. The box will float the left or right of other elements:

Property name: 'float'
Attribute Value: Left | right | none
Initial Value: None
Target objects: All elements
Inherit?: No
Percentage remarks: forbidden

For example:

<Style type = "text/CSS">
IMG {float: Left}
Body, P, IMG {margin: 2em}
</Style>
<Body>
<P>

Some sample text that has no other...
</Body>

On the contrary, the clear attribute is used to prevent elements from floating on the left or right of the box:

Property name: 'clear'
Attribute Value: Left | right | both | none
Initial Value: None
Target objects: All elements
Inherit?: No
Percentage remarks: forbidden

Absolute position attribute:

The absolute position attribute has four attributes:Top, right, bottom, and left, The property value is the length unit or percentage:

Attribute name: 'top', 'right', 'bottom ', and 'left'
Attribute Value: <length >|< percentage> | auto
Initial Value: None
Target objects: All elements
Inherit?: No
Percentage remarks: forbidden

With the preceding attributes, You can precisely define the position of an element, for example:

<P style = "position: relative; margin-Right: 10px; left: 10px;">
I used two red hyphens to serve as a change bar. They
Will "float" to the left of the line containing this
<Span style = "position: absolute; top: auto; left: 0px; color: red;"> -- </span>
Word. </P>

Z-index attributes:

In CSS, the overlapping display of elements is allowed, so there is a problem of display order, the Z-index attribute describes the front and back of the element, if the computer screen as a X-Y plane, then, the Z axis is perpendicular to the screen, and the Z-Index uses an integer to indicate the front and back positions of the element. A larger value will display the front position, CSS agrees to use a negative number in Z-index.

Property name: 'z-Index'
Attribute Value: auto | <integer>
Initial Value: Auto
Applicable objects: Elements Using the position attribute
Inherit?: No
Percentage remarks: forbidden

Width property:

Specify the width attribute of the box so that the width of the box does not depend on the content it contains:

Property name: 'width'
Attribute Value: <length >|< percentage> | auto
Initial Value: Auto
Target objects: block elements
Inherit?: No
Percentage remarks: Based on the width of the parent Element

The Min-width and max-width attributes are also provided in CSS, so that the width of the box is between the minimum width and the maximum width.

Property name: 'min-width'
Attribute Value: <length >|< percentage>
Initial Value: 0
Target Audience: All
Inherit?: No
Percentage remarks: Based on the width of the parent Element

Property name: 'max-width'
Attribute Value: <length >|< percentage>
Initial Value: 100%
Target Audience: All
Inherit?: No
Percentage remarks: Based on the width of the parent Element

Height attribute:

The same box also has the height attribute to control its own height:

Property name: 'height'
Attribute Value: <length >|< percentage> | auto
Initial Value: Auto
Target objects: block elements
Inherit?: No
Percentage remarks: Based on the height of the parent Element

The Min-height and max-height attributes are also provided in CSS, so that the height of the box is between the Min-height and max-height.

Property name: 'min-height'
Attribute Value: <length >|< percentage>
Initial Value: 0
Target Audience: All
Inherit?: No
Percentage remarks: Based on the height of the parent Element

Property name: 'max-height'
Attribute Value: <length >|< percentage>
Initial Value: 100%
Target Audience: All
Inherit?: No
Percentage remarks: Based on the height of the parent Element

Overflow attributes:

When specifying the width and height of an element, the overflow attribute is required if the area of the element is insufficient to display all content:

Attribute name: 'overflow'
Attribute Value: visible | hidden | scroll | auto
Initial Value: visible
Applicable object: Position attribute of an element
Inherit?: No
Percentage remarks: forbidden

The attribute values are as follows:

Visible: Expand the area to show all content.
Hidden: Hide content out of range.
Scroll: A scroll bar is displayed on the right of the element.
Auto: When the content exceeds the element area, the scroll bar is displayed.

Clip attributes:

CSS also provides a clip attribute to cut the element area into various shapes, but currently only provides one square type:

Property name: 'clip'
Attribute Value: <shape> | auto
Initial Value: Auto
Applicable element: the position attribute of an element is set to absolute.
Inherit?: No
Percentage remarks: forbidden

<Shape> the value is rect (top right bottom left ).

Line-height and vertical-align attributes:

The line-height attribute specifies the row spacing inside the element. The unit of length or percentage is used:

Property name: 'line-height'
Attribute Value: normal | <number >|< length >|< percentage>
Initial Value: normal
Target objects: All elements
Inherit?: Yes
Percentage remarks: Based on the font size of the element

In the following example, although the expressions are different, the results are the same:

Div {Line-Height: 1.2; font-size: 10pt}
Div {Line-Height: 1.2em; font-size: 10pt}
Div {Line-Height: 120%; font-size: 10pt}

The vertical-align attribute determines the vertical display of elements:

Property name: 'vertical-align'
Attribute Value: Baseline | sub | super | top | text-top | Middle | bottom | text-bottom | <percentage >|< length>
Initial Value: Baseline
Intended audience: inline Elements
Suitable for inheritance: No
Percentage remarks: Depends on the line-height attribute of the element.

The attribute values are as follows:
Baseline: Align with the baseline of the element.
Middle: Align with the middle of the element.
Sub: Sinking.
Super: Word increase.
Text-top: Align the top of the text.
Text-bottom: Align the bottom of the text.
Top: Alignment of the highest element in the current row.
Bottom: The lowest element alignment of the position of the line.

Visibility attributes:

This attribute is used to control the display or hide of elements:

Property name: 'visibility'
Property Value: Inherit | visible | hidden
Initial Value: Inherit
Target objects: All elements
Inherit: If the value is inherit, It inherits the attributes of the parent element.
Percentage remarks: forbidden

Related Article

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.