css - 浮动对span高度的影响
伊谢尔伦
伊谢尔伦 2017-04-17 13:04:11
0
7
1042

给span加上浮动(float:left),再给他加上行高(line-height:30px;),那么此时span的高度为30px。那么去除其浮动,它的高度就不为30px。为什么呢?暂时没想明白。

span{float:left; line-height:30px;}
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(7)
Ty80

First of all, span is an inline element, and secondly, span is a non-replacement element, so the width and height cannot be set. After you float, make span a block-level element, so you can set the width and height. Although img, input, textarea, and select are inline, they are replacement elements. If the width and height are not set, then the default width and height are set, and the width and height can be set.

Ty80

float will become an element block, that is to say, the display of a floating element is block

阿神

Span is an inline element by default

左手右手慢动作

I feel like your description is unclear.
With the line-height:30px; attribute, the line height is always 30px regardless of whether it is floated or not.
If it is height:30px; the height attribute does not work without the float attribute, and the row height cannot be set for inline elements. With the addition of float, the element will become a block-level element, and the height will be effective.

大家讲道理

The inline element has no border. For example, two spans will be mixed into one line. Use the height from outside to inside to determine the height of the content. It can be understood that the inline element has no border and shrinks to the content boundary. If float is added, the rules are not explicitly specified. It will inherit inline-block by default; due to the block method of flat, it is used to determine the boundary from the inside out and then take the height;

洪涛

It’s very simple, span is an inline element, and the width and height cannot be set for this element. But there are two ways to indirectly change its display: float and position.

小葫芦

I can’t tell what the problem is just by looking at your CSS.
You write and add line-height: 30px !important; try

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template