我的图像有问题。图像不是浮动的,但确实可以在中央工作。但是,我想要图像浮动和div的中心。这是我的代码。
的HTML
<div class="middle-align">
<div id="gallery-left">
<div class="gallery-left-middle">
<p class="gallery-photo"> <a rel="gallery_group" href="#" title=""><img alt="" src="assets/images/welcome.jpg" /></a> </p>
<p class="gallery-photo"> <a rel="gallery_group" href="#" title=""><img alt="" src="assets/images/welcome.jpg" /></a> </p>
<p class="gallery-photo"> <a rel="gallery_group" href="#" title=""><img alt="" src="assets/images/welcome.jpg" /></a> </p>
<p class="gallery-photo"> <a rel="gallery_group" href="#" title=""><img alt="" src="assets/images/welcome.jpg" /></a> </p>
</div>
</div>
</div>
的CSS
.gallery-left-middle {text-align:center;}
#gallery-left img{float:none;display:inline-block;width:180px;height:180px;}
我遵循了这个问题:问题已解决。但这仍然行不通。
问题在于图像不是浮动的,而是在中间。有任何想法吗?
这是因为p
是block元素,它将自动填充width
其父元素,div
并且因为img
has text-align:center
,它位于该p
元素的中心。如果要使这些图像浮动,可以尝试设置display:inline-block
这些p
元素而不是img
元素。
.gallery-left-middle {text-align:center;}
.gallery-photo {display: inline-block;}
img{width:180px;height:180px;}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句