【发布时间】:2015-02-06 14:59:33
【问题描述】:
最近在使用图形标签进行一些测试时,我发现了一些奇怪的东西。虽然我可以轻松地将图像标签浮动在段落内,并将段落的背景颜色保留在段落下方和图像本身。我无法通过包含我的图像的浮动图形标签获得类似的结果。
这里没有说话,这里有两个链接,以确保您理解我遇到的问题:
简单的图片漂浮在段落中,效果很好: here
相同,但带有一个包含图像标签但未按预期工作的图形标签: here
如何在使用图形标签时获得相同的结果?
这是代码,但检查codepen,问题会很明显。
HTML 结构(
<div class="wrapper">
<p class="clearfix">
<img class="fox" src="http://raptorimages.hu/wp-content/gallery/blog/fox_img_9734_w500_kovacsa.jpg" alt="fox" >
<!-- the figure tag is supposed to work such as the image tag above when uncommented -->
<!--<figure class="fox">
<img src="http://raptorimages.hu/wp-content/gallery /blog/fox_img_9734_w500_kovacsa.jpg" alt="fox" >
<figcaption>Running fox</figcaption>
</figure>-->
</p>
<p>Praesent non risus enim. Duis ac mi tempus, feugiat nunc non, vestibulum magna. Curabitur in tempor lorem. Mauris fermentum vulputate </p>
</div>
CSS
*{
box-sizing:border-box;
}
.wrapper{
width:90%;
background:#cecece;
margin: 0 auto;
padding: 1.1111111%;
}
.wrapper p{
background-color:grey;
padding:1.111111%;
}
.fox{
float:right;
padding:0 0 0 1.1111%;
}
img,video,object,embed{
max-width:100%;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
【问题讨论】: