Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Underline text but ignore the spaces

I have a couple of links that have a margin-left of 3px. These links are underlined and look like that:

<a href='#'>
    test
</a>

Unfortunately, there are spaces inside the link and I'm not able to remove these space since I don't have access to the HTML code. These spaces are also underlined, which I'm not happy with. Is there any way to remove them without changing the HTML?

Here is a fiddle that shows my problem: http://jsfiddle.net/e8quz/

Update:
Here is a picture, what I want it to look like: enter image description here

like image 266
Matt3o12 Avatar asked Apr 20 '14 13:04

Matt3o12


People also ask

How do you underline text only in CSS?

There is no CSS for applying an underline ( text-decoration: underline; ) only to individual words in a multiple-word element. The best way would be to wrap each word in a span (not the spaces, just the words) in spans and apply underline to those spans.

How do I change the space between underline and text?

In the following “Font” dialog box, switch to “Advanced” page. Select “Raised” in the “Position” box, and enter a specific number you want in the “By” box. For example, here we enter “6 pt”. Note that the larger the value we enter, the more space there will be between texts and underline.

How do you keep underlined in CSS?

Complete HTML/CSS Course 2022 To underline a text, you can also use the style attribute. The style attribute specifies an inline style for an element. The attribute can be used with the HTML <p> tag, with the CSS property text-decoration. Just keep in mind, the usage of style attribute overrides any style set globally.


1 Answers

The spaces come from the line-breaks (well-known from the display:inline-block problematic).

So make your a elements display: block and float them to the left.

DEMO

PS: The display:block is "redundant", as float normally already sets the display property of the respective element to "block". But it do no harm ...!

like image 68
Netsurfer Avatar answered Sep 30 '22 12:09

Netsurfer