开发者

Why we need inline box/inline element instead of block-level box/element?

开发者 https://www.devze.com 2023-04-12 06:11 出处:网络
I mean, If all element is block-level, then there may be more simple to learn. so, why we needthi开发者_Go百科s kind of box/element?Block-level elements cannot be placed next to each other, in contrar

I mean, If all element is block-level, then there may be more simple to learn. so, why we need thi开发者_Go百科s kind of box/element?


Block-level elements cannot be placed next to each other, in contrary to inline and inline-block elements.

Example:

<div style="display:block;width:40px">Up</div>
<div style="display:block;width:40px">Down</div>

<div style="display:inline-block">Left</div>
<div style="display:inline-block">Reft</div>

<div style="display:inline">left</div>
<div style="display:inline">right</div>


If all tags would be treated as block level elements, the following snippet:

<div>This is a <a href=".">link</a>, you can <b>click</b> it.</div>

would look like this in your browser:

Why we need inline box/inline element instead of block-level box/element?

The corresponding code:

<div>This is a <a href="." style="display:block">link</a>, you can <b style="display:block">click</b> it.</div>

Edit: By the way, if there is a need for you to deal with block elements only, just reset the HTML using CSS: * { display:block}

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号