如何使用高度:如果未定义容器高度,则为50%?(How to use height:50% if the container height is not defined?)

编程入门 行业动态 更新时间:2024-10-20 09:27:17
如何使用高度:如果未定义容器高度,则为50%?(How to use height:50% if the container height is not defined?)

我想使用高度:50%,但容器的高度没有定义,什么是正确的解决方案?

<div id="container"> <div id="left-50"> <div id="left-50-1">1</div> <div id="left-50-2">2</div> </div> <div id="image"> <img src="http://automarka.hu/images/stories/Audi%20A8%202.8%20V6%20FSI%202007.jpg"> </div> </div> #container { overflow:hidden; } #left-50 { float:left; } #left-50-1 { height:50%; width:50px; background:yellow; } #left-50-2 { height:50%; width:50px; background:purple; } #image { float:left; }

Jsfiddle网址: http : //jsfiddle.net/XqMDF/

I would like to use height:50%, but the container's height is not defined, what's the correct solution?

<div id="container"> <div id="left-50"> <div id="left-50-1">1</div> <div id="left-50-2">2</div> </div> <div id="image"> <img src="http://automarka.hu/images/stories/Audi%20A8%202.8%20V6%20FSI%202007.jpg"> </div> </div> #container { overflow:hidden; } #left-50 { float:left; } #left-50-1 { height:50%; width:50px; background:yellow; } #left-50-2 { height:50%; width:50px; background:purple; } #image { float:left; }

Jsfiddle url: http://jsfiddle.net/XqMDF/

最满意答案

正确的解决方案是定义容器高度。 或参考身体或其他定义的元素。

make container display:inline-block; 调整图像高度...或定义固定高度。

演示:http://jsfiddle.net/XqMDF/2/

the correct solution is to define container height. or refer to the body or other defined element.

make container display:inline-block; to adjust to image height ... or define a fixed height.

DEMO: http://jsfiddle.net/XqMDF/2/

更多推荐

本文发布于:2023-08-04 08:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412509.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高度   则为   如何使用   容器   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!