Fixed width CSS sidebar with fluid content
I am trying to add a fixed width sidebar. But the content of the div must be fluid.
Here is my code:
.page-main{
padding: 10px;
height: auto;
overflow: hidden;
}
.page-content{
background-color: red;
width: auto;
overflow: hidden;
}
.page-side {
float: right;
width: 200px;
background-color: green;
}
<div class="page-main">
<div class="page-content">
Content
</div>
<div class="page-side">
Sidebar
</div>
</div>
I hope someone can help.
source to share
Just move .page-side
before .page-content
to your html
.page-main{
padding: 10px;
height: auto;
overflow: hidden;
}
.page-content{
background-color: red;
width: auto;
overflow: hidden;
}
.page-side {
float: right;
width: 200px;
background-color: green;
}
<div class="page-main">
<div class="page-side">
Sidebar
</div>
<div class="page-content">
Content
</div>
</div>
source to share
1. You can use css expression
.page-content {width: calc(100% - 200px);float:left}
2.or you can set the sidebar to absolute and add margin-right to the page content
.page-side {
width: 200px;
background-color: green;
position: absolute;
right: 20px;
top: 18px;
}
.page-content {
background-color: red;
width: auto;
overflow: hidden;
margin-right: 200px;
}
source to share
Not sure if you want to increase the sidebar width to 200px, you can also assign the width as a percentage ... hope this helps
<div class="page-main">
<div class="page-content">
Content
</div>
<div class="page-side">
Sidebar
</div>
</div>
.page-main{
padding: 10px;
height: auto;
overflow: hidden;
}
.page-content{
background-color: red;
width: auto;
overflow: hidden;
float:left;
width: 61%;
}
.page-side {
float: right;
width: 200px;
background-color: green;
}
OR check this: https://jsfiddle.net/pjx6wqrw/3/
{edited to remove jsfiddle link from code block}
source to share
You can use negative stock.
HTML:
<div class="wrapper">
<div class="content">
</div><!-- .content -->
<div class="sidebar">
</div><!-- .sidebar -->
</div><!-- .wrapper -->
CSS
.wrapper{
margin-right: 300px;
}
.content{
width: 100%;
float: left;
}
.sidebar{
float: right;
width: 300px;
margin-right: 300px;
}
full description and example for 2-3 columns:
https://shellcreeper.com/responsive-fixed-width-sidebar-why-and-how/
source to share