3

I'm trying to display a header with a hr and a button at the same line. Something like this:

Header ------------------------------------ Button

See image I've tried with display flex, but the hr changed for a vertical line.

.flex-header {
  display: flex;
}
<div class="flex-header">
<h2> Des habitations pour tous </h2>
<hr/>
<button> Collections </button>
</div>
analuspi
  • 184
  • 1
  • 1
  • 10

3 Answers3

3

You could just use a <div> with some to create a <hr>-like line;

.flex-header {
  display: flex;
}

.line {
  display: flex;
  flex-grow: 1;
  height: 1px;
  align-self: center;
  margin: 0 20px;
  background-color: grey;
}
<div class="flex-header">
<h2> Des habitations pour tous </h2>
<div class="line"></div>
<button> Collections </button>
</div>
0stone0
  • 34,288
  • 4
  • 39
  • 64
0

you need change te display property of h2 element, by default it is "block", change to "in-line" (so the button is show in side of header)

h2{
  diplay: inline;
}

To horizontal line, remove the display flex and change hr property:

h2{
  hr{ 
  display: inline-block;
  width: 50%;
}
}

Look project: https://codepen.io/Luis4raujo/pen/mdOXdyB

if this help you check as correct or voteup!

0

Make it behave like a table is one way (but needs a few wrapping divs):

<div class="w">
  <span class="a">Des habitations pour tous</span>
  <div class="b"><hr></div>
  <button class="c">COLLECTIONS</button>
</div>
.w {
  display: table;
}
.a, .b, .c {
  display: table-cell;
  white-space: nowrap;
}
.b {
  width: 100%;
}