如何让 2 个 HTML 块元素(具有不同的宽度)“内联”,覆盖整个父元素?
我怎样才能有2个块元素(“块”,因为我想将背景图像应用到其中之一)对齐(一个在左边,一个在右边),其中:
- 左侧元素的宽度由文本定义它包含的行(可以变化...)
- 右侧元素的宽度占据了总宽度的其余部分
- 总宽度是固定的(由某些父元素给出)
像这样:
<div id="some_parent_element_with_fixed_width">
<div class="left">Here should be some text of varying length...</div>
<div class="right">Here should be displayed a x-repeat background image on the entire remaining width...</div>
</div>
非常感谢任何跨浏览器解决方案! 汤姆
how can I have 2 block elements ("block" because I want to apply a background image to one of them) aligned (one on the left, one on the right), where:
- the width of the left element is defined by the text line it contains (can vary...)
- the width of the right element takes up the rest of the total width
- the total width is fixed (given by some parent element)
Like so:
<div id="some_parent_element_with_fixed_width">
<div class="left">Here should be some text of varying length...</div>
<div class="right">Here should be displayed a x-repeat background image on the entire remaining width...</div>
</div>
Thanks a lot for any cross-browser solutions to this!
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在左侧元素上使用
float:left
,这将使其仅占用其内容的大小。在右侧元素上使用overflow:hidden
,这将自动使用其余空间,因为块元素的width
属性默认为auto.
Use
float:left
on the left element, that will make it take up only the size of it's content. Useoverflow:hidden
on the right element, that will automatically use the rest of the space as the default for thewidth
property of a block element isauto
.