Scott Simpson
Scott Simpson

Reputation: 3850

Flex box issue on Safari — mobile and desktop

The horizontal rule on the right overlaps the text in Safari on desktop and mobile.
How can I prevent the overlap?

Safari on right

http://codepen.io/simply-simpy/pen/EyENLr

h2 {
  align-items: center;
  display: flex;
  font-size: 3.125vw;
  margin-top: 0;
  position: relative;
  width: 100%;
}

h2:after {
  border-top: 1px solid #000;
  content: "";
  display: block;
  margin-left: 1.875vw;
  width: 100%;
}

h2:before {
  border-top: 1px solid #000;
  content: "";
  display: block;
  margin-right: 1.875vw;
  width: 100%;
}

.container {
  align-items: center;
  align-content: center;
  text-align: center;
  display: flex;
  flex-direction: column;
}
<div class="container">
  <h2>precision</h2> 
</div>

Upvotes: 1

Views: 506

Answers (1)

Hunter Turner
Hunter Turner

Reputation: 6894

Using flex-grow: 1; instead of width: 100%; on your h2:before and h2:after will solve the issue.

h2 {
    align-items: center;
    display: flex;
    font-size: 3.125vw;
    margin-top: 0;
    position: relative;
    width: 100%;
}

h2:after {
    border-top: 1px solid #000;
    content: "";
    display: block;
    margin-left: 1.875vw;
    flex-grow: 1;         /* <--- Replace */
}

h2:before {
    border-top: 1px solid #000;
    content: "";
    display: block;
    margin-right: 1.875vw;
    flex-grow: 1;         /* <--- Replace */
}

.container {
  align-items: center;
  align-content: center;
  text-align: center;
  display: flex;
  flex-direction: column;
}
<div class="container">
  <h2>precision</h2> 
</div>

Upvotes: 1

Related Questions