You are here:Home»KB»Web Design»Design Elements, Styling, Effects and Code»Styled Elements»Horizontal Type Line Behind Text
Thursday, 26 January 2017 19:55

Horizontal Type Line Behind Text

Written by

This is a cool little effect where you can put a line behine a title but the text remains unaltered.

EVENTS 2016

CSS

/**
 * Horizontal Type Line Behind Text
 * https://codepen.io/ericrasch/pen/Irlpm
 * Inspired by this discussion @ CSS-Tricks: http://css-tricks.com/forums/topic/css-trick-for-a-horizontal-type-line-behind-text/#post-151970
 * Available on jsFiddle: http://jsfiddle.net/ericrasch/jAXXA/
 * Available on Dabblet: http://dabblet.com/gist/2045198
 * Available on GitHub Gist: https://gist.github.com/2045198
 */

h1.background,
h2.background,
h3.background  {
  position: relative;
  z-index: 1;
}
h1.background:before,
h2.background:before,
h3.background:before {
  border-top: 2px solid #00AFB2;
  content: "";
  margin: 0 auto;
  /* this centers the line to the full width specified */
  position: absolute;
  /* positioning must be absolute here, and relative positioning must be applied to the parent */
  top: 50%;
  left: 0;
  right: 0;
  bottom: 0;
  width: 95%;
  z-index: -1;
}
h1.background span,
h2.background span,
h3.background span {
  /* to hide the lines from behind the text, you have to set the background color the same as the container */
  background: #fff;
  padding: 0 15px;
}

/* homepage CTA - how can we help */
.jsn-homepage h3.background:before {
  border-top: 2px solid #fff;
}
.jsn-homepage h3.background span {
  background: #00AFB2;
}

/* About page - Main content */
.jsn-itemid-344 h2.background.benefits span {
  background: #EFE9DE;
}

/* I dont think i need this */

h1.double:before,
h2.double:before {
  /* this is just to undo the :before styling from above */
  border-top: none;
}
h1.double:after,
h2.double:after {
  border-bottom: 1px solid blue;
  -webkit-box-shadow: 0 1px 0 0 red;
  -moz-box-shadow: 0 1px 0 0 red;
  box-shadow: 0 1px 0 0 red;
  content: "";
  margin: 0 auto;
  /* this centers the line to the full width specified */
  position: absolute;
  top: 45%;
  left: 0;
  right: 0;
  width: 95%;
  z-index: -1;
}
h1.no-background,
h2.no-background {
  position: relative;
  overflow: hidden;
}
h1.no-background span,
h2.no-background span {
  display: inline-block;
  vertical-align: baseline;
  zoom: 1;
  *display: inline;
  *vertical-align: auto;
  position: relative;
  padding: 0 20px;
}

h1.no-background span:before,
h1.no-background span:after,
h2.no-background span:before,
h2.no-background span:after {
  content: '';
  display: block;
  width: 1000px;
  position: absolute;
  top: 0.73em;
  border-top: 1px solid red;
}
h1.no-background span:before,
h2.no-background span:before {
  right: 100%;
}
h1.no-background span:after,
h2.no-background span:after {
  left: 100%;
}
h1.no-span,
h2.no-span {
  display: table;
  white-space: nowrap;
}
h1.no-span:before,
h1.no-span:after,
h2.no-span:before,
h2.no-span:after {
  border-top: 1px solid green;
  content: '';
  display: table-cell;
  position: relative;
  top: 0.5em;
  width: 45%;
}
h1.no-span:before,
h2.no-span:before {
  right: 1.5%;
}
h1.no-span:after, 
h2.no-span:after {
  left: 1.5%;
}

HTML

<h1 class="background" style="text-align: center;"><span>EVENTS 2016</span></h1>

 

 

Read 864 times Last modified on Thursday, 26 January 2017 20:03