Reputation: 1642
I need two columns, one responsive, another fixed with 100px width
For example left columns have 100px width
and right columns have the remaining width
In this simple code how much to put the width?
<!DOCTYPE html>
<html>
<head>
<style>
.main{
display: table;
clear: both;
width: 100%;
}
#left{
float: left;
width: 100px;
}
#right{
float: right;
/*width: ;*/
background-color: red;
}
</style>
</head>
<body>
<div class="main">
<div id="left">
left
</div>
<div id="right">
right
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 86
Reputation: 32255
You can use calc()
to calculate the remaining width. Check the browser compatibility table: Can I use calc().
html,
body {
margin: 0;
padding: 0;
}
.main {
width: 100%;
}
#left {
float: left;
width: 100px;
background: lightblue;
}
#right {
float: left;
background-color: tomato;
width: calc(100% - 100px);
}
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<div class="main">
<div id="left">
left
</div>
<div id="right">
right
</div>
</div>
</body>
</html>
Upvotes: 1
Reputation: 2753
Try this:
#left {
position: absolute;
left: 0;
width: 100px;
}
#right {
position: absolute;
left: 100px;
width: 100%;
}
Upvotes: 1
Reputation: 5982
Since you're already using display: table
on the parent, set the children's display to table-cell
and give a width to the first one like you did. The second column will automatically take the remaining width.
#left{
display: table-cell;
width: 100px;
}
#right{
display: table-cell;
}
Example : https://jsbin.com/dicuvigaka/edit?html,output
Upvotes: 2