Expanding divisions vertically without the constraints of fixed heights

Instead of resorting to fixed heights and absolute positioning with top: and bottom:, I'm challenging myself to find a CSS solution without using those methods. I want to explore different ways to solve this problem and enhance my skills.

I have a standard navbar at the top and a scrolling content div below it.

The challenge is fitting the bottom scrolling div container into the remaining space without relying on absolute coordinates. Using position: absolute won't work because that requires knowing the height of the navbar for top:. And setting "bottom: 0" would mean specifying a fixed height, which we want to avoid.

You can view the JSFiddle here:

http://jsfiddle.net/8dugffz4/1/

The specified class is ".result". Currently, the height is fixed, but I'm aiming to make it dynamic.

Thank you. PT

CSS:

* {
  font-family: Helvetica, Sans;
  border: 0px;
  margin: 0px;
  padding: 0px;
}

.navBar {
  width: auto;
  overflow: auto;
  border-bottom: 1px solid #bbb;
}

.pageBar {
  float: right;
}

.pager {
  cursor: pointer;
  float: left;
  border: 1px solid #bbb;
  width: 2em;
  height: 2em;
  line-height: 2em;
  text-align: center;
  margin: 5px;
  margin-left: 0px;
  background: #eee;
  color: #bbb;
}

.pager:hover {
  background: #777;
  border: 1px solid black;
  color: white;
}

.fliph {
  -ms-transform:scale(-1,1); /* IE 9 */
  -moz-transform:scale(-1,1); /* Firefox */
  -webkit-transform:scale(-1,1); /* Safari and Chrome */
  -o-transform:scale(-1,1); /* Opera */
}

.results {
  background: gray;
  width: 100%;
  height: 200px;
  overflow: scroll;
}

.line {
  height: 10em;
  line-height: 10em;
  border: 1px solid red;
}

HTML:

<body>
    <div class='navBar'>
        <div class='pageBar'>
            <div class='pager'>&#9665;</div>
            <div class='pager'>1</div>
            <div class='pager fliph'>&#9665;</div>
        </div>
    </div>
    <div class='results'>
        <div class='line'>Line1</div>
        <div class='line'>Line2</div>
        <div class='line'>Line3</div>
        <div class='line'>Line4</div>
    </div>
</body>

Answer №1

Check out this innovative solution using display: table to create fluid heights:

http://jsfiddle.net/8dugffz4/8/

For a quick look at the code, here's a simple snippet of what was done:

* {
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
}
#table {
  display: table;
  height: 100%;
  width: 100%;
}
#table > div {
  display: table-row;
}
#navbar {
  height: 45px;
  opacity: .5;
}
#navbar > div {
  height: 100%;
  background: black;
}
#results {
  height: 100%;
}
#results > div {
  height: 100%;
  overflow: auto;
  background: green;
}
<div id="table">
  <div id="navbar">
    <div></div>
  </div>
  <div id="results">
    <div></div>
  </div>
</div>

Answer №2

If you're in search of a different approach than using the position: absolute technique, you might consider utilizing the height: 100% method:

html, body { height: 100%; }
body { box-sizing: border-box; padding-top: 45px; }
.navBar { height: 45px; margin-top: -45px; }
.results { height: 100%; }

For example: http://jsfiddle.net/8dugffz4/7/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can a javascript code for "Infinite Scroll" be created to manage the back button?

Head over to this website: Experiment with the infinite scroll feature. You may notice that when you click a link and then press "back", there are some glitches. Therefore, I am considering developing my own version of an Infinite Scroll functionality. ...

Creating a for loop using jQuery to append the value of [i] to the string "id" for the element

As a newcomer to programming, my code may not be the best. I am attempting to automate game results (1 / X / 2) based on the input of home and away goals in a form. To achieve this, I need assistance with my jQuery for loop. Here is the current code: for ...

Mastering the Zurb Foundation equalized grid: aligning content at the bottom of a div within a grid cell

One common challenge is how to position content at the bottom of a div, but with Flexbox, it's becoming easier nowadays. In my case, I'm using the Zurb Foundation grid with equalisation. This equalisation is crucial because my cells have an imag ...

Creating a form that is unable to be submitted

Can a form be created in HTML without the ability to submit, all while avoiding the use of JavaScript? I would like to utilize <input type="reset"> and have intentionally omitted an <input type="submit">, but there is still the possibility for ...

Stopping CSS animations at a specific point along the path without using timing functions can be achieved by implementing a targeted

Is there a way to pause an animation at the 50% mark for 2 seconds and then resume? P.S. The setInterval method is not recommended! function pauseAnimation() { document.getElementById("0").style.animationPlayState = "paused"; }; var pauseInterval = set ...

The Angular Tooltip feature is unable to interpret the characters "' '" or "' '"

Let me explain the scenario: I am receiving a list of objects from my back-end service, which I then break apart using ngFor and display accordingly. Each item in the list has an associated toolTip that provides additional information. The info for each i ...

What is the best way to conceal floated elements with overflow in CSS?

How can I ensure that my block container element only displays the content of block elements, cutting off any floated elements that are taller than the parent container? Applying overflow: hidden seemed like a simple solution, but it created a new block f ...

Arranging Form Elements with Bootstrap styling

Check out the Bootply I created to demonstrate an issue I'm facing: http://www.bootply.com/8fPmr31Wd7 When scrolling down, you'll notice that "People" and "Places" are indented on the sides. It's possible that I'm not using the correc ...

What are the implications of implementing this particular CSS code?

One common thing I come across on websites is this snippet of code: body:before { content: ""; width: 0; height: 100%; float: left; margin-top: -31700px; } What happens when this CSS is implemented? ...

Tips for creating a functional Submit button in HTML

How can I ensure that the submit button sends the necessary information to my email address when clicked (e.g. [email protected])? If PHP is required, please provide the code so I can easily integrate it into my project. Thank you! <div id="forms ...

What does the error message "Uncaught TypeError: Cannot access property 'style' of an undefined object" mean?

I've been attempting to execute the code below, but I keep encountering an error. I even tried including document.addEventListener('DOMContentLoaded', (event) => yet it still doesn't work. Interestingly, there are no errors if I run ...

Is AJAX malfunctioning while the success function is functioning properly?

the function for success is operational, however the data isn't being saved in the database $(document).ready(function() { $("#ChatText").keyup(function(e){ if(e.keyCode == 13) { var ChatText = $("#ChatText").val(); ...

Stop the Text Table from being highlighted

My webpage includes a dynamic table where users can select multiple rows. jQuery events and CSS are utilized to provide visual feedback when a row is selected. However, pressing the shift key sometimes causes text to become highlighted, which is not idea ...

Display a progress bar in Bootstrap with a labeled indicator positioned above the bar and background to the

Is there a way to create a progress bar with a label positioned to the right using Bootstrap v5.2 Progress Bar? https://i.sstatic.net/gOWie.png I attempted to use negative margins to achieve this layout but faced issues when the label expanded due to lon ...

Set maximum size for background image in div

I'm facing some challenges with setting the maximum height of a background image within a div. I want the max height to be equal to the actual height of the image, without stretching it. Ideally, if there is excess content in the div, it should stop a ...

What is the best way to arrange cards in a horizontal stack for easy carousel viewing later on

My main objective is to design a unique card carousel where users can navigate through the cards by clicking on arrows placed on the left and right sides. The approach I am considering involves stacking multiple card-decks and smoothly transitioning to th ...

Creating an easy-to-update catalog utilizing an external file: A step-by-step guide

I am looking to create a product catalog with 1-4 products in a row, each displayed in a box with details and prices. I would like to be able to generate the catalog easily using an XML/CSV file that can be updated. Can anyone provide guidance on how to ac ...

Can we retrieve the CSS of an element?

Using Selenium's webdriverJS, I have automated tasks on an HTML5 page. To incorporate a CSS selector into a function, I had to rely on XPath for selecting elements: var complexXpath = "//*/div/a"; /* This is just an example */ var element = mydri ...

Maximizing the width of navbar elements with Bootstrap 3

I am currently working on building a webpage with bootstrap3, but I have encountered an issue with the navigation bar. I would like the navigation links ("Web Design", "Development", "Photography", "Blog") to be evenly spaced out within the horizontal na ...

Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while au ...