Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center an image inserted with after: pseudo-element; can't use spans

I'm pulling in a tumblr feed using tumblr's code, and using after: to add an image as a separator between posts. I'd like to center the image, but haven't had luck doing so. Since tumblr's generating the content, not me, I don't think I can use span tags, which seems to be the usual answer. Any other ideas?

Page showing feed in use: lumn.net/index.shtml

CSS:

.tumblr_post:after {
    content: url(../img/flower.png);
    display: block;
    position: relative;
    margin-top: 42px;
    margin-bottom: 24px;
    margin-left: auto;
    margin-right: auto;
}
like image 502
poetiscariot Avatar asked May 28 '12 01:05

poetiscariot


Video Answer


2 Answers

Try this:

.tumblr_post:after {
    content: url("../img/flower.png");
    display: block;
    margin: 42px auto 24px;
    position: relative;
    text-align: center;
    width: 100%;
}
like image 63
Zoltan Toth Avatar answered Sep 21 '22 09:09

Zoltan Toth


While the answer from Zoltan Toth works, it's got a bunch of code that does nothing for the desired effect. This should do the trick and with less code.

.tumblr_post:after {
    content: url("../img/flower.png");
    display: block;
    text-align: center;
}
like image 24
Cole Geissinger Avatar answered Sep 19 '22 09:09

Cole Geissinger