TristanD27
TristanD27

Reputation: 89

Div to the right of a float is causing a horizontal scroll

I have a div which is floating to the left with a menu in it and another div to the right which is filling the rest of the space, the problem is, the div on the right is set to 100% but is going off to the right of the page and creating an unwanted scroll. I think the cause is the left-margin I have put on it to allow for the left floating div. Is there a way to make the right div fill the rest of the space without creating a horizontal scroll but so that I can also align things left: 0px against the edge of the float.
I have put the page onto one of my other domains so you can see:
http://aspiresupportandhousing.com/cleanserve/

HTML:

<body>
<div id="lp_bt">
    <div id="logo_container_s">
    </div>
    <div id="menu_container_s">
      <nav id="secondary_nav">
        <ul>
          <li><a href="index.html">Home</a></li>
          <li><a href="#">About Us</a></li>
          <li><a href="#">Our Services</a></li>
          <li><a href="#">Cleaning</a></li>
          <li><a href="#">Contact Us</a></li>
        </ul>
      </nav>
    </div>
</div>
<div id="left_panel">
    <div id="logo_container">
    </div>
    <div id="menu_container">
      <nav id="primary_nav">
        <ul>
          <li><a href="index.html">Home</a></li>
          <li><a href="#">About Us</a></li>
          <li><a href="#">Our Services</a></li>
          <li><a href="#">Cleaning</a></li>
          <li><a href="#">Contact Us</a></li>
        </ul>
      </nav>
    </div>
</div>
<div id="right_panel">
    <div id="main_container">
      <div id="title">
      </div>
    </div>
</div>
</body>

CSS:

html {
    height: 100%;
    min-width: 1000px;
}

* {
    margin: 0px;
    padding: 0px;
}

body {
    height: 100%;
    min-width: 1000px;
    color: #000000;
}

/* Hidden */
#lb_bt {
    height: 30px;
width: 30px;
left: 30px;
}

#logo_container_s { 
left: -150px;
width: 150px;
height: 42px;
position: absolute;
background: url(logo.jpg);
z-index: 3000;
}

#menu_container_s {
left: -150px;
height: 400px;
width: 150px;
position: absolute;
z-index: 3000;
}
/* End Hidden */

/* Left Panel */
#left_panel {
height: 100%;
width: 150px;
float: left;
background-color: #26609E;
z-index: 2000;
}

#logo_container {
width: 150px;
height: 42px;
left: 0px;
top: 0px;
position: relative;
background: url(logo.jpg);
z-index: 3000;
}

#menu_container {
height: 400px;
width: 150px;
top: 0px;
left: 0px;
position: relative;
}

ul {
list-style: none;
text-align: left;
border-top: solid 1px #002954;
}

ul li {
display: list-item; 
}

ul li a:link, ul li a:visited {
font-family: Verdana, Geneva, sans-serif;
font-size: 14px;
font-weight: normal;
width: 800;
color: #FFFFFF;
line-height: 38px;
margin: 0px 10px;
padding: 0px 5px 8px 0px;
text-align: left;
text-decoration: none;
}

ul li a:hover, ul li a:active {
color: #2593C1;
}

@media only screen and (min-width: 280px) and (max-width: 800px) {
body {
    background: none rgba(161, 220, 254, 0.4);  
}

#left_panel {
    left: -150px;
    position: absolute;
}

#lp_bt {
    top: 0px;
    left: 0px;
    background: url(menu.jpg);
    width: 30px;
    height: 30px;
}

#lp_bt:hover {
    width: 150px;
    height: 100%;
    background: none #26609E;
}

#lp_bt:hover #secondary_nav {
    display: list-item; 
}

#lp_bt:hover #logo_container_s {
    left: 0px;
    top: 0px;
    position: relative;
}

#lp_bt:hover #menu_container_s {
    top: 0px;
    left: 0px;
    position: relative;
}
}
/* End Left Panel */

/* Right Panel */
#right_panel {
height: 100%;
width: 100%;
margin-left: 150px;
background: url(bg.jpg) no-repeat top left fixed;
background-size: cover;
position: absolute;
z-index: 1;
}

#main_container {
width: 700px;
height: 50%;
margin-left: auto;
margin-right: auto;
margin-top: auto;
background: rgba(255, 255, 255, 0.8);
border-radius: 30px 30px 30px 30px;
}

#title {
width: 600px;
height: 104px;
margin-left: auto;
margin-right: auto;
top: 30px;
background: url(title.png) no-repeat center center;
position: relative;
}

@media only screen and (min-width: 280px) and (max-width: 800px) {
#right_panel {
    background: none;
}
}

Upvotes: 0

Views: 2291

Answers (3)

ColoO
ColoO

Reputation: 833

You need use CSS position.

A little example Codepen

CSS

*{margin:0;padding:0;}


#divleft {
 position:absolute;
 top:0;bottom:0;left:0;
 width:250px;
 background: red;
}

#divright {
 position:absolute;
 top:0;
 bottom:0;
 left:250px;
 right:0;
 background: green;
}

Upvotes: 0

Moob
Moob

Reputation: 16184

Seen as though #left_panel and #right_panel are positioned absolutely, you can simply remove the negative margin form #left_panel:

#left_panel {
    left: 0px;
    position: absolute;
}

... then remove the 100% width from #right_panel and position it thusly:

#right_panel {
    top:0; right:0; bottom:0; left:150px;
}

http://jsfiddle.net/Pz7PP/

Upvotes: 0

DaniP
DaniP

Reputation: 38252

Your Scroll Is caused beacuse yo have a margin-left for your

#right_panel

You have three solutions wich envolve make some changes in CSS for the #right_panel

  • One use method calc() to set the width:

    #right_panel {
       width: calc( 100% - 150px);
    }
    
  • Two change your z-index value and delete margin-left:

    #right_panel {
       width:100%;
       margin-left:0;
       z-index:-1;
    }
    
  • Three use box-sizing and padding instead of margin:

    #right_panel {
      box-sizing:border-box;
      padding-left:150px;
      width:100%;
      margin:0;
    }
    

Upvotes: 1

Related Questions