Set the width of the left div in percentage and have the right div automatically fill

In my layout, I have a left div with a percentage width floating to the left, and a right div also floating left that should take up the remaining space. Here is a [fiddle] link for reference: https://jsfiddle.net/gfhfku8k/. Any assistance would be greatly appreciated. Thanks!

HTML:
<div class="container">
  <div class="left">

  </div>
  <div class="right">

  </div>
</div>
CSS:
html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
.container {
  width: 100%;
  height: 100%;
  border: 1px solid #000;
}
.left {
  width: 30%;
  height: 100%;
  float: left;
  border: 1px solid #000;
  overflow: hidden;
}
.right {
  height: 100%;
  /* width: 30px; */
  overflow: hidden;
  float: left;
  border: 1px solid #f00;
}

Answer №1

If setting width: 70% on the right column isn't the solution you're seeking, achieving this type of layout is best done using flex. Here's how it functions:

It should be noted that I have eliminated the float attribute from the columns and included box-sizing: border-box to all elements (*) for proper functionality (although it's optional for this demonstration).

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
}
* {
  box-sizing: border-box;
}
.container {
  width: 100%;
  height: 100%;
  border: 1px solid #000;
  /* flex */
  display: flex;
}
.left,
.right {
  border: 1px solid #000;
  overflow: hidden;
}
.left {
  background: pink;
  width: 30%;
}
.right {
  background: blue;
  /* flex */
  flex-grow: 1;
}
<div class="container">

  <div class="left">
  </div>

  <div class="right">
  </div>

</div>

Answer №2

Give this a shot

.right {
  height: 100%;
  overflow: hidden;
  border: 1px solid #f00;
}

Simply eliminate the float:left property from the .right class.

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

Ways to incorporate the setTimeOut function

<body> <script> $(window).scroll(function() { $('#csgo').each(function(){ var imagePos = $(this).offset().top; var topOfWindow = $(window).scroll ...

AngularJS Material Design sticky header MD table container

I am looking to create a table container to display records with a unique requirement - when the table reaches the top of the screen, its header should stick in place. Can you provide guidance on how to implement this feature? For reference, please check ...

The AJAX POST request is not receiving the JSON data as expected

After creating an HTML form with the following structure: <form id="loginForm" name="loginForm"> <div class="form-group"> <input type="username" class="form-control" id="username" name="username" placeholder="Your username..." > ...

What is the best way to position the logo on the left side and the navigation on the right

How can I position my logo to the left of the navigation bar? This is my current HTML code: <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> <link rel="icon" type="image/png" href="SENCOR_Logo.ico"> & ...

The CSS grid functionality seems to be malfunctioning on a specific page, yet it operates perfectly on other

I'm currently working on my Portfolio application, but I'm facing an issue on the home page where the grid layout is not functioning properly. The different div tags are overlapping each other instead of displaying correctly. https://i.sstatic.n ...

Troubleshooting spacing problems in Angular Material tables

I'm attempting to utilize an Angular Material table in the following way: <div class="flex flex-col pb-4 bg-card rounded-2xl shadow overflow-hidden"> <table mat-table class="" [dataSource]="$candidates ...

Looking for guidance on sending data from a JS file to HTML using Nodejs? Seeking advice on various modules to achieve this task effectively? Let's

Looking for advice on the most effective method to transfer data from a JS file (retrieved from an sqlite db) to an HTML file in order to showcase it in a searchable table. My platform of choice is NodeJS. As a beginner, I am willing to put in extra time a ...

PHP - Sending selected option value to index.php to add new user

In my nuevo.php file, which translates to 'new client', I have set up a form to insert data into a MySQL database. The form includes various input fields such as: <label for="Nombre">Nombre : </label><br/> <input width="50" ...

What steps are involved in extracting a Flot animation?

Check out this cool animation of a diatomic chain in action on this website: http://lampx.tugraz.at/~hadley/ss1/phonons/1d/1d2m.php I'm interested in extracting it, specifically to create a gif. The HTML script for the animation is visible: var c= ...

`At a loss: jQuery failing to retrieve JSON data`

I'm having trouble with a basic script that is supposed to fetch data from a JSON feed and display it in an alert. Despite having loaded jQuery correctly and checked for common issues, the code doesn't seem to be working. I am using jQuery and ca ...

AngularJS script to dynamically update a table upon selecting an option from the dropdown menu

Just starting out with Angularjs and facing a challenge. I have a table with a "Update" button on the UI and a drop-down option in the 3rd column. The requirement is, upon selecting an option from the drop-down and clicking the "Update" button, the values ...

Why is the feedback section showing a horizontal scrollbar?

I'm puzzled as to why a horizontal scrollbar is appearing in the feedback section. I've examined the elements but can't seem to pinpoint the issue. ...

What is the best way to keep wp_nav_menu expanded while accessing submenu links?

Recently, I joined the Wordpress community and am currently in the process of converting a static HTML site to the WP platform. Almost everything is working smoothly except for the navigation menu. I am attempting to utilize the built-in navigation featur ...

Ensure that grid rows occupy the least amount of space possible

I'm relatively new to grid layout and I've encountered a challenge that has me stuck. Here's what I have so far: codepen And this is the relevant part of the grid: grid-template: 'img date' 'img head' 'img s ...

Creating a Scrollbar within a Bootstrap Dropdown: a Complete Guide

Is there a way to create a scrollbar within a bootstrap 4 dropdown selection? I am facing an issue where the dropdown does not fully load when there are too many files. My solution is to display only 5 files when the dropdown is clicked and include a scrol ...

Is it possible to create floating unordered lists using Bootstrap in HTML?

Is there a way to float text left or maintain list order in the HTML code of my page while using a dense CSS from this bootstrap template? For example, I would like my list to remain organized regardless of how many items are added: https://i.sstatic.net ...

Incorporating HTML 5 data attributes into the DOM using jQuery

I'm attempting to insert an HTML 5 data attribute into the DOM. According to the jQuery site, the format for data attributes is as follows: $('.pane-field-related-pages ul').data("role") === "listview"; However, it doesn't appear to b ...

The scaling feature in CSS does not function properly in Internet Explorer 8

I've tried multiple approaches to transform the IE Matrix, but I'm facing an issue with the transform scale CSS not functioning in IE8. Code: .fture_box ul li.fture_img img{ width: 451px; height: 284px; display: block; margin: 0 0px 0 11px; pad ...

The Google Rich Result Testing Tool encountered an issue: Parsing error detected - a '}' or object member name is missing

Visit my website: www.bharatpharmatech.com I have implemented my code using Next.js Here is the schema I am utilizing: { "@context": "https://schema.org/", "@type": "WebSite", "name": "Bharat Pharmate ...

Embellishing Your Website with Unique Cursor Styles

Looking to add personalized cursors to my website using asp.net 4.0. On my master page, I aim to set a custom cursor as the default for the entire site and have different custom cursors for all links. Is this achievable? ...