Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy HTML underline

Tags:

html

I am creating a form in HTML that will be printed, with fields that need to be written in by the recipient. Basically what I want is a single line that stretches from the end of the field label to the side of the page. Here's how I'm doing it right now:

<table width="100%">
    <tr>
        <td width="1%">
            Label:
        </td>
        <td style="border-bottom-style:solid; border-bottom-width:1px;">
            &nbsp;
        </td>
    </tr>
</table>

This works, but there must be an easier way to do this without needing a whole table element. Any ideas?

like image 774
gfrizzle Avatar asked Nov 13 '08 18:11

gfrizzle


1 Answers

Here's my CSS:

span.print_underline
{
    display: inline-block;
    height: 1em;
    border-bottom: 1px solid #000;
}

So your HTML will look like:

<span class="print_underline" style="width: 200px">&nbsp;</span>

I left the width out, so I could reuse it as much as I want, but you can specify the width.

As a sidenote, I tested the same concept with a div tag instead of span tag, and it did not work in some situations. This is probably because it is semantically incorrect to put a div within a paragraph tag (which is why I used a span), and I generally use paragraph tags instead of using table rows like you've used.

like image 68
Jon Smock Avatar answered Oct 06 '22 02:10

Jon Smock