What is the best way to resize an HTML element to fill the remaining height?

I'm struggling with adjusting the height of a node-webkit app to fit the current window size. See below for an image depicting what I am aiming for.

Intended Goal :

HTML Markup :

<body>
<div class="header">
  THIS IS A HEADER WITH LINKS AND THINGS
</div>

<div class="content">
  <div class="sidebar">
    SIDE BAR WITH MORE LINKS AND THINGS
  </div>
  <div class="mainarea">
    <div class="chatbox">
        SOME SORT OF BOX WITH THINGS IN
    </div>
      
    <form>
        <input name="q" placeholder="type something here"/>
        <input type="submit" value="Send"/>
    </form>
      
  </div>
</div>
</body>

CSS Styling :

body {
    height: 100%;
}

.header {
    height: 80px;
    background-color: red;
}

.content {
    width: 100%;
    height: 100%;
}

.sidebar {
    float: left;
    width: 20%;
    height: 100%;
    background-color: yellow;
}

.chatbox {
    width: 100%;
    border-style: solid;
    border-width: 1px;
}

.mainarea {
    float: right;
    width: 80% !important;
    background-color: green;    
    height: 100%;
}

Live Demo:

JSFiddle Link

Answer №1

Opt for display:table-cell over float:right/left when styling .mainarea and .sidebar. Additionally:

body, html { height: 100%; margin:0; }
.content { width: 100%; height: calc(100% - 80px); display:table; }

JSFiddle

Answer №2

Utilizing flexbox is another option.

http://jsfiddle.net/gki94/

XHTML

<div class="container">
    <div class="top">TOP</div>

    <div class="middle">
        <div class="left">LEFT NAV</div>

        <div class="content-box">CONTENT BOX</div>
    </div>
</div>

CSS Styling

html, body, .container {
    height: 100%;
}

body {
    margin: 0;
    padding: 0;
}

.top {
    width: 100%;
    height: 100px;
    background-color: blue;
}

.middle {
    display:flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: stretch;
    align-items: stretch;
    width: 100%;
    height: 100%;
    background-color: pink;
}


.left {
    background-color: purple;
    width: 200px;
}

.content-box {
    background-color: turquoise;
    width: 300px;
    flex-grow: 1;
    flex-shrink: 0;
    flex-basis: 0;
}

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

Obtain user input from a form and assign it to a variable in a jQuery AJAX

How can I pass the value of an HTML Input Form to a jQuery AJAX call's URL as `amt` in `url: "http://localhost:8080/orderNo?amount=" + amt,`? The input value logs to the console when calling getAmtValue(), but I'm struggling to access the `amt` ...

What are some effective CSS styles that can be used to illustrate the concept of "loading . . ."?

I've been leveraging the power of blockUI successfully, but now I'm faced with the challenge of dynamically loading a table row. My research indicates that blockUI may not be compatible with HTML table rows. My idea is to use: jquery.AddClass(" ...

The function fromEvent is throwing an error stating that the property does not exist on the type 'Event'

I'm attempting to adjust the position of an element based on the cursor's location. Here is the code I am currently using: this.ngZone.runOutsideAngular(() => { fromEvent(window, 'mousemove').pipe( filter(() => this.hove ...

React frontend communicating without backend server

Is it possible to send a message between two frontend users on web applications built with React? ...

Internet Explorer versions 9 and 10 do not support the CSS property "pointer-events: none"

In Firefox, the CSS property pointer-events: none; functions properly. However, it does not work in Internet Explorer 9-10. Are there any alternative approaches to replicate the functionality of this property in IE? Any suggestions? ...

Unusual hue in the backdrop of a daisyui modal

https://i.stack.imgur.com/fLQdY.png I have tried various methods, but I am unable to get rid of the strange color in the background of the Modal. Just for reference, I am using Tailwind CSS with Daisy UI on Next.JS. <> <button className='btn ...

What steps should I take to resolve the textarea border bottom CSS effect?

My simple border bottom animation is working fine with a basic input element, but it's not functioning properly when used with a textarea. (If using JavaScript is necessary for a solution, please provide guidance) How can I adjust the height of a te ...

Forwarding based on URL/Query Parameters

I'm looking to create a redirect for users based on URL or query parameters, but I'm not sure how to go about it. For example, if the URL is https://www.tamoghnak.tk/redirect?link=https://www.tamoghnak.tk/gobob, I want to redirect to /gobob. If ...

Custom Wikipedia HTML template for a unique and immersive user experience

I am looking to develop a wiki website similar to Wikipedia using .Net, but I am having difficulty finding an HTML template that resembles it. Can anyone provide information on the template or framework used by Wikipedia and where I can get it? ...

Tips for submitting multiple radio button values in a tabular format

HTML Code: <div class="tab"><h4>Zip Code</h4> <p><input type="text" class="text1" placeholder="Enter zip code..." oninput="this.className = ''" name="zipcode"></p> </div> <div class="tab">& ...

struggling to access the value of a hidden field by using the parent class name

My coding experience so far looks like this- <tr class="chosen"> <td id="uniqueID">ABCDE5678</td> <input type="hidden" value="000005678" id="taxCode"> <td id="fullName">Z, Y</td> </tr> In this scenario, I need to ...

Using jQuery to drag a div and drop it to swap out an image in a different

I am looking to implement a drag and drop function where I can move elements from one div to another, each containing different images. However, I want the image displayed in the second div to change based on the element being dragged. For example: When d ...

enhancing the appearance of the initial sentence in the closing passage through CSS styling

Is there a way to make only the first sentence in the final paragraph bold using CSS? Specifically, I would like to add extra padding to the top of this last paragraph so that it wraps around an image. However, when I increase the bottom padding of the flo ...

Exploration of jQuery Dropdown Menus

Encountering a problem with my dropdown menu. Check out the code here: http://jsfiddle.net/xY2p6/1/ It seems like a simple issue that I can't figure out, but as shown in the link, the functionality is not working properly. I need help linking the hid ...

Creating a rotating circle in CSS with ion-slides: A step-by-step guide

Hello, I am attempting to develop a circular object that will rotate in the direction it is dragged. Within this circle, there are elements positioned along the border so that these elements also spin accordingly. To illustrate, below are the specific elem ...

What is the best way to make the Bootstrap navbar stay fixed at the top of the

I am currently experiencing an issue with the Bootstrap navbar while using version 5.0. Whenever the Bootstrap navbar expands, the content below it also moves down, which is not the desired behavior. I want the content to remain in place. I tried set ...

"Troubleshooting: Why is the JavaScript canvas.toDataURL method returning an

While I know this question has been asked multiple times before, I still haven't been able to find a solution. My goal is to take an image, rotate it, and place it in an HTML canvas. To achieve this, I am utilizing another canvas where I rotate the i ...

Trouble adjusting opacity with CSS in @media queries for maximum width restrictions

When building a webpage with a collapsible header and a fading large logo that transitions to a smaller version in a different location upon scrolling down on the desktop view, there seems to be an issue. The smaller logo's opacity property does not r ...

Tips for making radio button selection mandatory in an HTML5 form

How can I require a user to select one radio button in an HTML 5 form before submitting it? I attempted to use the required attribute, but since there is no radio button group, how can I apply this requirement? <form action="/Home/Sendtitle" method=" ...

Guide to updating text color in marquee tag with each reload

Seeking assistance in addressing the following issues... On each refresh, I want to change the text color within a marquee tag by utilizing a JavaScript function. I have obtained a color code like #18EEC5... however, when attempting to call the script fun ...