Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2013
    Location
    Finland/Estonia
    Posts
    53
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Div moves down when window/screen resolution changes

    Hello. I got this annoying little glitch in my code, when I resize the window/zoom browser/view my site on a different sized screen my div moves down about 30px maybe. On some screens and settings it is just fine.
    How it should be:

    What it does sometimes:


    HTML is simple.
    Code:
    <div id="holder">
    <div id="flatHolder">
        <div id="lastupload">
    </div>
        <div id="subscribe">
    </div>
        <div id="modpack">
    </div>
        <div id="announcementsIndex">
    </div>
    </div>
    
    
    More content that doesn't really have to do anything with this...
    </div>
    CSS
    Code:
    #flatHolder
    {
    height:400px;
    width:100%;
    background:#666;
    }
    #holder
    {
    margin:auto;
    width:100%;
    background-color:#FFF;
    min-height:500px;
    overflow: hidden;
    z-index:0;
    }
    #modpack
    {
    float:right;
    height:200px;
    width:200px;
    }
    #subscribe
    {
    float:right;
    color:#FFFFFF;
    width:200px;
    min-height:40px;
    z-index:30;
    background-color:#0066FF;
    background-color:#545454;
    }
    #lastupload
    {
    float:left;
    }
    Edit: The post was based on experience of chrome, this happens in firefox 100% of the time, unlike in chrome.
    Last edited by estXcrew; 01-28-2014 at 08:19 PM.

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello estXcrew,
    The code you provide doesn't reproduce the problem.

    A few issues I see:

    You do have multiple floats, one without dimensions of any kind, so you have to wonder what it's supposed to look like.

    You don't follow the box model rule. See the box model here. The box model says that whatever you put inside an element cannot be larger than that element. margin/padding/border all count when figuring width/height. When you set containing #flatHolder to a height of 400px, how does 500px tall #holder fit?

    You use z-index on elements that are not positioned.

    Mulitiple background colors

    Maybe this will give you some ideas?
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	background: #fc6;
    }
    #holder {
    	width: 100%;
    	background: #fff;
    }
    	#flatHolder {
    		width: 100%;
    		overflow: auto; /*to clear the floats*/
    		padding: 0 0 200px; /*demo only*/
    		background: #666;
    	}
    		#lastupload { float: left; }
    		#subscribe {
    			min-height: 40px;
    			float: right;
    			width: 200px;
    			color: #FFFFFF;
    			background: #0066FF;
    		}
    		#modpack {
    			height: 200px;
    			width: 200px;
    			float: right;
    			background: #f00;
    		}
    </style>
    </head>
    <body>
    	<div id="holder">
    		<div id="flatHolder">
    			<div id="lastupload"> </div>
    			<div id="subscribe"> </div>
    			<div id="modpack"> </div>
    			<div id="announcementsIndex"> </div>
    		</div>
    	More content that doesn't really have to do anything with this... 
    	</div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    New Coder
    Join Date
    Jul 2013
    Location
    Finland/Estonia
    Posts
    53
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thank you . I added overflow:auto; to the flatHolder div and it let the div flowed up all the way. I will surely try to follow the box model. Thank you again.

    I got one question, What do you mean by this?

    When you set containing #flatHolder to a height of 400px, how does 500px tall #holder fit?
    That you can't fit a 400px tall div into a MINIMUM of 500px tall one because 400px is higher than 500px? Makes no sense.
    None of these elements have borders/padding/margin either so I don't get it.
    Last edited by estXcrew; 01-28-2014 at 09:16 PM.

  • #4
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Quote Originally Posted by estXcrew View Post
    Thank you . I added overflow:auto; to the flatHolder div and it let the div flowed up all the way. I will surely try to follow the box model. Thank you again.

    I got one question, What do you mean by this?


    That you can't fit a 400px tall div into a MINIMUM of 500px tall one because 400px is higher than 500px? Makes no sense.
    None of these elements have borders/padding/margin either so I don't get it.
    See how overflow: auto; is clearing your floats here.

    Your first post is putting 500px high or higher #holder inside 400px #flatHolder, which is the opposite of what you've just explained here.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •