简体   繁体   English

display:inline不支持边框

[英]display:inline doesn't work work with border

I encountered a problem when I tried to put 2 divs next to each other. 我在尝试将2个div彼此相邻时遇到了一个问题。

display: inline it deletes my border and doesn't place both divs on the same line. display: inline它删除我的边框,并且不会将两个div放在同一行上。

Please advise: 请指教:

.gig {
    outline: 1px solid green;
    width: 400px;
    height: 200px;
    display: inline;
}
<div class="gig">
    <h3>The band</h3>
    <p><em>We love to play</em></p>
    <p>Great gigs we have met good people!</p>
</div>
<div class="gig">
    <h1>great shit</h1>
    <p>fdfdsfsd</p>
</div>

Inline对象没有height或width属性,因此请使用display: inline-block

you can use: 您可以使用:

float: left;

instead of 代替

display: inline;

In contrast to block elements, inline elements don't have properties such as width, height, margin, etc. 元素相比, 内联元素不具有宽度,高度,边距等属性。

Solution: 解:

use display: flex 使用display: flex

For cross-browser support: 对于跨浏览器支持:

use display: inline-block 使用display: inline-block

Try one of these changes: 请尝试以下更改之一:

Use float: 使用浮点数:

float: left;

or 要么

float: right;

Or use display inline: 或使用内联显示:

display: inline-block

or use flex display: 或使用弹性显示:

display: flex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM