Guide to automatically adjust child div width to match parent container dimensions

I need assistance with structuring my HTML page, which consists of header, main, and footer sections.

Below is the HTML and CSS code I'm utilizing:

HTML code :

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <link rel="icon" type="image/ico" href="/static/images/favicon.ico">
        <link rel="stylesheet" type="text/css" href="/static/css/eGirvi.css">
        <title>eGirvi ERP for jewellers</title>
    </head>
    <body>
        <div id="wrap">
            <div id="header">
                <div id="logo">
                    <img src="/media/logo.png">
                </div>
            </div>
            <div id="main">
                <div id="content">content</div>
                <div id="right-sidebar">right-sidebar</div>
            </div>
        </div>
        <div id="footer">Footer</div>
    </body>
</html>

CSS code :

/*Header div start here*/
#header{
    border: 1px dotted;
    height: 100px;
}
/*Header div end here*/

/*Logo start here*/
#logo{
    width: 100px;
    height: 100px;
}
/*Logo start here*/

/*Main start here*/
#main{
    min-height: 800px;
    border: 2px solid;
}
/*main end here*/

/*content start here*/
#content{
    min-height: 800px;
    border: 2px dashed;
    float: left;
}
/*content end here*/

/*right-sidebar start here*/
#right-sidebar{
    min-height: 800px;
    width: 100px;
    border: 2px solid;
    float: right;
}
/*right-sidebar end here*/

/*footer start here*/
#footer{
    clear: both;
    border: 1px dotted;
    height: 100px;
}
/*footer end here*/

I am looking to set the 'content' div to occupy the remaining width of the page, which would be (total page width minus the width of the right-sidebar). Can anyone provide insights or suggestions?

Answer №1

Visit: CSS Auto Width Child 'div's in Parent 'div'

XHTML

<div class="parent">
  <div class="child">...</div>
  <div class="child">...</div>
  <div class="child">...</div>
</div>

CSS Styling

.parent
{
  display: table-row;
  width: 900px;
}    
.child
{
  display: table-cell;
}

Answer №2

#main-content{ width: calc (100% - 100px);}

The sidebar is 100 pixels wide.

Answer №3

To define the width, use the following code:

width: -moz-calc(100% - 40px); /* Works in Firefox */
width: -webkit-calc(100% - 40px); /* Works in Chrome, Safari */
width: calc(100% - 40px); /* Works in IE9+ and upcoming browsers */

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

Retrieving the final item from an ng-repeat loop that has been sorted using the orderBy function

I need assistance in creating a list of terms and their definitions, each categorized under a header based on the first letter of the term. A Apple B Banana Currently, I am using the following code: <div ng-repeat="definition in definitions"& ...

What is the best way to link a file to index.html using feathers.js?

I am currently learning feathers and encountering a problem. I am attempting to include files similar to PHP's switch function. For instance: /src/middleware/index.js 'use strict'; const handler = require('feathers-errors/handler&ap ...

Unexpected data being passed in knockout click event binding

for (let i = 0; i < 9; i++) { vm.icdCodes.push({Index:i, ID:'',DiagnosisCd: '' ,Description:ko.observable('')}); } <tbody data-bind='foreach: $root.icdCodes'> <tr> <td> ...

How to align text to the bottom of a div using CSS

I am struggling to position the text 'About' at the bottom of an image. The red line marks the spot where I want the text aligned at the bottom. However, every method I try results in inconsistent outcomes when viewed on desktop and mobile device ...

What is the best way to ensure that this encompassing div adjusts its width to match that of its child elements?

My goal is to keep fave_hold at 100% of its parent div, while limiting the width of .faves to fit its child elements. These elements are generated dynamically with predefined widths. Below is the code snippet in React/JSX format: <div id='fave_h ...

Copying to the clipboard now includes the parent of the targeted element

