I have the following css-code:
.readMore:before {
content: \'\';
display: block;
float: left;
width: 10px;
height: 27px;
margin: 0;
I tend to use absolute
positioning for :before and :after elements. Then you can do whatever you want to the parent without worrying about your pseudoelements going anywhere (unless, of course, you move the element itself).
View on JSFiddle
<div></div>
div {
position: relative;
background: #eee;
width: 25px;
height: 25px;
margin: 30px 0 0 30px;
}
div:before {
position: absolute;
width: 10px;
height: 25px;
top: 0;
left: -10px;
content:"";
background: #222;
}
div:after {
position: absolute;
width: 10px;
height: 25px;
top: 0;
right: -10px;
content:"";
background: #222;
}
This shows how I would lay them out. You can then use any method you want to adjust the position of the text in the parent.
The key points of the above code are the following:
If you want to center the text in the parent div
vertically, and it's just a single line, you can set the line-height equal to the height of the container. View that here. This would be better than 'guessing' the padding to make it vertically centered, if that's what you're going for.
Of course, there are other ways to center the text vertically, too, and accordingly there are lots of SO questions on the subject. Here's just one.
I just styled the height based on rem
values, e.g. height: 2 rem
. Can't confirm that's the best solution, but for responsiveness worked out quite perfectly in 1 line of code.