Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a CSS layout from distorting when zooming in/out?

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!

like image 372
Pztar Avatar asked Mar 14 '12 19:03

Pztar


People also ask

How do you make the page layout stay the same after minimized?

Add width: 1000px; to your container. Then the layout should stay consistent. Save this answer.

How do I zoom out CSS content?

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.

How do I zoom the same element size?

min-width: 100%; This will freeze the width, you can do the same for height too.

What is the best way to make your website responsive with zoom in out support?

Use the CSS zoom property to make responsive web development easier. Responsive web development is basically a requirement in 2020.


2 Answers

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

like image 132
Pztar Avatar answered Oct 08 '22 23:10

Pztar


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.

like image 36
London804 Avatar answered Oct 08 '22 22:10

London804