I've set up a very basic site with a #container div that includes the #navbar and #content. However, when I zoom in or out, the #navbar distorts, if I zoom in the links get pushed down below each other instead of being inline. If I zoom out, too much padding is added between the links. How can I stop this?
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;
}
How can I stop it from distorting?
Also, I'm still pretty new to CSS, I was taught to use % instead of px. Is that right? Also anything else you've got to point out, please let me know.
Thanks in advance!
Add width: 1000px; to your container. Then the layout should stay consistent. Save this answer.
The non-standard zoom CSS property can be used to control the magnification level of an element. transform: scale() should be used instead of this property, if possible. However, unlike CSS Transforms, zoom affects the layout size of the element.
min-width: 100%; This will freeze the width, you can do the same for height too.
Use the CSS zoom property to make responsive web development easier. Responsive web development is basically a requirement in 2020.
As this question still gets constant views, I'll post the solution I use currently.
CSS Media Queries:
@media screen and (max-width: 320px) {
/*Write your css here*/
}
@media screen and (max-width: 800px) {
}
Check out: CSS-Tricks + device sizes and Media Queries
I had a similar problem that I fixed by adding an extra div around my navigation menu. I then added the following
#menu-container {
position: absolute;
white-space: nowrap;
overflow: hidden;
}
This prevented it from wrapping. Hope it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With