PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 15, 2022

[FIXED] How to calculate the height of a header in <body> tag?

 July 15, 2022     css, html, web-deployment     No comments   

Issue

How do I calculate the height of a <header> tag from a <main> tag so that I can use the calc() function to calculate the rest of the screen space available to span a banner in its place.

HTML:

<body>
  <header>
    <!-- A Navigation Bar of some sorts -->
  </header>
  <main>
    <div class="banner">
      <!-- Some text on the banner -->
    </div>
  </main>
</body>

And CSS:

.banner {
  height: calc(100vh - /* Height of <header> */);
  background-image: url(some image);
  background-position: center;
  background-size: cover;
}

Just an FYI... I'm designing for a project for college and for mobile specifically so this formatting will not span to desktop as I will change the styling for desktop and tablets


Solution

If you don't have time to learn JavaScript the easiest the thing to do is to give the header a fixed height. Than you can subtract the fixed height from the banner. It's not the most beautiful solution, but it works:

header {
  height: 80px
}

.banner {
  height: calc(100vh - 80px);
  background-image: url(some image);
  background-position: center;
  background-size: cover;
}```


Answered By - CarbonvanE
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,248,159

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing