简体   繁体   English

如何在表单上的字段下划线,但单元格中的文本除外

[英]How to underline a field on a form except text in the cell

I've been asked to make a form that has labels in cells (not underlined) followed by an underlined area that indicates where someone is supposed to put information.我被要求制作一个表格,该表格在单元格中包含标签(没有下划线),然后是一个带下划线的区域,指示某人应该在哪里放置信息。 I don't personally like this design approach, but it is what I've been asked to do.我个人不喜欢这种设计方法,但这是我被要求做的。

Something like this:像这样的东西:

First Name: ________
Last Name: ________
Street Address: ________

In other words, everything in the table cell is underlined except the label and the trailing space character.换句话说,除了label 和尾随空格字符之外,表格单元格中的所有内容都带有下划线。

The labels contain varying information and clearly will not align.标签包含不同的信息,显然不会对齐。 However, all the underlines should right-align in their respective cells.但是,所有下划线都应在其各自的单元格中右对齐。

Here's a pen that hopefully illustrates what I'm trying to do.这是一支笔,希望能说明我正在尝试做的事情。 https://codepen.io/timmerbu/pen/pojMypE?editors=1100 https://codepen.io/timmerbu/pen/pojMypE?editors=1100

 html { font-size: 16px; } body { background: #9f9; } div { background: #fff; padding: 1rem; margin: auto; width: 200px; } table, tr, td { margin: 0; padding: 0; border-collapse: collapse; } table { width: 100%; } tr:nth-child(odd) { background: #fd4; } td { padding: 3px; }
 <div> <p>This is a test.</p> <table> <tbody> <tr> <td>Word: __________________</td> </tr> <tr> <td>Word word: ______________</td> </tr> <tr> <td>Word word word: _________</td> </tr> <tr> <td>Word word word word: ____</td> </tr> </tbody> </table> <p>End of test.</p> </div>

You can try this code你可以试试这段代码

 <p style="width: 250px; display: table;"> <span style="display: table-cell; width: 80px;">First Name:</span> <span style="display: table-cell; border-bottom: 1px solid black;"></span> </p>

A little non-formal, but it works.有点不正式,但它有效。 Removing the underscore and adding it back with a CSS Pseudo class, while having the <span> for the text has a background and z-index that puts the underline behind it.删除下划线并使用 CSS 伪 class 将其添加回来,同时具有文本的<span>具有背景和 z-index,将下划线置于其后面。 You can change the underline placement by adjusting the top: -4px;您可以通过调整top: -4px; . .

 html { font-size: 16px; } body { background: #9f9; } div { background: #fff; padding: 1rem; margin: auto; width: 200px; } table, tr, td { margin: 0; padding: 0; border-collapse: collapse; } table { width: 100%; } tr:nth-child(odd) { background: #fd4; } td { padding: 3px; } tbody td:after { border-bottom: 1px solid #f50909; content: ""; width: 100%; height: 1px; display: block; position: relative; top: -4px; } td span { display: inline-block; position: relative; z-index: 2; padding-right: 5px; background: #FFF; } tr:nth-child(odd) span { background: #FD4; }
 <div> <p>This is a test.</p> <table> <tbody> <tr> <td><span>Word:</span></td> </tr> <tr> <td><span>Word word:</span></td> </tr> <tr> <td><span>Word word word:</span></td> </tr> <tr> <td><span>Word word word word:</span></td> </tr> </tbody> </table> <p>End of test.</p> </div>

I think with the underlined field, you would like the user to enter the text too... I suggest the following HTML我认为对于带下划线的字段,您也希望用户输入文本......我建议以下 HTML

You can use a <span> <td> <p> or any other suitable container tag, I am using <div>您可以使用<span> <td> <p>或任何其他合适的容器标签,我正在使用<div>

 <div> First Name: <input type="text" style="border: none; border-bottom: solid 1px black; width: 200px" /> </div>

You can put the styling in a CSS as well您也可以将样式放入 CSS


UPDATED更新

Right align all the underlines右对齐所有下划线

 <table style="width: 300px"> <tr> <td> <div style="width: 100%; float: left"> <span style="background-color: white">First Name: </span> <hr style="margin-top: -4px;/> </div> </td> </tr> <tr> <td> <div style="width: 100%; float: left"> <span style="background-color: white">Last Name: </span> <hr style="margin-top: -4px;/> </div> </td> </tr> <tr> <td> <div style="width: 100%; float: left"> <span style="background-color: white">Age: </span> <hr style="margin-top: -4px;/> </div> </td> </tr> <tr> <td> <div style="width: 100%; float: left"> <span style="background-color: white">Gender: </span> <hr style="margin-top: -4px;/> </div> </td> </tr> </table>

simply use use css after?简单地使用 css 之后?

 .underlined:after { content: '______________' }
 <p class="underlined">First Name: </p> <p class="underlined">Last Name: </p> <p class="underlined">Street Address: </p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM