Stop hyperlink inheriting div width?

Hi, I have hyperlinks inside a div with display: block. The problem is that the length of the hyperlinks when clicked is equal to the width of the div. How to make a hyperlink a pressed length equal to the text of the hyperlink without specifying the width for each link? Jsfiddle here

+3
source share
5 answers

Using

#links a {clear:left;float:left}

floatwill allow the size of the link, and clearwill prevent the links from being on the same line.

You may need to add clear:leftto the container #linksdepending on your design.

EDIT

A small tutorial since you asked:

: . . .

. .

<a> . , , .

float , . float / . .

( ).

display:block float: .

display:inline-block, , ( ).

+5

: inline-block; ( IE6) float: left; float: right;

+1

display: block; - , . , .

, .

JSFiddle

+1

- :

<a href="example.com" style="text-decoration: none;">Foo</a>
0

:

: ;

divs,

0
source

Source: https://habr.com/ru/post/1777852/


All Articles