Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make elements stop from moving when resizing the window after using percentage

Tags:

html

css

So I have divs that I have within my webpage .. like header , or div boxes .. they adjust fine on bigger screen sizes so that they dont look too tiny on a big monitor , but the issue is that when I resize the window or browser to make it small , all the elements move along till they reach a point where they all meet and it gets ugly .. How can I make it so the divs I have adjust to bigger screen sizes becoming bigger as well , but then stop them from moving along with the window when resizing the window making it smaller ??? I used percentages from all the elements I want to readjust and make bigger on bigger /wider screens

Below is an example of my code .. my header and other elements with these classes move to the point where they overlap when resizing the window

.header{
        position:absolute;
        top:0px;
        width:100%;
        height:100px;
        left:0;
        background:#EB6A4A; 
    }

    .slogan{
        position:absolute;
        top:60%;
        left:40.5%;
    }

    .login{
        position:absolute;
        top:15%;
        left:90%;
    }

        .whitebackground{
        background:#FFFFFF;
    }
like image 363
Stack Overflow Avatar asked Oct 14 '13 18:10

Stack Overflow


People also ask

How do you stop a moving element in HTML?

Basically, by giving an element absolute positioning, it is no longer being taken into account when positioning the rest of the page. It will take up its alloted space in its set position no matter what. In your case, the div was moving relative to the elements surrounding it.

How do I stop a browser window from resizing after a specific size?

You can not control the size of the window. You can use CSS to set min-width and min-height properties to ensure your page layout stays sane. using 'window. open' I can open a page with a fixed height width.

How do you stop an element from resizing?

To prevent a text field from being resized, you can use the CSS resize property with its "none" value. After it you can use the height and width properties to define a fixed height and width for your <textarea> element.

How do I stop a DIV from resizing?

It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none.


1 Answers

I'm not sure about your question because you didn't post any code but i think that your solution can be using css style:

max-width:50%;
min-width:800px;
max-height:500px;
min-height:21%;

properties in pecentage or pixel as you prefer, so you can tell divs how much expand and how much get smaller.

Hope it helps, if you post your code maybe i can be more useful.

Regards

EDIT 1:

This should resolve your problem:

*{
    margin: 0;
    padding: 0;
    text-decoration: none;
    color: inherit;

}
.header{
        position:relative;
        float:left;
        top:0px;
        width:100%;
        height:100px;
        left:0;
        background:#EB6A4A; 
    }

    .slogan{
        position:relative;
        float:left;
        top:60%;
        left:40.5%;
    }

    .login{
        position:relative;
        float:left;
        top:15%;
        left:90%;
    }

        .whitebackground{
        background:#FFFFFF;
    }

Just do the same with the class you didn't poste in css. The idea is having all items with position relative and floated on the left so they don't move. Should work!

like image 172
SBO Avatar answered Sep 22 '22 21:09

SBO