Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Padding on the sides for multiline link background?

I am trying to build links that look like these:

enter image description here

This from another post on here is the closest I have found - http://jsbin.com/ahoyug/1/edit

but due to using border-left the gaps between the line height is filled. As shown here:

enter image description here

Is this possible to do using CSS or will a JS solution be needed?

like image 544
Kevin Mann Avatar asked Aug 14 '12 14:08

Kevin Mann


People also ask

Does background color affect padding?

Styling of an element such as background color does not affect the margin. Padding is affected by the styling of an element, such as background color.

How do you make a table with multiple lines on long text in CSS?

When the text in a single table cell exceeds a few words, a line break (<BR>) may improve the appearance and readability of the table. The line break code allows data to be split into multiple lines. Place the line break code <BR> within the text at the point(s) you want the line to break.

How do I show multiple lines of text in HTML?

Complete HTML/CSS Course 2022 To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.


2 Answers

Is this what you want?

Demo

JSFiddle

HTML

<div>
<span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</span>
</div>​

CSS

div {
    padding: 40px;
    background-color: #C9D77D;
    font-family: Helvetica, sans-serif;
    font-weight: bold;
    font-size: 20px;
}

span {
    padding: 6px 0;
    background-color: white;
    line-height: 2.2;
    box-shadow: -10px 0px 0 #FFF, 10px 0px 0 #FFF;
}

Edit: I added the box-shadow property from @Jaik's answer because it was totally great.

like image 148
Marcelo De Polli Avatar answered Oct 16 '22 07:10

Marcelo De Polli


It can certainly be done with CSS3 box-shadow easily enough. I've put up a JS Bin example here: http://jsbin.com/ahoyug/12/edit

You'll need to sort out vendor prefixes and old IE fallbacks for production.

like image 2
Jaik Dean Avatar answered Oct 16 '22 08:10

Jaik Dean