2

I am wondering if this is possible: I have a header that can contain a variable amount of text. Below that I have another element which I want to take up the remaining height of the page.

<div class="header row">
  <div class="title column large-5">Potentially very long text</div>
  <div class="menu column large-7">Menu items</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>

Normally I would do this using calc, eg:

.content {
  height: calc(100vh - 75px);
}

Where 75px is the set height of .header.

But in this example, the .header element is dynamic and does not have a set height. Only a padding and font-size are set.

To complicate things, this also uses the Foundation Grid layout, which makes me nervous about using display: table (.title and .menu sit side by side on desktop, but stacked on mobile) .

Is there anyway to get the height of the dynamic header element (without resorting to JQuery)?

2
  • 2
    Can you use flexbox? codepen.io/anon/pen/gmaape Commented Feb 28, 2017 at 6:20
  • 1
    @MichaelCoker thanks! Want to make that an answer? Commented Feb 28, 2017 at 6:39

2 Answers 2

3

You can use flexbox and set .content to flex-grow: 1 so that it will fill to grow the available space.

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
}
.content {
  flex-grow: 1;
  background: #eee;
}
<div class="header row">
  <div class="title column large-5">Potentially very long text</div>
  <div class="menu column large-7">Menu items</div>
</div>
<div class="content">
</div>
<div class="footer">
</div>

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

2 Comments

now I just need to make the 'long text' part scroll while the others remain fixed :/
Can you describe the layout a little more? Maybe make a codepen with what you're working with and describe what you want to be different?
1

I made a small pen to show the way to do this using flex box, it involved changing your markup a bit:

css:

.container {
  display: flex;
  flex-direction: column;
  height: 250px; // whatever you want here
}

.header {
  width: 100%;
  background: red;
  padding: 10px;
}

.content {
  background: yellow;
  width: 100%;
  flex-grow: 1;
}

So the content will always take the available space inside the content div.

check the whole pen: http://codepen.io/anshul119/pen/yMYeLa

hope this helps.

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.