Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way I can adjust the width of a <span> inside a <td>?

Tags:

html

css

I have a

<table>
   <tr>
       <td><span style="margin-left: 48px; width: 20px;">2</span></td>
   </tr>
</table>

The span seems to have a margin but the width does not work. Is there a way I can make this work? Note that I thought of using a <div> but from what I understand it might work but it's not allowed inside a <td>.

like image 999
Samantha J T Star Avatar asked Sep 17 '25 19:09

Samantha J T Star


2 Answers

span is inline by default. For it to understand the width it needs to be at least inline-block.

So add the following styles to your css-file:

td span {
    display: inline-block;
}

P.s. Mind that display: inline-block; works from ie8 and higher.

like image 54
skip405 Avatar answered Sep 19 '25 09:09

skip405


<table>
   <tr>
       <td><span style="margin-left: 48px; width: 20px; display: block;">2</span></td>
   </tr>
</table>

Add display: block; and then the <span /> will resize according to the given pixels on the width property.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!