Stable width on the right and flexible content

I attempted to align two divs next to each other. The challenge was that the right div needed to have a fixed width, while the left div had to be resizable. I experimented with different approaches, but none met all my criteria:

  1. Right div has fixed width
  2. Parent div adjusts its height based on the largest child (wraps its children)
  3. Left div must be resizable
  4. The HTML structure must follow this specific order (explained at the end):

HTML:

<div class="container">
    <div class="variable_width"></div>
    <div class="fixed_width"></div>
</div>

I tried absolute positioning for the right div and applied a margin to the left one, which successfully met all requirements, except that the parent div didn't wrap around the largest child as anticipated http://jsfiddle.net/0fxL71xL/3/

.container{max-width:400px;position:relative;}
.variable_width{margin-right:100px;}
.fixed_width{width:100px; position:absolute;right:0;top:0;}

I also experimented with using inline-block and max-width, but then the divs did not align at the top, and I struggled with handling whitespace. Most importantly, the left div didn't resize: http://jsfiddle.net/0fxL71xL/4/

.container{max-width:400px;}
.variable_width{max-width:290px; display:inline-block;}
.fixed_width{width:100px; display:inline-block;}

I also tested with a float right on the right div, but it fell short of my expectations. The closest solution involved rearranging the HTML order and applying float:right to the div intended for the right side. However, this approach prevented me from using an @media query to reposition it below the left div when necessary.

EDIT: While paulie_d's suggestion resolves the issue, I would prefer a method with wider browser support.

Answer ā„–1

Using flexbox is the solution

Check out this JSFiddle Demo

.box {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}
.fixed_size {
  width: 150px;
  background-color: #abcdef;
}
.variable_size {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
  background-color: #fedcba;
  height: 80px;
}
<div class="box">
  <div class="variable_size"></div>
  <div class="fixed_size"></div>
</div>

Answer ā„–2

.container {
width:100%;
}

.variable_width {
    max-width: 70%;
    display: inline-block;
    background-color:blue;
margin-right: -3px;
}
.fixed_width {
width:100px;
width: 28%;
display: inline-block;
    background-color:red;
vertical-align: top;
}

Feel free to utilize the code provided above. Adding content to the variable width div class should work without any issues. I have tested it myself and it works perfectly! Check it out here!

Answer ā„–3

After conducting further research, I stumbled upon an intriguing page that outlines several techniques to accomplish exactly what I was looking for. This resource provides the most comprehensive solution.

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

"Showcasing a pair of icons side by side in an HTML layout

I need assistance with formatting two legends on the form. I want both legends to be displayed side by side instead of one on top of the other. Here's how I want it: -----legendOne---LegendTwo----- What CSS code do I use to achieve this layout? Be ...

Guide to showcasing an image on an HTML page using HTTP header

I have an HTML page with a basic layout that includes a single button. When this button is clicked, it needs to trigger an HTTP request to a specific URL while including an Accept header for GET requests. The response from the HTTP URL will vary depending ...

Error in generating MySQL database tables due to syntax issues

