【发布时间】:2011-06-09 08:13:55
【问题描述】:
我正在尝试制作一个没有固定宽度 (argh) 的居中、100% 高的布局。下面的解决方案似乎一切正常,除了我需要缩放到高度的 img:100%,它不能在表格单元格内缩放(在 div 之外一切正常)。 编辑:我可以在 css 和标签中设置固定高度,如 100px 左右。为什么这不适用于 %?
<div id="center">
<div id="tcontainer">
<div id="tleft">a</div>
<div id="tright"><img id="bgright" src="images/bgright1.jpg" height="100px" /></div>
</div>
</div>
和样式:
html,body {
margin:0;
padding:0;
height:100%; /* needed for container min-height */
font-family:arial,sans-serif;
font-size:small;
color:#666;
}
#bgrepeat { /* unnecessary ATM */
width: 100%;
height: 100%;
position: absolute;
z-index: 0;
}
#bgright { /* HERE THE PROBLEM */
height: 100%;
}
img { border: 0; /*float: left;*/ }
#center {
text-align: center;
height: 100%;
}
#tcontainer {
text-align: left; /* POTRZEBNE ? */
background: red;
height: 100%;
display: table;
margin: 0 auto;
}
#tleft {
display: table-cell;
}
#tright {
background: pink;
display: table-cell;
}
【问题讨论】:
-
如果我理解你的问题,它确实适用于 Chrome:jsfiddle.net/jFxXh
标签: image height center css-tables