1

I have two divs side by side. The div on the left side is a basic navigation. The div on the right is an article. I want the div on the left to be the height of the viewport and the div on the right to hide anything that longer than the div on the left (the end goal is to have a stick side bar that takes up 1/3 of the screen). I’ve considered using flexbox, but haven’t used it before and wasn’t sure if this is the best method to go.

I tried setting the height of the left div to 100vh as suggested in this article: Make div 100% height of browser window but it didn’t work. I’ve seen suggestions regarding using tables but would prefer avoiding them. I’ve seen some suggestions regarding using jquery and having the right div resize itself based on the left, but this seems a little more complex then necessary.

Note: Most articles I've seen about matching div heights seems geared toward making the smaller div match the height of the larger. My issues is the opposite. I want the larger div to match the height of the smaller one and hide any extra content. However I’m open to any suggestions.

<doctype="HTML">
<html>
<head>
  <title>Web Hosting Issues</title>
  <style>@import url('https://fonts.googleapis.com/css?family=Open+Sans');
  </style>
</head>

<body>
  <header>
    <div id="logo">
     <a href="home">
       <h1>Website</h1>
       <img>
     </a>
    </div>
    <navigation>
      <ul>
        <div class="nav-row">
          <li id="site-down">
            <a href="site-down-url">
              <img>Site Down
            </a>
          </li>
          <li id="wordpress">
            <a href="wordpress-url">
              <img>Wordpress
            </a>
          </li>
        </div>
        <div class="nav-row">
          <li id="migrations">
            <a href="migrations-url">
              <img>Migrations
            </a>
          </li>
          <li id="backups">
            <a href="backups-url">
              <img>Backups
            </a>
          </li>
        </div>
        <div class="nav-row">
           <li id="databases">
               <img>Databases
             </a>
           </li>
           <li id="domains">
             <a href="domains-url">
               <img>Domain
             </a>
           </li>
        </div>
      </ul>
    </navigation>
    <div id="contact-us">
      <a href="contact-form">
        <img>
        <div>
          <h2>Have Us Fix It</h2>
          <button id="contact-button">Contact Us</button>
        </div>
      </a>
    </div>
  </header>


    <article>
      <h1>Article Title</h1>
      <p>Lorem ipsum dolor sit amet, mei hinc graeci vituperatoribus et. Pri stet copiosae mediocrem eu. Mollis inimicus mel id, mutat mentitum vix an. No pro virtute intellegam, ea has epicurei referrentur, posse oporteat ius ei.</p>

  <p>Libris appellantur et pro. Insolens ocurreret salutatus et sit. Mei ea aeque ludus aliquando, at hinc ponderum comprehensam cum. Eu nam mandamus expetenda dissentiunt, probo tacimates at eos, no everti docendi sed. Id appetere democritum nam.</p>

  <p>Odio animal aperiam ea sit. Debet accumsan ne pro, eos simul perfecto invenire ea. Per ea quaestio consulatu. Eos vide repudiare id, mei cu ridens possim assentior, te probo intellegat vim. Has etiam incorrupte an. Id oratio verear audire mei, reque tincidunt duo ex.</p>

  <p>Eum erant putant vocent ei. At dico exerci quo. Pri melius ocurreret persequeris in, eu noster virtute est. Aeque commodo ut duo. In sit melius dignissim, te has lorem minimum consectetuer.</p>

  <p>Pri oratio vocibus vituperatoribus te, dolores persecuti sit ut. Esse munere eam ea, possim mentitum moderatius nec at. Doming gubergren ut mei, luptatum salutatus scriptorem mei an. Nec partem ponderum assueverit cu, veri erat libris his ad, ad vidisse docendi ius. At everti dolores disputationi vel, nec cu diceret eleifend. Pri cu falli erant, tamquam democritum ad sit, vis illum inani in. Apeirian nominati sed at, ei atomorum accommodare usu, has modus definitionem te.</p>
    </article>

  </body>
  </html>


body {
  font-family: 'Open Sans', sans-serif;
  display: flex;
}

img {
  max-width: 100%;
  display: block;
  margin: auto;
}
header { 
  float: left;
  width: 50%;
}

header a {
  text-decoration: none;
}

#logo, #contact-us {
  background: #074f7b;
  padding: 0.5em;
}

#logo h1 { 
  display: inline-block;
  text-align: center;
  font-family: sans-serif;
  color: white;
  float: left;
  width: 68%;
}

#logo img {
  float: left;
  width: 30%;
  padding-left: .4em;
  color: white;
}


#logo::after{
  content: " ";
  display: block; 
  height: 0; 
  clear: both;
}
navigation {}

navigation:after {
  visibility: hidden;
    display: block;
    content: "";
    clear: both;
    height: 0;
}

navigation ul {
  margin: 0;
  padding: 0;
}

.nav-row {}

.nav-row li {
  width: 50%;
  float: left;
  display: inline-block;
  min-height: 100px;
}

.nav-row a {
  display: block;
  padding: .5em;
  text-align: center;
  color: black;
}

.nav-row a:hover {
  color: white;
}

#site-down {
  background: #ffc219;
}

