0

So I have these titles that have horizontal lines to the left and right of them using CSS :before and :after.

lines example

The code looks like this:

.infoBlockA h1 {
  line-height: normal;
  color: #F6F6F6;
  text-transform: uppercase;
  letter-spacing: .5px;
  text-decoration: none;
  font-size: 200%;
  text-align: center;
  position: relative;
  text-shadow: 1px 1px 0px #2c2e38, 2px 2px 0px #5c5f72;
}

.infoBlockA h1:before {
  content: "";
  margin: 15px 0px 0px 0px;
  left: 0;
  height: 2px;
  position: absolute;
  background: #DE1B1B;
}

.infoBlockA h1:after {
  content: "";
  right: 0;
  margin: 15px 0px 0px 0px;
  height: 2px;
  position: relative;
  background: #F6F6F6;
}

And then I normally set my width:

.infoBlockA h1:before,
.infoBlockA h1:after {
  width:27%;
}

But since I have so many titles, I don't want have to set widths for every single title. How can I make the title squish the horizontal lines so that the lines are always a certain distance away from the text, but always fill the container they are in?

EDIT: To clarify, the titles are dynamic and are different lengths of text!

Fearium
  • 120
  • 10
  • change your margins to use percentages and make sure that the H1s are in a container that has "absolute" dimensions (px, not %)... – MaxOvrdrv Dec 22 '15 at 19:43
  • being that my site uses a lot of relative positioning, changing the parent container to absolute, absolutely destroys the layout. – Fearium Dec 22 '15 at 19:47
  • ok... well try to change the margins to percent... it may still work. Depends on how the browser reads and converts the params. – MaxOvrdrv Dec 22 '15 at 19:48
  • Thanks @Paulie_D for finding that post for me! Works like a charm. – Fearium Dec 22 '15 at 19:52
  • 1
    And thank you for your suggestions @MaxOvrdrv – Fearium Dec 22 '15 at 19:53

0 Answers0