如何保持基于百分比的元素不重叠?

时间:2013-10-27 04:46:41

标签: html css

我有带CSS的HTML页面,我正在使用百分比测量宽度,高度等。

问题是,当我通过缩小窗口来调整窗口大小时,HTML元素会在某些时候重叠。

这就是我想要做的事情:

元素应该具有一定程度的百分比测量值。但除此之外,元素应该固定,不应缩小。

我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:2)

您正在寻找min-width

div{
    width:50%;       /* Your dynamic width */
    min-width:300px; /* The narrowest the element can be */
}

http://jsfiddle.net/ejbSd/

答案 1 :(得分:1)

您可以使用min-width作为元素,或使用css3媒体查询来改变各种宽度的布局。

答案 2 :(得分:0)

听起来你应该能够使用media queries来解决这个问题。在这种情况下,你只需要:

@media (max-width: [width you want things to turn fixed]) {
  element selector {
    position: fixed;
    width: [fixedWidth];
  }
}

如果您实际上不需要fixed,则应do what others have suggested并使用min-width而不是费心去进行查询。