[英]Margin-top doesn't work after img element
why is it happen? 为什么会发生?
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT2FCIU0MAB5Op7RAt-5u576obOi-9JKtseSgYJDMdhAc04mKoS"
style="width:200px; height: 200px;"></img>
<span style="margin-top: 300px;">my text</span>
this is my jsfiddle: 这是我的jsfiddle:
http://jsfiddle.net/8sxFT/1/ http://jsfiddle.net/8sxFT/1/
I know I can add display: block
to the span and then margin-top
will work. 我知道我可以添加
display: block
到跨度,然后margin-top
将起作用。
but why isn't it working now? 但是为什么现在不起作用? I closed the
img
element.. 我关闭了
img
元素。
any help appreciated! 任何帮助表示赞赏!
Span element is inline element not a block element. 跨度元素是内联元素,不是块元素。 So they ignore vertical margin value.
因此他们忽略了垂直边距值。
Solution is you can make the span element display:inline-block;
解决方案是可以使span元素
display:inline-block;
Now you can use margin property. 现在您可以使用margin属性。
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT2FCIU0MAB5Op7RAt-5u576obOi-9JKtseSgYJDMdhAc04mKoS" style="width:200px; height: 200px;"></img>
<br />
<span style="margin-top: 300px;display:inline-block;">my text</span>
you are forgetting to use the float:leeft or right try it 您忘记使用float:leeft或正确尝试
<img src='https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT2FCIU0MAB5Op7RAt-5u576obOi-9JKtseSgYJDMdhAc04mKoS' style="float:left;width:200px; height: 200px;">
<span style="float:left;margin-top: 300px;">my text</span>
you don't need to close the img tag as you did < /img> 您不需要像以前那样关闭img标签</ img>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.