Two divs (left, right) in parent, right with fixed width, left fill free space, both in same line. (without position relative/absolute)
You could do it like this:
JSFiddle - DEMO
CSS:
.container {
width: 500px;
background-color: bisque;
height: 50px;
display: table;
}
.container .left {
background-color: burlywood;
height: 50px;
display: table-cell;
width: 100%;
}
.container .right {
background-color: chartreuse;
width: 50px;
height: 50px;
display: inline-block;
vertical-align: text-top;
}
Two divs, one fixed width, the other, the rest
See: http://jsfiddle.net/SpSjL/ (adjust the browser's width)
HTML:
<div class="right"></div>
<div class="left"></div>
CSS:
.left {
overflow: hidden;
min-height: 50px;
border: 2px dashed #f0f;
}
.right {
float: right;
width: 250px;
min-height: 50px;
margin-left: 10px;
border: 2px dashed #00f;
}
You can also do it with display: table
, which is usually a better approach: How can I put an input element on the same line as its label?
How to make divs side-by-side with one fixed width and one the rest of the screen
This is achievable using CSS alone with the calc function, see this fiddle for example: https://jsfiddle.net/jks421gy/1/
width: calc(100% - 200px);
You need to float the divs, then give the first one the fixed width, then the right one will be 100% of the space minus 200px.
How to make a div fill a remaining horizontal space?
This seems to accomplish what you're going for.
#left { float:left; width:180px; background-color:#ff0000;}#right { width: 100%; background-color:#00FF00;}
<div> <div id="left"> left </div> <div id="right"> right </div></div>
make left div to fill all available space, when right div has fixed width
Try this:
HTML
<div id="left">
Menu
</div>
<div style="text-align: center;">
<div id="right">
Content
</div>
</div>
CSS
#left {
background-color: green; /*for demonstration purposes*/
float:left;
}
#right{
background-color: blue;
width: 800px;
}
JS
$(document).ready(function(){
var width = $(document).width();
var rightDivWidth = $("#right").width();
var leftDivWidth = width - rightDivWidth;
$("#left").css("width", leftDivWidth);
});
Demonstration
Two divs side by side: first fixed-width, second stretch-to-fit
I think that should do it :
#d1 {
display: table;
width: 100%;
}
#d2, #d3 {
display: table-cell;
padding: 2px 6px;
}
#d2 {
white-space: nowrap;
}
#d3 {
width: 100%;
}
You can try it here
Fixed width div on right, fill remaining width div on left
You can do it like this:
HTML:
<div class="right">right</div>
<div class="left">left</div>
CSS:
.left{
background:red;
}
.right{
float:right;
width:200px;
background:green
}
Check this live example http://jsfiddle.net/QHTeS/2/
Fixed width div on left, fill remaining width div on right
Try removing the float:left
and width:100%
from .header-right
— the right div
then behaves as requested.
.header { float: left; background: #efefef; background-repeat: no-repeat; width: 240px; height: 100px;}
.header-right { overflow: hidden; background-color: #000; height: 100px;}
<div class="header"></div><div class="header-right"></div>
Related Topics
Vertically Center Constrained Image in Bootstrap Thumbnail
CSS Filter Invert Rule Breaking Fixed Position on Chrome 68
Split Page Vertically Using CSS
Compass-Style (Ruby) Encoding Error
CSS for Double Height Text and Double Width Text in Font Style
Styling Input Range for Webkit with Pure CSS
How to Set Height of Element to Match Height of Another Element
Page-Break-Before:Auto Not Working for Me....Why
How to Change The Background Colour's Opacity in CSS
CSS - Making a Div Consume All Available Space
Editing CSS in Gwt Windowbuilder
How to Center Text Inputs Using Materialize CSS
Styling Part of The Text in The Placeholder
Divs Appearing Different on Different Browsers
How to Apply Different CSS Styles to 2 Elements with The Same Class Name
What Is Meant by "Participate" in The Definition of "Normal Flow" in The CSS 2.1 Spec
What Does The * CSS Operator Do? Are There Any Other CSS Operators
Position Relative in Firefox Causing Problems with Google-Map-Markers Clickable Area