-1

I want to show two divisions side by side. I have tried a few possible solutions, but they still overlap. Thank you in advance.

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
    .sidebar
    {
        width:200px;
        background:yellow;
        color:orange;
        padding:50px;
    }
    .content
    {
        width:600px;
        background:silver;
        color:red;
        padding:50px;
    }
</style>
</head>
<body>
       <div class="sidebar">
        This is sidebar div
    </div>
    <div class="content">
        This is Content div
    </div>
</body>
</html>
Bradley Marques
  • 502
  • 3
  • 22

10 Answers10

2

Use float:left; Learn about CSS float Property

.sidebar
    {
        width:150px;
        background:yellow;
        color:orange;
        padding:50px;
  float:left;
    }
    .content
    {
        width:200px;
        background:silver;
        color:red;
        padding:50px;
  float:left;
    }
<div class="sidebar">
 This is sidebar div
</div>
<div class="content">
 This is Content div
</div>
Manjeet Barnala
  • 2,975
  • 1
  • 10
  • 20
2

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
    .sidebar
    {
        width:200px;
        background:yellow;
        color:orange;
        float:left;
        padding:50px;
    }
    .content
    {
        width:200px;
        background:silver;
        color:red;
        float:left;
        padding:50px;
    }
</style>
</head>
<body>
       <div class="sidebar">
        This is sidebar div
    </div>
    <div class="content">
        This is Content div
    </div>
</body>
</html>
Govind jha
  • 400
  • 3
  • 16
0

I think do you mean just display two div in one row is it right so it is just simple add float:left in first div it will solve your issue.

Like :

    .sidebar {
        width: 200px;
        background: yellow;
        color: orange;
        padding: 50px;
        float:left;
    }
Pragnesh Khalas
  • 2,908
  • 2
  • 13
  • 26
0
<!DOCTYPE html>
<html>
<head>
   <title></title>
<style type="text/css">
    .sidebar
    {
        width:200px;
        background:yellow;
        color:orange;
        padding:50px;
        float:left;
    }
    .content
    {
        width:600px;
        background:silver;
        color:red;
        padding:50px;
        float:left;
        margin-left:10px;
    }
</style>
</head>
<body>
    <div class="sidebar">
        This is sidebar div
    </div>
    <div class="content">
        This is Content div
    </div>
</body>
</html>
Dharmesh Rakholia
  • 1,210
  • 9
  • 22
0

Just added main parent to both div and used display:inline-flex to it.

.main{
  display:inline-flex;
}   
.sidebar
    {
        width:200px;
        background:yellow;
        color:orange;
        padding:50px;
    }
    .content
    {
        width:600px;
        background:silver;
        color:red;
        padding:50px;
    }
<div class="main">
<div class="sidebar">
        This is sidebar div
    </div>
    <div class="content">
        This is Content div
    </div>
</div>
Sagar Kodte
  • 3,723
  • 4
  • 23
  • 52
0

adding float:left to both div will fix the issue.

css code:

 .sidebar
    {
        width:200px;
        background:yellow;
        color:orange;
        padding:50px;
        float:left;
    }
    .content
    {
        width:600px;
        background:silver;
        color:red;
        padding:50px;
        float:left;
    }

html code:

 <div>
         <div class="sidebar">
           This is sidebar div
         </div>
         <div class="content">
           This is Content div
         </div>
    </div>

and if one of your div is going down then you must adjust your div's width.

Dinnu Buddy
  • 369
  • 1
  • 3
  • 13
0

Apply a float:left to the widgets

Pons Purushothaman
  • 2,225
  • 1
  • 14
  • 23
0

To solve this problem :

You should add this code to .content and to .sidebar

Add float:left...

This should help

http://www.w3schools.com/cssref/pr_class_float.asp..

glad to help you

0

Since div is a block level element, so it will occupy 100% width of its immediate parent. Because of it, one cannot place them in a horizontal manner without making use of float - a very useful CSS property.

So in your CSS you should add the property as below, to get the desired result:

.sidebar {
     float: left;
}

Watch the demo here.

To get more information about float, one can always Google, as it is an ocean of knowledge.

Shashank
  • 2,010
  • 2
  • 18
  • 38
0

use CSS float Property

float: none|left|right|initial|inherit;

 .sidebar {
   width: 200px;
   background: yellow;
   color: orange;
   padding: 50px;
   float: left;
 }
 .content {
   width: 200px;
   background: silver;
   color: red;
   padding: 50px;
   float: left;
 }
<div class="sidebar">
  This is sidebar div
</div>
<div class="content">
  This is Content div
</div>
Mahendra Kulkarni
  • 1,437
  • 2
  • 26
  • 35