Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Pseudo-elements :before and :after vertical position

Pseudo-elements :before and :after vertical position

Problem

I'm trying to vertically position :before and :after pseudo-elements in a

.

Each is placed in a float:left orange column, next to a another float:left column which contains a .

I'd like to have at the top and the Bottom of the

, a thin border.

The issue is : if the text contained in the float column is longer than the

, the bottom-border of the

is placed at the bottom of the text column, not at the bottom at the

column.

Because of my "not-so-good-english", I made a fiddle : http://jsfiddle.net/vcH4T/

I'm really stuck with this :(

Thanks in advance for your help! Camille

Problem courtesy of: creamille

Solution

I'd like to have at the top and the bottom of the

, a thin border.

Like this:

JSFiddle

CSS /* generic h2 */

h2 {
    font-size:1.1em;
    line-height: 20px;
    background-color: #d8713c;
    border-radius: 4px;
    text-align: center;
    color: #fff;
    padding: 20px 10px;
    position:relative;
}

h2::before, h2::after {
    content:"";
    position: absolute;
    left:50%;
    width: 10%; /* anything you like */
    margin-left:-5%; /* 50% of width */
    height: 0px;
    border-bottom: 3px solid #efbe94;
}

h2::before {
      top: 7%;  
}

h2::after {
    bottom: 7%;

}
Solution courtesy of: Paulie_D

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Pseudo-elements :before and :after vertical position

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×