我有一个分隔符,左浮动属性包含一些文本,然后分隔符右浮动包含图像。两个分隔线的总宽度不应大于 735,我为图像保留 200。如果存在图像,如何将第一个分隔线的宽度调整为 535,如果隐藏图像,如何将其调整为 735?
<div style="width:735px">
<div style="float:left; width=????????>
some text here
</div>
<div style="float:right">
<img src="../images/biteme.png" alt="" style="height:auto; width:auto; max-height:115px; max-width:200px; display:block" />
</div>
</div>
最佳答案
要在纯 CSS 中做到这一点很容易,您需要一种不同的方法。只 float 一个div,然后另一个会自动占用剩余空间
演示 http://jsfiddle.net/kevinPHPkevin/gAUR5/
img {
width: auto;
height: auto;
max-width: 200px;
display: block;
}
将 img
的 css 设置为 display: none
并看到另一个 div 占用了所有剩余空间。
关于html - 如果存在图像,则调整分隔线宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17708768/