Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do I get an anchor tag to fill the width of a table cell?

Tags:

html

anchor

width

I have a table cell with an anchor tag and I want the width (and height) of the anchor tag to fill the width of the containing table cell. Intuition doesn't seem to work on this. Please help.

HTML:

<table>
    <tr>
        <td class="width_is_100px">
            <a href="http://www.doesnotwork.com"><span class="make_width_100px">Some Text</span></a>
        </td>
    </tr>
</table>

CSS: (doesn't work)

.make_width_100px {
    width:100px !important;
}

The anchor tag is only as wide as the text "Some Text". I want the user to be able to click anywhere inside the table cell and trigger the link. No javascript please.

like image 375
John Anderson Avatar asked Jun 04 '12 03:06

John Anderson


People also ask

How do you increase the width of a table cell?

Resize a column or table automatically with AutoFit. Automatically adjust your table or columns to fit the size of your content by using the AutoFit button. Select your table. On the Layout tab, in the Cell Size group, click AutoFit.

How do I change the width of an anchor tag?

css: <style> li { width: 110px; height: 42px; background-color: black; } li a { width: 32px; height: 32px; color: white; } </style> html page: <li><a href="#">write something</a></li> you need to set anchor tag's display property as block :: 'display:block;' , then only it will accept values of height and width.

How do you stop a cell from expanding in a table?

To prevent cells (rows) from expanding vertically, you have to set a fixed height for table rows. Select the relevant rows and, on the Table Tools Layout tab, click Properties. On the Row tab, select "Specify height" and then choose "Exactly" for "Row height is." Specify the desired amount.


2 Answers

Try it:

a {
    display: block;
    height: 100%;        
    width: 100%;
}
like image 75
Tooraj Jam Avatar answered Nov 02 '22 11:11

Tooraj Jam


Make your <a> element a block element (it's inline by default):

.width_is_100px a {
    display:block;
}
like image 27
Tieson T. Avatar answered Nov 02 '22 12:11

Tieson T.