-2

I want to place a square symbol between two hr tags to create a separator and i want the square to be in the middle of the lines. With this code the square is placed lower than the hr tags, not in the middle of them.

This is the html:

    <div class="separator">
        <hr width='150' align="left">
            <span style="color: #fff;">&#9632;</span>
        <hr width='150' align="right">
    </div>

And here is the css:

   separator {
         margin: 5% 0;
   }

   hr {
       border: none;
       height: 2px;
       background: #fff;
       display: inline-block;
   }

2 Answers2

1

Something like this should do the job by leveraging flexbox:

CSS

.divider {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
}

.divider hr {
  flex: 1 1 0;
}

.divider .square {
  width: 15px;
  height: 15px;
  background-color: black;
}

HTML

<div class="divider">
    <hr />
    <div class="square"></div>
    <hr />
</div>
treyhakanson
  • 4,611
  • 2
  • 16
  • 33
1

Use float in hr

Html code

<div class="separator">
            <hr width='150' align="left" style="float: left;">
                <span style="color: #fff;">&#9632;</span>
            <hr width='150' align="right">
        </div>
Ayush Sahu
  • 268
  • 3
  • 15