html - 如何使单个标签的内容相等?
问题描述
这是一个 react.js 应用程序。我希望我的输出看起来像这样:
但我有这个输出:
我已经在我的 CSS 中尝试了 text-indent 和 space-between ,但它不起作用。
这是我的 HTML 代码:
为修复进度添加项目 <div className="AddItemDiv">
<span className="spanItem"> Ticket No: <strong>170</strong> </span>
<br/><br/>
<span className="spanItem">
Issue: <strong>Cannot Login in Inventory System</strong>
</span>
<br/><br/>
<span className="spanItem"> Status:
<select>
<option selected value="">First Choice</option>
<option value="">Second Choice</option>
<option value="">Third Choice</option>
<option value="">Fourth Choice</option>
</select>
</span>
<br/><br/>
<span className="spanItem"> PIC:
<select>
<option selected value="">First Choice</option>
<option value="">Second Choice</option>
<option value="">Third Choice</option>
<option value="">Fourth Choice</option>
</select>
</span>
<br/><br/>
<span className="spanItem">
Remarks: <input type="text" name="name" />
</span>
<br/>
解决方案
您可以使用布局为 的网格系统2 columns
,也可以在这种情况下放弃使用标签,当您有文本、短语、诗歌等需要在文本中换行的内容时<br />
,更喜欢使用标签。<br >
这是一个网格系统的基本示例:
.ticket-form {
max-width: 400px;
display: grid;
grid-template: auto / 150px 1fr;
gap: 10px;
}
<div class="ticket-form">
<label for="ticket-no">Ticket No:</label>
<output id="ticket-no">170</output>
<label for="issue">Issue:</label>
<output id="issue">Cannot login in Inventory System</output>
<label for="status">Status:</label>
<select id="status">
<option selected></option>
</select>
<label for="pic">PIC:</label>
<select id="pic">
<option selected></option>
</select>
<label for="remarks">Remarks:</label>
<textarea id="remarks"></textarea>
<label>Important</label>
<div data-comment="multi elements in right">
<div>if you have more that 1 element you must wrap with a div to mantain the grid flow</div>
<div>or use another solution, the div wrapping the line with flex or something else</div>
</div>
</div>
此处有关网格的更多信息:https ://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Grids
下面是一个使用 div 来换行和使用 flex 系统来控制其内部间距的示例:
.input-wrapper {
margin: 5px;
display: flex;
width: 400px;
}
/* use a fixed width label */
.input-wrapper label {
width: 150px;
}
.input-wrapper textarea,
.input-wrapper input,
.input-wrapper select {
flex-grow: 1;
}
<div>
<div class="input-wrapper">
<label for="ticket-no">Ticket No:</label>
<output id="ticket-no">170</output>
</div>
<div class="input-wrapper">
<label for="issue">Issue:</label>
<output id="issue">Cannot login in Inventory System</output>
</div>
<div class="input-wrapper">
<label for="status">Status:</label>
<select id="status">
<option selected></option>
</select>
</div>
<div class="input-wrapper">
<label for="pic">PIC:</label>
<select id="pic">
<option selected></option>
</select>
</div>
<div class="input-wrapper">
<label for="remarks">Remarks:</label>
<textarea id="remarks"></textarea>
</div>
</div>
display: inline-block
当然,在or的帮助下还有其他解决方案float: left
,我个人认为 grid 或 flex 是更好的选择。
推荐阅读
- python - 尽管使用了计算,但延迟输出延迟的结果
- java - 错误:包android.support.v7.app不存在导入android.support.v7.app.ActionBarActivity;
- java - 如何从 URL 共享 PDF、XIS、DOC、PNG
- python - 如何仅使用for循环在python中反转给定数字
- google-bigquery - 我将某个品牌及其竞争对手的已售商品数量存储在同一列中,但希望将其放在单独的列中
- javascript - 如何旋转正方形以最小化每个点与四个任意点之间的距离?
- python - 如何在 Pandas 中有效地选择多个值范围?
- python - 在 tkinter 中复制一个窗口
- sql - SQL MAX 返回多个值,但我只想要 MAX 值
- tensorflow - CRNN tf.keras.backend.ctc_decode。什么是对数概率?