Pregunta

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

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

I'd like to have at the top and the bottom of the <h2>, a thin border.

The issue is : if the text contained in the <p> float column is longer than the <h2>, the bottom-border of the <h2> is placed at the bottom of the text column, not at the bottom at the <h2> 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

¿Fue útil?

Solución

I'd like to have at the top and the bottom of the <h2>, 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%;

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top