Edit - More Information: Here is a simplified version of the sandbox: https://codesandbox.io/s/stupefied-leftpad-k6eek Check out the demo here: https://i.sstatic.net/2XHu1.jpg The issue does not seem to occur in Firefox, but it does in Chrome and other ...

Discovering the quantity of pagination tabs in Selenium WebAutomation

A critical element in the table "ContentPlaceHolder1_gvChannelList" is Pagination, located at the last row. I need to determine how many pages/columns are present in this pagination table. The code driver.findElements(By.id("//*[@id='ContentPlaceHold ...

Is it possible to arrange elements in CSS based on their attribute values?

I need to arrange a list of images in ascending order based on the index attribute using CSS. The challenge is that the index values will change dynamically and new images will be added through Ajax, so I want them to automatically update in the correct or ...

Static Header - Halts Animation on Downward Scroll, Resumes when Scrolling Ceases

I've implemented a fixed menu on my website. Everything seems to be working fine, but here's the issue: When I scroll down and the fixed menu starts animating, if I continue scrolling quickly, the animation pauses. It only continues when I stop ...

Reorder elements in CSS Grid

I've been working with a css-grid and it's almost there, but I'm stuck on reordering the items in a specific way. Currently, the html layout is set as “1, 2, 3, 4,…10”, but for smaller screens, I want the visual order to be “1, 2, 4 ...

Using ORDER BY RAND() on Internet Explorer consistently returns the same row

I am using a JavaScript function called by a button to perform an AJAX request to a PHP file. This PHP file connects to the database and echoes a random row from the database. The following PHP code is responsible for this: $value = $db->get_row("SELEC ...

What is the best way to insert a triangle shape to the bottom of a div with an opacity level set at 0.2

https://i.stack.imgur.com/sqZpM.png I've been trying to create something similar, but my triangle keeps overlapping with the background in the next section. I've already spent 3 hours on it. Any help would be greatly appreciated. Check out my c ...

Maintain the fixed position of the Google Map <div> while allowing background <div>s to scroll

I'm having trouble keeping a Google Map div fixed on the screen while allowing my background, consisting of multiple scrolling divs with content inside, to scroll as normal. My attempt to wrap the map div in another fixed div resulted in the map disa ...

React Bootstrap's drop-down components with a dark theme

In my react application, I am looking to design a custom navbar for the header using react-bootstrap. Specifically, I need a dark styled NavDropdown that changes background color to #f0ad4e on hover. Despite attempting the following code snippet, I couldn& ...

Splitting a td tag into multiple columns dynamically with Angular

I am attempting to dynamically split the table element into separate columns. My desired layout should resemble this: https://i.sstatic.net/C81tg.png The values for name and surname are fixed at 1, but the values for subjects and grades can vary (there ma ...

What is the method to ensure background images are loaded with SSL from a different domain?

I run an online store and to improve performance, the images are hosted on a different domain. However, when I switch to secure mode using SSL on certain parts of the website, the background images disappear. Trying to view the image directly in the browse ...

What is the method for retrieving embedded JavaScript content?

In an attempt to scrape a website using Cheerio, I am facing the challenge of accessing dynamic content that is not present in the HTML but within a JS object (even after trying options like window and document). Here's my code snippet: let axios = ...

Angular causes HTML Dropdown to vanish once a null value is assigned

In my scenario, I have two variables named power and mainPower. Both of these variables essentially represent the same concept, with mainPower storing an ID of type Long in the backend, while power contains all attributes of this data transfer object. The ...

Do custom Bootstrap 4 variables fail to cascade downwards?

Discovering a strange behavior in the custom.scss file of Bootstrap, I realized that setting a custom color and removing the !default flag doesn't cascade down as expected. For example, updating $blue to #000 without !default in _custom.scss should id ...

Creating dynamic HTML elements with bound JSON data

When a JSON array list of objects is retrieved from the database, it is sent to the client side upon page load of the current user control. var json = new JavaScriptSerializer(); var jsonList = json.Serialize(mylList); Page.Client ...