【发布时间】:2014-09-05 14:55:38
【问题描述】:
我想在 div 中居中放置一张图片 (fiddle)。因为我希望那个 div 继承另一个漂浮在它旁边的 div 的高度,所以我不得不使用this trick.
因此,here 描述的解决方案似乎不起作用。
要求是不修改其他行为,但代码只要达到的效果相同即可。如有必要,我也愿意接受涉及 javascript 的解决方案。
<div class="container">
<div class="logo-div">
<img class="logo" src="http://bit.ly/1qCKrtJ" />
</div>
<div class="text-div">
<h4 style="display: inline;">Because Sometimes It Takes a Village</h4><br />
What about robots the size of tea cups that scoot around on tiny wheels, snapping pictures with miniature cameras and keeping track of where they are in relation to dozens of others?
</div>
.container {
background: green;
overflow: hidden;
}
.logo-div {
background: yellow;
width: 150px;
float: left;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
.text-div {
background: blue;
float: left;
max-width: 350px;
padding-bottom: 1000px;
margin-bottom: -1000px;
}
.logo {
width: 100px;
}
【问题讨论】:
标签: javascript html css layout web