2

I have a site, basic CSS layout, Top bar with logo and nav, image container below it, and then content a footer.

In the 'content area' I have set up two div classes, oSection and eSection (odd and even, clever, I know). I did this so each div could have an alternating background color to easily visually break up the packets of content. However, these rows are not of equal height. They seem to expand only to the height of what content is contained within the div. Ideally, I'd like each of these divs to have the same height, regardless of how much content is in the div (I guess it would have to be as tall (same height) as largest div), but I also want to make sure they are each on their own individual line, so what I really need is equal height divs that are stacked on top of each other

I have tried using Flexbox with various properties, but it wasn't working as I expected it to.

.oSection {
    /*margin: 2% 0; */
    background-color: #E6E6E6;
    height: 50%;
    padding-left: .5%;
    padding-top: .5%;
    padding-bottom: .5%;
}
.eSection {
   /* margin: 2% 0; */
    background-color: #FFFFFF;
    height: 50%;
    padding-left: .5%;
    padding-top: .5%;
    padding-bottom: .5%;
}
<div class="oSection">
    <b>Web Design</b><br>
     Yada yada yada
</div>
<div class="eSection">
    <b>Microsoft SharePoint</b><br>
    Yada yada yada<br>
</div>
<div class="oSection">
    <b>Microsoft Dynamics CRM</b><br>
    yad yada yada
</div>
<div class="eSection">
    <b>Technology Consulting</b><br>
    yada yada yada
</div>

Here is a screenshot showing the mis-sized Divs. I want each of the horizontal divs with text in them (not header or footer, just the middle divs) to be the same height, and continue to be stacked on top of each other like they are now.

Mis-Sized Divs

0

3 Answers 3

2

I think you are after something like this.

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.oSection,
.eSection {
  flex: 1;
}
.oSection {
  background-color: #E6E6E6;
}
.eSection {
  background-color: #FFFFFF;
}
<div class="container">
  <div class="oSection"> <b>Web Design</b>

    <br/>Yada yada yada</div>
  <div class="eSection"> <b>Microsoft SharePoint</b>
    <br/>Yada yada yada
    <br/>
    <br/>
    <br/>Yada yada yada
    <br/>
  </div>
  <div class="oSection"> <b>Microsoft Dynamics CRM</b>

    <br/>yad yada yada</div>
  <div class="eSection"> <b>Technology Consulting</b>

    <br/>yada yada yada</div>
</div>

Sign up to request clarification or add additional context in comments.

3 Comments

this sets each box evenly, but if you have more text than what you set it to, each box won't flex to expand and show the rest of the text
Well it can't within the confines of this demo because there isn't room if you have a more accurate demo we might be able to adapt.
Thank you kindly @Paulie_D! I will give this a shot and see if it works for me. I think it will - and I'll just downsize it for mobile. Like I said - I may not even use it, just wanted to know it was possible and see how to implement. Thanks for taking the time
0

instead of using % use height: 480px or whatever amount you want?

I'm not sure how specific you want this, this is just speculation, I can edit my answer if you provide a screenshot of what you have vs what you want though

10 Comments

Thanks for the quick response. I cannot use px, as I am designing this to be mobile friendly as well - so Percentages, or VH/VW are my best options. I will edit the post to show you what I've got now - but I won't be able to show you what I want, but you should be able to tell pretty easily - you'll see my oSection and eSection are different heights, when I want them to be the same. Also, its only at 50% in my code just because I was trying to do an exaggerated example. It is likely to be closer to 10-15% in its final form.
then use max-height and max-width for mobile, so bascially you set the width to 100% but use max-width: 480px; to set the width
Have you tried enclosing all four of those divs in a single div that has a defined height? perhaps relative to the screen?
so basically no matter how many lines of text there are in each div, you want the the other divs to match the longest or tallest div that you have?
Well the reason it's driving you crazy because you're asking for something that is a bad practice & contradicting. You want all of them to be "equal height" which means they will be technically static regardless of the amount of content they have; yet you want them to be dynamic with percentages in a mobile context.
|
0

Flexbox can't achieve this. Only CSS Grid can, so your browser support is somewhat shallow.

The main thing is to set grid-auto-rows: 1fr on the CSS grid container and have it's height undefined.

Hre's a pen: https://codepen.io/Hlsg/pen/XgjWMz

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.