简体   繁体   中英

H1:before trouble involving image

I am trying to make a css headline that looks like this 参考

I have the triangle as a png with transparency, but I haven't really used pseudo elements before, so if anyone could help that would be awesome.

So far I've got this:

h1 {text-transform: uppercase;font-weight: 600; margin: 0; padding: 0;}
h1:before {
content: url( "../images/triangle.png" ) ;
margin-right: -50px;}

This places the text correctly horizontally, but I can't find a way to place the text correctly vertically

You can use below css and manage this via position:

h1 {
    text-transform: uppercase;
    font-weight: 600;
    margin: 0;
    padding: 0;
    position: relative
}
h1:before {
    content: "";
    position:absolute;
    width: 40px;
    height: 40px;
    background: url( "../images/triangle.png" );
    right: -50px;
    top: 0px;
}

Please check the fiddle - http://jsfiddle.net/afelixj/obmwncd4/

To add background image, remove all the border in h1:before , and add width and height of the image

so you want to make the text vertical ? try this

.vertical-text {
    transform: rotate(90deg);
    transform-origin: left top 0;
    float: left;
}

you can try like this: Demo

h1 {
    text-transform: uppercase;
    font-weight: 600;
    margin: 0;
    padding: 0;
    position:relative;
    z-index:9999;
    line-height:80px;
    text-indent:20px;
}
h1:before {
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    border-top: 100px solid red;
    border-right: 100px solid transparent;
    content:"";
    display:block;
    position:absolute;
    z-index: -1;
    /* to be below the parent element */
}

HTML:

<h1>fddfgfdg</h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM