-3

I have the following HTML:

<div>
    <button>b1</button> 
    <button>b1</button> 
    <button>b1</button> 
    <span>Heading</span>
    <span>Status</span>
</div>

When the div is this wide I would like this to be displayed like this:

|-------------------------------------------|
| b1 b2 b3         Heading           Status |
|-------------------------------------------|

When the div is this wide I would like things to be displayed like this:

|----------------------------------------------------------------------------------|
| b1 b2 b3                        Heading                                   Status |
|----------------------------------------------------------------------------------|

When the div is too narrow to accommodate everything, something reasonable should happen.

|--------------------------|
|          Heading         | 
| b1 b2 b3          Status | 
|--------------------------|

Summary of requirements:

  • 3 buttons are aligned to the left
  • Heading is centered
  • Status is aligned to the left
  • When the div is too narrow to accommodate all three things, the heading should appear on a separate line before the other things (other reasonable behaviour would also be fine).

What is the best way to implement this kind of layout?

8
  • 4
    And what have you tried that failed?
    – ggdx
    Commented Sep 29, 2014 at 22:30
  • 4
    What is the best way to implement this kind of layout? The kind where you are using CSS and more than likely, media queries. Long story short: We wont help you unless you attempt to do it on your own, first.
    – Oberst
    Commented Sep 29, 2014 at 22:38
  • 4
    You should spend the time making your pretty little box layouts actually trying out some CSS
    – Macsupport
    Commented Sep 29, 2014 at 22:49
  • 4
    "Bonus part"? This isn't code golf and it certainly isn't a free "write code for me please" service. Ask an actual question - don't make code requests.
    – mechalynx
    Commented Sep 29, 2014 at 22:55
  • 3
    Did you just edit in parts of the below answers to make it look like you had attempted to solve the problem on your own?
    – apaul
    Commented Sep 29, 2014 at 23:17

3 Answers 3

0

Im not sure if this is what you wanted, but I made a jsfiddle with several changes to the html http://jsfiddle.net/dj0p1tqx/

All I had to do is put the them inside containers, with equal width:33.333%

0

The css code

<style type="text/css">
div {
    margin: 0 auto;
    position: relative;
    display: block;
    width: 100%;
    text-align: center;
}

button {
    float: left;
}

.position-right {
    float: right;
}   
</style>

And the html:

<div>
    <button class="position-left">b1</button> 
    <button class="position-left">b1</button> 
    <button class="position-left">b1</button> 
    <span class="position-left">Heading</span>
    <span class="position-right">Status</span>
</div>
0

You can do that: http://jsfiddle.net/csdtesting/74ShU/40/

.mainDIV {
  position: relative;
  width: 100%;
  min-width: 315px;
}
.leftDIV {
  position: absolute;
  top: 0px;
  left: 0px;
  height: 50px;
  width: 130px;
}
.middleDIV {
  height: 50px;
  width: 100px;
  margin: 0px auto;
}
.rightDIV {
  position: absolute;
  top: 0px;
  right: 0px;
  height: 50px;
  width: 100px;
}
<div class="mainDIV">
  <div class="leftDIV">
    <button>b1</button>
    <button>b1</button>
    <button>b1</button>
  </div>
  <div class="middleDIV"> <span>Heading</span>
  </div>
  <div class="rightDIV"> <span>Status</span>
  </div>
</div>

Not the answer you're looking for? Browse other questions tagged or ask your own question.