0

I'm trying to create a top bar for my webpage thats seperated into two sections. However, I'm having difficulty getting my divs positioned. It would appear the wrap collapses with these styles set. Howe can I avoid this.

I have somthing like this,

<div id="wrap"> <div id="one"></div> <div id="two"></div> </div> 

Css is as follows;

#wrap { position: fixed; top:0; width: 100%; background-color:#ff0; } #one { position: relative; left:0; width: 40%; background-color: #f00; } #two { position: relative; right:0; width: 40%; background-color: #00f; } 

I want it to display on page something like this...


|One | (wrap underneath) | Two|

Any help would be much appreciated.

2
  • The wrap "collapses" because none of the element has any height. Commented Apr 3, 2016 at 20:34
  • You would think adding content would define height, but that fails also... Commented Apr 3, 2016 at 20:36

2 Answers 2

1

you can use flexbox

#wrap { position: fixed; top:0; height:50px; width: 100%; background-color:#ff0; display:flex; justify-content: space-between; } #one { height:50px; width: 40%; background-color: #f00; } #two { height:50px; width: 40%; background-color: #00f; }
<div id="wrap"> <div id="one"></div> <div id="two"></div> </div>

Sign up to request clarification or add additional context in comments.

Comments

1

Flexbox can do that.

#wrap { position: fixed; top: 0; width: 100%; display: flex; flex-wrap: wrap; justify-content: space-between; background-color: #ff0; } #one { height: 50px; width: 40%; background-color: #f00; } #two { height: 50px; width: 40%; background-color: #00f; }
<div id="wrap"> <div id="one"></div> <div id="two"></div> </div>

JSFiddle Demo

1 Comment

Flexbox? Never heard of it. Is it widley supported?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.