The CSS height attribute sets the height of the element, and the cssheight attribute element.

Source: Internet
Author: User

The CSS height attribute sets the height of the element, and the cssheight attribute element.

The height attribute sets the height of an element. Note: The height attribute does not include padding, border, or margins! This article introduces the usage and basic examples of CSS height to coders. For more information about css coders, see.

Css height

HereCSS heightCSS is used to control the height of the Set object. Use CSS attribute wordsHeight. PX and em are commonly used as html units.

 

I. height syntax

1. High basic syntax

Height: auto sets the Height automatically.

(The default height is auto, and the value increases from the applicable content. Generally, you do not need to set the height self-adaption)

Height: 20px set the Height to a fixed value

2. CSS height usage Structure

# Box {height: 50px}

Set the box object box height to 50px (pixel)

Extended reading: CSS Row height line-height

Note: "# box" is the CSS selector, which represents the CSS style of the object in curly brackets.

 

Ii. Height style usage

Height: 50px sets the object Height to 50px.

Height: 50 em sets the object Height to 50 relative length em

Normally, the height of a single div is not effective as a percentage.

Extended reading: html em tags

CSS adaptive height

Generally, we need to increase the height as the content increases when the width is fixed. In this case, we do not need to set the height to achieve this effect. No need to useHeight: autoTo achieve the heightAdaptive. Generally, you do not need to set the height to auto by default. The object height is the adaptive height.

Commonly used px (pixels) as Unit

 

3. Set the height element of the original height in the html Tag

1) set the table height: <td height = "50"> content </td>
2) Set img Image height: If the width is not set after the image height is set, the image will be automatically scaled down or zoomed in according to the set height or other proportions (Extended reading: css img)

The preceding height values have no unit and do not need to be added. An error occurred while adding the unit. The default value is pixel length.

 

Comparison between Html original height attributes and CSS height

Previously, html directly sets the height width = "300". This method is embedded into the table label without any unit. The default unit is px (pixel.

Table tr td table height style setting example html code:

<Table> <tr> <td height = "100"> my height is 100px </td> </tr> <td height = "50"> my height 50px </td> </tr> </table>

Two rows of tables with the height of 100px and 50px are set respectively.

 

Iv. Case study of css height

We set a box named "box" and a PX box with a height. To intuitively view the effect of the height setting, we add a 1 pixel red border to the box. If no width is set, the full screen width is 100%, so we will set a css width of 80 PX.

1. High Case CSS code:

#box{height:200px;border:1px solid #F00;width:80px}

/* CSS Description: Set the red css border, height PX, and width to 80 PX */

2. High Case HTml source code snippets:

<Div id = "box"> my height is 200px </div>

 

V. Summary of css height

Css height is usually used to set the height length unit for the object. Generally, you only need to add a height value to the CSS class when setting the height of the box object. The height cannot be set as the percentage height, for example, "height: 50%". The height setting as the percentage is invalid. This tutorial explains the differences and usage between CSS height and html height. We hope you can master the settings and usage of height style attributes.

 

Address: http://www.manongjc.com/article/809.html

Css Tutorials:

  • CSS tutorial
  • CSS Introduction
  • CSS syntax
  • CSS Id and Class selector
  • Create CSS styles
  • CSS background
  • CSS text style
  • CSS font
  • Css a link
  • CSS ul ol list Style
  • Css table Style
  • CSS Box Model
  • CSS border
  • CSS Outlines
  • CSS Margin
  • CSS Padding
  • CSS grouping and nested Selector
  • CSS size (Dimension)
  • CSS Display attributes
  • CSS Position Positioning
  • CSS Float floating
  • Horizontal CSS Align)
  • CSS combination Selector
  • CSS pseudo-class
  • CSS pseudo elements
  • CSS navigation bar
  • CSS drop-down menu
  • CSS image gallery
  • CSS image Transparency/opacity
  • CSS sprite image splicing technology
  • CSS media type
  • CSS attribute Selector
  • CSS instance

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.