The css attribute that must be mastered--lineheight
1. The definition of line height
The line height refers to the distance between lines, that is, the distance between baselines. Only two lines of text will have two lines. A baseline, so why does a single line of text still have a line height? We look down with this question in mind.
##
This It is a single line of text, and there is a content area tag.
##Figure 1
(content area ) is the box surrounding the text. We can think of it as the size of the text area selected by the mouse. Its size is only related to font-size. It can be thought of as the area where the text in Figure 1 is selected by the mouse. , that is, the area of "single lines of text" selected.
"Inline boxes"(inline boxes) will not allow text to be displayed in blocks, but arranged in a line. Text wrapped by inline elements, such as the "content area" wrapped by the span tag, can be called an "inline box", while the part not wrapped by inline elements can be regarded as "anonymous content" "Linked Box". The "inline box" can be seen as the "content area" area within the span tag in Figure 1, and the "anonymous inline box" can be seen as the content wrapped by the red dotted line.
"Line box box"(line boxs), each line is a "line box box", and the line box box is composed of anonymous and non-anonymous inline boxes. It can be seen as the area wrapped by the outermost red solid line in Figure 1.
"Containing box"(containing box), this box is composed of "line box boxes".
3. The height mechanism of line heightThe influence of line height is everywhere, even a single line of text is no exception.
The height performance of a single line of text is only affected by
line-height, but mainly by the content area and line spacing. Single line text line height:
line-height = content area height + line spacing height
Then:
Line spacing = line-height - content Area height
The distance between the top of the text we usually see and the top of the "line box" is the half-line spacing.
4, the unit of line height(1), number
For example:
line-height:2; font-size:20px;
Then the text occupies at this time The height is 20*2=40px
(2), length
For example:
font-size:20px; line-height:20px; line-height:2em; line-height:3rem; line-height:3pt;
has a fixed value in px, and the rest needs to be combined with the browser The default size is converted or calculated using the body's font-size
property<p> 文字文字 <p>这是p标签</p> </p> p{ font-size:20px; line-height:150%; } p{ font-size:50px; }
Then the line height of "text text" is 30px, and the line height of the internal p tag is also 30px, without recalculating the line height based on the child elements.
means that when setting the line height as a percentage, the parent element will inherit the line height calculated based on font-size
to the child element, and the child element will not be recalculated based on font-size. Row height, generally not commonly used. Set the line height according to the browser's default line-height attribute. (5), inheritRow height inheritance IE8+Inherits the row height setting of the parent element, which is usually applied to some input and button tags.5, the application of line-height
(1), eliminate the distance between the picture
and the bottom of the containerFigure 2
vertical-align
:baseline, so there is spacing at the bottom of the image. When the parent element is set to a fixed height, the simple p contains a picture and the letter c. By default, the picture is aligned with the text baseline. In Figure 3, c is equivalent to a ghost blank node.Picture 3
1, make the picture blocky
2, picture vertical-align:
bottom3,让匿名空白节点line-height:0 (2),小图标大文字 (3),图片水平垂直居中 图三 图四 原理: 空白p内存在空白幽灵节点(看不见摸不着但存在空白元素中,例如图四中的)。 当设置text-align的时候,内联元素文字和图片会居中显示,我们让空白幽灵节点的行高与p高度一致,这样就可以实现垂直居中,图片和幽灵空白节点默认基线对齐,这时图片将偏上显示,我们设置图片的vertical-align为middle就可以实现图片近似居中的效果了。 如果想让图片完全垂直居中,我们可以让p的font-size:0,原因是不同字体的显示效果不同,有的下沉,有的刚好中线对齐,当font-size:0的时候,文字就变成一个点了,也就不存在不同字体的差异了。 (4),多行文本垂直居中 图五 图六 原理: 我们可以把span看做是图片,这样原理就和图片垂直居中原理大同小异了。就是需要将span的元素display设置成inline-block,并且重置line-height和text-align。 为何display不能是inline属性,个人观点,如果还是inline元素的话,由于此时父元素的line-height过高,子元素设置的行高很小就没有作用(因为line-height达不到父元素行高的高度,所以看上去好像是无效的),类似于margin中的由于浮动或者绝对定位的无效的原因,我在另外margin篇有介绍,css中margin的深入了解,如果有兴趣可以去看看,如果设置子元素line-height设置很大的话是有作用的,所以只能让span元素为inline-block元素,inline-block具有包裹性,所以呈现出图六效果。 如果容器是自适应高度的,无法获得高度,那么我们可以让外部容器为表格元素居中。 【相关推荐】 1. 免费css在线视频教程 2. css在线手册 The above is the detailed content of The css attribute that must be mastered--lineheight. For more information, please follow other related articles on the PHP Chinese website!<i class='icon'></i>
<span>这是span标签内的文字</span>
span{
line-height:30px;
vertical-align:middle;
}
i{
vertical-align:middle;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.
