gpt4 book ai didi

css - 如何阻止 CSS 布局在放大/缩小时变形?

转载 作者:行者123 更新时间:2023-12-02 18:01:58 25 4
gpt4 key购买 nike

我已经建立了一个非常基本的网站,其中包含#container div,其中包括#navbar 和#content。但是,当我放大或缩小时,#navbar 会扭曲,如果我放大,链接会被推到彼此下方而不是内联。如果缩小,链接之间会添加过多的填充。我怎样才能阻止这个?

HTML:

<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。是对的吗?还有什么需要指出的,请告诉我。

最佳答案

由于这个问题仍然得到不断的关注,我将发布我当前使用的解决方案。

CSS 媒体查询:

@media screen and (max-width: 320px) { 

/*Write your css here*/

}

@media screen and (max-width: 800px) {

}

查看: CSS-Tricks + device sizesMedia Queries

关于css - 如何阻止 CSS 布局在放大/缩小时变形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9709125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com