CREATE TABLE products ( 'productid' int(10) NOT NULL AUTO_INCREMENT, 'productname' varchar(255), 'type' varchar(255), 'size' varchar(255), 'category' varchar(255), 'color1' varchar(255), 'col ...

The image in the HTML is currently positioned at the bottom, but I would like it to be

this is what it looks like: https://i.sstatic.net/VLqN7.png I need it to be at the top next to the first card. <!-- top nav--> <nav class="navbar navbar-expand-lg navbar-light" style="background-color:white"> <a class="navbar-brand" ...

JavaScript and AJAX: Dynamically Create URLs

I don't have any experience with web development, so could you please explain in detail? If my questions are unclear, feel free to ask for more information. Imagine I have a webpage with the following URL: www.mycompany.com/category1 This page has ...

What is the best way to apply fading effects to three divs containing additional divs?

Looking at this HTML and CSS code: HTML <DIV class="newsPic"></DIV> <DIV class="newsPicTwo"></DIV> <DIV class="newsPicThree"></DIV> CSS .newsPic { width: 500px; height: 200px; } .newsPicTwo { width: 500px; height: 2 ...

What is the best way to add a sliding effect to this presentation?

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow I am attempting to create a sliding effect for image transitions instead of the typical fade in and out. However, I'm uncertain about how to approach this challenge. My concept i ...

Is there a way to change the input type=file value?

What is the best method for customizing a file upload using input type="file" in HTML? Here is an example of what I am trying to achieve: <form enctype="multipart/form-data" action="xmlupload" method="post" name="form1" id="form1"> <input type ...

I'm looking to transform the input text in HTML into separate box-like structures every time a word is typed by the user and separated by a comma. (refer to

https://i.sstatic.net/ZWIu1.png Can you provide guidance on how to transform text data into separate boxes like the image when a user inputs words separated by commas? I am working on implementing this feature in an input field using Angular. ...

Transmit information to an HTML website displayed within a QT GUI utilizing QWebview

Currently, I am developing a desktop application using QT (c++) that integrates a website created with a basic html file (including javascript) through Qwebview. The website consists of a plugin and html boxes where the data entered triggers changes in the ...

Having trouble adjusting the width of a button inside a DIV in Internet Explorer

Iā€™m having difficulty reducing the button width within a div, especially on IE8 and newer versions. Any suggestions on how to fix this issue would be greatly appreciated. <html> <body> <table> <tr> ...

Display the JSON result from a RESTful API call within an Ionic framework

I am facing a challenge in displaying a JSON response retrieved from a RESTful API request. Below is the code snippet: products:Observable<any>; constructor(public navCtrl: NavController, private backgroundGeolocation: BackgroundGeolocation, public ...

How to dynamically toggle div visibility using ng-model in Angular

I've been experimenting with dynamically changing the visibility of a div using ng-show="models.show" Here's what I tried initially: Unfortunately, it doesn't seem to be working as expected. html <div ng-init="models.show=false" ...

In my Vue application, I've noticed that when I implement a select tag, the drop-down icon mysteriously vanishes in Chrome

I'm currently working on a Vue.js project with Vuetify. However, I've encountered an issue where the drop-down icon disappears when using a select tag. <template> <select class="select"> <option v-for="item ...

Disable the ability to resize OpenCV frame

I am currently working on creating a frame using OpenCV in Python, but I have encountered an issue where the frame is resizable with the mouse. This is not the desired behavior and my searches online have not yielded any useful solutions. Below is the cod ...

Invoking a C/C++ library from a web server

As someone who is relatively new to web programming, I am in the process of developing an HTML5-based user interface that needs to interact with a middle ware written in C/C++. I would prefer not to rely on any browser-specific features or libraries for th ...

Employing JQuery Cycle and automatic resizing background images

Is there a way to make jquery's cycle plugin resize images automatically as the user scales the window size? Currently, it cycles through images based on the initial screen size and does not adapt afterwards. Any suggestions? <?xml version="1.0" e ...

Guide to enhancing jQuery tooltip plugin with ajax support - integrating live functionality

I am currently using a jQuery plugin from However, I am facing an issue where the plugin does not work properly when using Ajax. I would like to modify or add a function live() to address this problem. Here is the complete code: http://pastebin.com/up6KY ...

Achieving dynamic height in a parent div with a sticky header using mui-datatables

Here are the settings I've configured for my mui-datatables: const options = { responsive: "standard", pagination: false, tableBodyHeight: '80vh', }; return ( <MUIDataTable title={"ACME Employee ...

Table is not updating correctly following jQuery adjustments on Google Chrome

After resolving one of my previous questions mentioned in this solution, I encountered display issues in Google Chrome following recent changes. The table header row was not refreshing correctly after JavaScript modifications, resulting in anomalies. An e ...