0

I have 3 inline block elements;

The middle one is centered. I would like to stretch the others to take the remaining width container.

This is what I tried so far:

.container {
  width: 400px;
  height: 100px;
  text-align: center;
  background-color: yellow;
}

.line {
  border: dashed 1px #C7C9C7;
  display: inline-block;
  width: 38%;
}

.content {
  display: inline-block;
  background-color: red;
}
<div class="container">
  <hr class="line" />
  <div class="content">This is a text</div>
  <hr class="line" />
</div>

How can I have the same result even if middle width will change?

j08691
  • 204,283
  • 31
  • 260
  • 272
V. Sambor
  • 12,361
  • 6
  • 46
  • 65
  • This is just an example or you really just want to place a dotted line at the sides of the text ? – DaniP Mar 22 '17 at 15:43
  • is really a dotted line, and would be better to have it aligned aligned also vertically. Kind of
    with text in the middle is what I'm looking for. Thanks
    – V. Sambor Mar 22 '17 at 15:44
  • why don't you just use `:pseudo` elements `:before` and `:after` to make the border instead? – Lucian Mar 22 '17 at 15:47
  • can you post an answer with your proposal please? – V. Sambor Mar 22 '17 at 15:56

1 Answers1

1

You can use display: flex; on the .container to get the wanted output : See this fiddle

    .container{
        width: 400px;
        height: 100px;
        text-align: center;
        background-color: yellow;
        display: flex;
        -ms-flex-align: center;
        -webkit-align-items: center;
        -webkit-box-align: center;

        align-items: center;
    }

If you change the text in the middle, it will keep it centered and stretch the two others to take the remaining width of the container.

Vincent G
  • 8,547
  • 1
  • 18
  • 36