Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS content before block with padding

Tags:

html

css

less

Is it possible/how do I:

Remove the padding when using a CSS content/before selector/property?

E.g. given the follow code, how can I make the bottom paragraph look like the top on (with no white space between the content:before) but retain the padding on the paragraph.

Code: http://jsfiddle.net/569Ed/2/

HTML5:

<div class="no-padding">
    <p>Paragraph</p>
</div>

<div class="padding">
    <p>Paragraph</p>
</div>

CSS3:

p {
    outline: 3px solid #fbb;
    outline-top: 2px solid #fbb;
    margin-bottom: 15px;
}
p:before {
    content: 'Paragraph';
    border: 1px solid #fbb;
    background-color: #fbb;
    display: block;
}

.padding p {
    padding: 10px;
}

(this is only for the lastest and greatest browsers only, so HTML5 and CSS3/LESS is preferred)

like image 593
Petah Avatar asked Sep 11 '26 18:09

Petah


1 Answers

i think you can do it this way,

code : http://jsfiddle.net/yuliantoadi/569Ed/4/

p {
    outline: 3px solid #fbb;
    outline-top: 2px solid #fbb;
    margin-bottom: 15px;
}
.padding p {
    padding: 10px;
}
p:before {
    content: 'Paragraph';
    border: 1px solid #fbb;
    background-color: #fbb;
    display: block;
}
.padding p:before {
    margin:-10px -10px 0 -10px;
}

is that what you mean?

like image 145
yoel Avatar answered Sep 13 '26 16:09

yoel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!