How to place two divs next to each other?
Float one or both inner divs.
Floating one div:
#wrapper {
width: 500px;
border: 1px solid black;
overflow: hidden; /* will contain if #first is longer than #second */
}
#first {
width: 300px;
float:left; /* add this */
border: 1px solid red;
}
#second {
border: 1px solid green;
overflow: hidden; /* if you don't want #second to wrap below #first */
}
or if you float both, you'll need to encourage the wrapper div
to contain both the floated children, or it will think it's empty and not put the border around them
Floating both divs:
#wrapper {
width: 500px;
border: 1px solid black;
overflow: hidden; /* add this to contain floated children */
}
#first {
width: 300px;
float:left; /* add this */
border: 1px solid red;
}
#second {
border: 1px solid green;
float: left; /* add this */
}
CSS two divs next to each other
You can use flexbox to lay out your items:
#parent { display: flex;}#narrow { width: 200px; background: lightblue; /* Just so it's visible */}#wide { flex: 1; /* Grow to rest of container */ background: lightgreen; /* Just so it's visible */}
<div id="parent"> <div id="wide">Wide (rest of width)</div> <div id="narrow">Narrow (200px)</div></div>
How to place two divs next to each other?
Your border overflows here.
Try setting box-sizing: border-box
to both divs:
#video{
width: 50%;
height: 100%;
border-style: solid;
float: left;
box-sizing: border-box;
}
#chat{
width: 50%;
height: 100%;
border-style: solid;
float: left;
box-sizing: border-box;
}
How to keep two div next to each other?
There are two issues here:
You need to set a
box-sizing
so that the width of the element includes the borderYou need to remove the newline between the divs since it takes an extra space
div{
border: 1px solid;
display: inline-block;
box-sizing: border-box;
width: 50%;
}
<form>
<div>
two
</div><!-- you need to remove space here --><div>
one
</div>
</form>
Display two divs next to each other where each has a width of 50%
Because of two things
- Border size so you need to change
box-sizing
toborder-box
- White space on
inline-block
elements
* { box-sizing: border-box;}#wrapper { border: 1px solid blue;}#div1 { display: inline-block; width: 50%; height: 120px; border: 1px solid red;}#div2 { display: inline-block; width: 50%; height: 160px; border: 1px solid green;}
<div id="wrapper"> <div id="div1">The two divs are</div><div id="div2">next to each other.</div></div>
Related Topics
How to Align Checkboxes and Their Labels Consistently Cross-Browsers
Are There Any Style Options For the Html5 Date Picker
Absolutely Positioned Flex Item Is Not Removed from the Normal Flow in Ie11
What's the Proper Value For a Checked Attribute of an HTML Checkbox
Display: Inline-Block Extra Margin
Open Link in New Tab or Window
Is There an Equivalent to Background-Size: Cover and Contain For Image Elements
Flex Container Min-Height Ignored in Ie
Flexbox Fill Available Space Vertically
How to Link to Part of a Page - Hash
What to Use in Place of ::Ng-Deep
How to Use the "Required" Attribute With a "Radio" Input Field
How to Expand Floated Child Div'S Height to Parent'S Height
Maintain Aspect Ratio of Div But Fill Screen Width and Height in Css