Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seperate sidebar and content?

Tags:

html

css

web

I'm trying to make a side bar and a content div but I don't know how to keep them separated and the content goes under the sidebar and obviously I don't want that. I'm pretty new to coding so I don't know what to do or if there's a better way to do this.

picture Here's the code:

<div id="content" style="margin:50px; background-color:blue; padding:10px;">
   <div id="sidebar" style="margin:25px; background-color:red; width:200px; border: 2px solid lime; position:fixed;">
      <p>h</p>
   </div>
   <div id="stuff" style="background-color:orange; margin:20px;">
      <p>Lorem ipsum blah blah</p>
   </div>
</div>
like image 902
cayden Avatar asked Jan 30 '26 08:01

cayden


1 Answers

You can use display: flex at top level. It's easier to use than position: fixed or any other positioning strategies.

#content {
  margin: 20px 0;
  padding: 10px;
  background: blue;
  display: flex;
}

#content #sidebar {
  background: red;
  width: 150px;
  border: 2px solid lime;
  padding: 10px;
}

#content #stuff {
  background-color: orange;
  flex: 1;
  margin-left: 10px;
  padding: 10px;
}
<div id="content">
  <div id="sidebar" style="">
    <p>h</p>
  </div>
  <div id="stuff" style="">
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
    <p>Lorem ipsum blah blah</p>
  </div>
</div>
like image 99
Dinesh Pandiyan Avatar answered Feb 01 '26 00:02

Dinesh Pandiyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!