Search code examples
htmlhref

Reducing link clickable width


I have a link on my website and I dont like the way it is clickable along the whole width of the page. I have tried putting blank divs with width attributes on either side of the link and tried putting a width attribute in the link itself. I also tried the overflow attribute recommended in another answer. Does anyone have any suggestions? Here is the code:

<div align= 'center'>
<a href = "link"><p style="font-size: 15px;">text</p></a>
</div>

Solution

  • p stands for a paragraph, which is a block level element. These use the full width available to them by default. Your case looks like you want a span instead, which is an inline element, like the link itself, that only spans the contained text.

    <div align= "center">
    <a href = "link"><span style="font-size: 15px;">text</span></a>
    </div>
    

    Alternatively, you could skip the tag completely by applying the style directly to the link instead.

    <div align= "center">
    <a href = "link" style="font-size: 15px;">text</a>
    </div>