I have an inline element with a line break in it. It has padding on all sides. However, the side padding on where the line break cuts the element is not there.
This is what i mean:
http://jsfiddle.net/4Gs2E/
There should be 20px padding on the right of tag and left of with but there isnt. The only other way I can see this working is if i create a new element for every line but this content will be dynamically generated and will not be in a fixed width container so i dont see that working out. Is there any other way I can do this in css without any javascript?
I want the final result to look like this : http://jsfiddle.net/GNsw3/
but without any extra elements
i also need this to work with display inline only as I want the background to wrap around the text as inline block doesnt do this
Is this possible?
edit, altered the examples to make what i want more visible:
current http://jsfiddle.net/4Gs2E/2/
what i want it to look like http://jsfiddle.net/GNsw3/1/
When it comes to margins and padding, browsers treat inline elements differently. You can add space to the left and right on an inline element, but you cannot add height to the top or bottom padding or margin of an inline element. Inline elements can actually appear within block elements, as shown below.
Padding does not have this feature. Padding ignores inline elements: When your web design includes inline elements, which do not flow to a new line and only take up as much width as necessary, you can use margin and padding to add space to either side of the inline element but not above or below it.
Syntax. The padding-inline property may be specified with one or two values. If one value is given, it is used as the value for both padding-inline-start and padding-inline-end . If two values are given, the first is used for padding-inline-start and the second for padding-inline-end .
An inline element does not start on a new line. An inline element only takes up as much width as necessary. This is a <span> element inside a paragraph.
In some cases you can use box-shadow
for a workaround.
Move the right and left padding
of the element to its parent and add two box-shadow
s.
The result: http://jsfiddle.net/FpLCt/1/
Browser support for box-shadow
: http://caniuse.com/css-boxshadow
Update:
There is also a new css property for this issue called box-decoration-break
. It is currently only supported by opera, but hopefully more browsers will implement this soon.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With