#wordpress {
  background: #8f73b4;
}

#migrations {
  background: #0778bb;
}

#backups {
  background: #f06f26;
}

#databases {
  background: #764821;
}

#domains {
  background: #59bb53;
}

#contact-us h1, #contact-us img{
  color: white;
}

#contact-us {
  text-align: center;
}

#contact-us img {
  float: left;
  width: 45%;
  text-align: center;
  padding: 0 .5em
}

#contact-us div {
  width: 50%;
  float: left;
  text-align: center;
}

#contact-us h2 {
  color: white;
  margin: 0em 0em .5em 0em;
  padding-left: 0.625em

}
#contact-us::after{
  content: " ";
  display: block; 
  height: 0; 
  clear: both;
}

#contact-us button {
  background: #8f73b4;
  border-radius: .6em;
  border: 1px solid #8f73b4;
  color: white;
}

article {
  float: right;
  width: 50%;

}

article h1, article p {
  margin: 1.563em;
}

article h1 {
  text-align: center;
}
Community
  • 1
  • 1
strasbal
  • 143
  • 1
  • 11
  • 1
    Can you please add both your HTML and CSS so we can see what you're dealing with? – Obsidian Age Jan 26 '17 at 23:31
  • I really don't get your question... Most probably you made it too long to follow?! So you want a sticky left "aside" navigation and a scrollable right "page-content" element? What went wrong? What's the desired result? – Roko C. Buljan Jan 26 '17 at 23:52
  • Yes, a stick left aside and a scrollable right element. – strasbal Jan 26 '17 at 23:52
  • http://stackoverflow.com/questions/2997767/ – Stephen P Jan 27 '17 at 01:29
  • Found a solution using flexbox. http://stackoverflow.com/questions/38852811/create-a-row-of-flexbox-items-with-a-max-height-defined-by-one-child/38852981#38852981 – strasbal Jan 27 '17 at 21:38

1 Answers1

2

You could simply position:fixed; your left menu:

/*QuickReset*/*{box-sizing:border-box; margin:0;}html,body{height:100%;}

#menu{
  position:fixed;
  background: #8F73B4;
  height:100%;
  width: 33.333%;
}

#page{
  margin-left:33.333%;  /* matches the menu width */
  height: 2000px;       /* test: just to add scrollbars */
}
<div id="menu"> MENU BOXES HERE </div>
<div id="page"> PAGE CONTENT HERE </div>

Than for the menu elements/boxes I'd go with flexbox

JSBin demo

/*QuickReset*/
*{box-sizing:border-box;margin:0;}
html,body{height:100%;font:14px/1.4 sans-serif;}

.flex-col{
  display: flex;
  flex-flow: column wrap;
}
.flex-row{
  display: flex;
  flex-flow: row wrap;
}
.grow{
  flex: 1;
}

img{
  max-width:100%;
  vertical-align:top;
}

#menu{
  position:fixed;
  background: #8F73B4;
  height:100%;
  width: 33.333%;
}

#page{
  margin-left:33.333%;  /* matches the menu width */
  height: 2000px;       /* test: just to add scrollbars */
}
<div id="menu" class="flex-col">
  
  <header>header</header>
  
  <div class="flex-row grow">
    <div class="grow">1</div>
    <div class="grow">2</div>
  </div>
  
  <div class="flex-row grow">
    <div class="grow">3</div>
    <div class="grow">4</div>
  </div>
  
  <footer>footer</footer>
  
</div>
  
  
<div id="page">
  <h1>PAGE CONTENT HERE</h1>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. At recusandae explicabo numquam molestiae, debitis eius deserunt cum necessitatibus aspernatur. Excepturi omnis, tenetur nihil voluptatibus hic incidunt doloribus itaque delectus dolorum!</p>
</div>

P.S: <navigation> is not a HTML5 element. You probably want to use <nav> for your semantic.

Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • I like this solution, but it's cutting off a portion of the navigation. I tried setting a max height on the menu but it didn't fix it. You can see the results here: http://codepen.io/strasbal/pen/zNEMpj – strasbal Jan 27 '17 at 00:08
  • @strasbal that's cause your menu boxes are not height-responsive :) – Roko C. Buljan Jan 27 '17 at 00:11
  • @strasbal I'll try to make a jsBin demo – Roko C. Buljan Jan 27 '17 at 00:14
  • Shoot, I was under the assumption they would be since I'm not using a fixed width or height for the elements. Looks like I'm gonna have to go back and figure what's stopping them from auto-resizing, unless you have any suggestions. – strasbal Jan 27 '17 at 00:14
  • @strasbal well whatever i'll show you will not be a super-final usable example, since your page has to work on a variety of media... But for sure you need to work out on % responsive units. – Roko C. Buljan Jan 27 '17 at 00:19
  • Ok. I haven't dived into the responsive aspect yet, but the solution your provide solves the issue. Thanks, wasn't able to wrap my head around what I was doing wrong! – strasbal Jan 27 '17 at 00:21
  • @strasbal edited my answer to give you a hint on how I'd manage the menu boxes... – Roko C. Buljan Jan 27 '17 at 00:37