我建立了一个非常基本的站点,包含#container div,其中包含#navbar和#content。但是,当我放大或缩小时,#navbar会扭曲,如果我放大链接,链接会被推到彼此下方,而不是内联。如果我缩小,链接之间会添加太多填充。我如何才能阻止这种情况?
超文本:
<div id="navbar">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="top.html">Top</a></li>
<li><strong><a href="free.html">FREE</a></strong></li>
<li><a href="photo.html">Photo</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</div>
<div id="content">
<p>Some sample text.<p>
</div>
</div>
CSS:
#container {
position: static;
background-color: #00bbee;
margin-left: 20%;
margin-right: 20%;
margin-top: 7%;
margin-bottom: 15%;
border: 2px solid red;
}
#navbar ul{
list-style: none;
}
#navbar li{
display: inline;
}
#navbar li a{
text-decoration: none;
color: #11ff11;
margin: 3%;
border: 1px dotted orange;
padding-left: 4px;
}
#navbar li a:hover {
background-color: white;
color: green;
}
#navbar {
background-color: #eeeeee;
padding-top: 2px;
padding-bottom: 5px;
border: 1px solid yellow;
}
我怎样才能阻止它扭曲呢?
另外,我对CSS还是一个新手,我被教导使用%而不是px。对吗?还有任何其他你要指出的,请让我知道。
9条答案
按热度按时间nafvub8i1#
由于这个问题仍然得到不断的意见,我将张贴我目前使用的解决方案。
CSS媒体查询:
checkout :CSS-Tricks + device sizes和Media Queries
yftpprvb2#
我也遇到过类似的问题,我在导航菜单周围添加了一个额外的div,然后添加了以下内容
这使它无法 Package 希望能起作用。
1wnzp6jl3#
要解决放大问题,请尝试将
min-width
属性添加到外部计数器(#container
还是#navbar
?)。设置min-width
可防止网页尝试缩小到超过指定宽度(IidoE.300px)。如果你放大得太远,而不是<div>
内部的元素跳到下一行,你的导航条将停止收缩并且一个滚动条将出现在页面的底部.示例(在样式表中):
另一个很好的实现方法是将min-width属性应用于页面主体。
示例(在样式表中):
最后,如果你想让你的导航栏横跨页面的整个宽度,在样式表中使用
{clear:both;}
。uajslkp64#
嗯......你试过添加最小宽度/最小高度属性吗?你可以把这些属性包含在你的#container div中。这可能会很有用。
cuxqih215#
不同的浏览器使用不同的缩放技术。它们都有缺点。使用百分比会引入舍入误差。没有简单的答案。
参见:http://www.codinghorror.com/blog/2009/01/the-two-types-of-browser-zoom.html
nkhmeac66#
我只需要为页面上的所有元素/div设置绝对高度和宽度。
ID {高度:250像素;宽度:500像素}
或者您也可以使用min/max-width/hight来调整不同屏幕大小或调整浏览器窗口大小时的页面布局。
dgenwo3n7#
这主要是因为你已经设置了你的宽度或边距的百分比属性。如果你这样做,请确保你提供的最大宽度,这样的元素
gdrx4gfi8#
给你,这很像上面的建议,但是它有一个固定宽度的内容区域,如果你想找全宽度的,对不起(;_;)
6tqwzwtp9#
你会想要使用一个css媒体查询来设置css中不同样式的断点,如果使用正确的话,它将修复任何失真问题。