将div显示中元素的宽度固定为表格

时间:2016-03-31 15:55:42

标签: css row css-tables

我有问题将div显示中的元素宽度固定为表格,我意识到导致此问题的标题,我试图修复它没有成功,这里是示例:

以下是代码:

.row {
  display:table;
  border-spacing:10px;
  width: 100%;
  height: 100%;
}

.row-element {
  display: table-cell;
}
.row-element input{
  width:100%;
  line-height:20px;
}
.row-element label{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #2E2F3F;
display: table-caption;
white-space: nowrap;
  width:100%;
  box-sizing:border-box;
}
<div class="row">
  <div class="row-element">
    <label>Name#<span class="mandatory"> *</span></label>
	<input data="true" type="text" class="textfield error" title="Name" minlength="5" maxlength="15" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
					</div>
					<div class="row-element"><label>Outside Label &gt; <span class="mandatory"> *</span></label>
					
					  <input data="true" type="text" class="textfield error" minlength="5" maxlength="15" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
					</div> 
<div class="row-element">
  <label>custom_mandatory text#<span class="mandatory"> (Please Specify)</span></label>
  <input data="true" type="text" class="textfield error" mandatory-text="(Please Specify)" title="custom mandatory text" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
	</div> 					
 </div>

1 个答案:

答案 0 :(得分:0)

Is this what you're after? I added table-layout: fixed; to row and some arbitrary width to row-element.

.row {
  display:table;
  border-spacing:10px;
  width: 100%;
  height: 100%;
  table-layout: fixed;
}

.row-element {
  display: table-cell;
  width: 100px;
}
.row-element input{
  width:100%;
  line-height:20px;
}
.row-element label{
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #2E2F3F;
display: table-caption;
white-space: nowrap;
  width:100%;
  box-sizing:border-box;
}
<div class="row">
  <div class="row-element">
    <label>Name#<span class="mandatory"> *</span></label>
	<input data="true" type="text" class="textfield error" title="Name" minlength="5" maxlength="15" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
					</div>
					<div class="row-element"><label>Outside Label &gt; <span class="mandatory"> *</span></label>
					
					  <input data="true" type="text" class="textfield error" minlength="5" maxlength="15" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
					</div> 
<div class="row-element">
  <label>custom_mandatory text#<span class="mandatory"> (Please Specify)</span></label>
  <input data="true" type="text" class="textfield error" mandatory-text="(Please Specify)" title="custom mandatory text" message="Insert Your Name !" name="NAME_FIELD" mandatory="">
	</div> 					
 </div>

相关问题