【发布时间】:2012-10-17 02:55:07
【问题描述】:
我正在做一个有趣的小项目,但在尝试让<div> 中的图像漂浮在所述<div> 的右侧时遇到了一些麻烦。问题是它似乎忽略了容器(它所在的<div>)并表现得好像它是父包装的一部分。我想要发生的是包含元素根据其中的图像调整它的高度......我猜。一直在玩它,但没有任何运气。
HTML:
<div class="maincontentwrapper">
<!--First body article on page-->
<div class="contentpane">
<img src="images/welcomethumb_small.jpg" alt="" id="infoimg" />
Filler text. This is the only thing that<br />
seems to change the height of this div's<br />
border.
</div>
<!--Second body article on page-->
<div class="contentpane">
Text goes here.
</div>
</div>
CSS 所有可见类的代码:
.maincontentwrapper {margin: 10px 333px 10px 10px;}
.contentpane {border: solid 2px red;
margin-bottom: 10px;
padding: 4px 4px 4px 4px;
text-indent: 1em;}
/* Thumbnail for first article on home page.
Margins set to push image to align ignoring the container's
border width and padding width. */
#infoimg {float: right;
width: 145px;
height: 150px;
margin: -6px -6px 4px 4px;}
/* End Main Content Styles */
编辑:如果您需要网站链接以澄清问题所在,我当然可以添加它。
【问题讨论】:
-
如果您试图让内容窗格 DIV 将边框放在图像周围...那么内容窗格需要足够高以包含图像。您是否尝试在图像之后放置
?此外,如果最上面的内容窗格的唯一目的是在图像周围放置边框,为什么不直接将边框应用到图像本身? -
你想做什么?
-
我想帮忙,你问什么?你能在 jsFiddle 中给我们演示吗?
-
我尝试了 Leigh 之前所说的,没有用。我只是试图让 div 显示文章中可能包含的图像和文本周围的边框。因此,需要边框的不仅仅是图像,而是整个元素。
-
我没有仔细看,但 Leigh 可能很准确。与其做不正确的
,不如试试