我在fiddle
中有这段代码我想知道是否可以让div
在文本中浮动,就像下面的文字一样?
.a {
position: relative;
width: 100px;
height: 40px;
background: red;
}

<span>Pause and play icons will automatically be attached to every mp3 song in text. Like this for example: </span>
<div class="a"></div><span> ut laoreet hendrerit mi. Nam vestibulum viverra diam. Nullam eros ipsum, rutrum ut, ultricies sed, congue sed, est. Pellentesque porttitor. Donec dictum urna eu mi. Maecenas in lorem.</span>
&#13;
答案 0 :(得分:3)
将display:inline-block
与vertical-align
一起使用,因为您可以将其设置为更适合您。
评论用户:
这是有效的HTML,因为span
是兄弟的div
而不是其父级。
.a {
display: inline-block;
vertical-align: middle;
width: 100px;
height: 40px;
background: red;
}
<span>Pause and play icons will automatically be attached to every mp3 song in text. Like this for example: </span>
<div class="a"></div><span> ut laoreet hendrerit mi. Nam vestibulum viverra diam. Nullam eros ipsum, rutrum ut, ultricies sed, congue sed, est. Pellentesque porttitor. Donec dictum urna eu mi. Maecenas in lorem.</span>