在表单输入旁边放置垂直条。

huangapple go评论52阅读模式
英文:

Have vertical bar right next to form entry

问题

我正在尝试创建一个网页,其中有一个表单,但员工编号与表单的其余部分由一根跨越整个页面的垂直条分隔。在表单输入旁边放置垂直条。 但是,当我尝试使用绿色垂直条时,它看起来像 在表单输入旁边放置垂直条。。任何帮助将不胜感激!!

.vl {
	border-left: 6px solid green;
	height: 500px;
}
<label htmlFor='ID'>员工编号</label>
<input className="form-control w-25" id="ID" readOnly></input>
<div className="vl"></div>
<form data-transport-order="form">
  <div className="form-group">
    <label htmlFor='ID'>发票号</label>
    <input className="form-control" id="ID" readOnly></input>
    <label htmlFor="TransportDate">日期</label>
    <input type="date" className="form-control w-25" ID="TransportDate" autoFocus required></input>
  </div>
</form>
英文:

I am trying to create a webpage where it is a form, but the employee id is separated from the rest of the form by a vertical bar that spans the entire page. 在表单输入旁边放置垂直条。 However, when I try to do that with a green vertical bar, it looks like 在表单输入旁边放置垂直条。. Any help would be greatly appreciated!!

.vl {
	border-left: 6px solid green;
	height: 500px;
  }

&lt;label htmlFor=&#39;ID&#39;&gt;EMPLOYEE #&lt;/label&gt;
&lt;input className=&quot;form-control w-25&quot; id=&quot;ID&quot; readOnly&gt;&lt;/input&gt;
&lt;div className=&quot;vl&quot;&gt;&lt;/div&gt;
&lt;form data-transport-order=&quot;form&quot;&gt;
&lt;div className=&quot;form-group&quot;&gt;
&lt;label htmlFor=&#39;ID&#39;&gt;Invoice No.&lt;/label&gt;
&lt;input className=&quot;form-control&quot; id=&quot;ID&quot; readOnly&gt;&lt;/input&gt;
&lt;label htmlFor=&quot;TransportDate&quot;&gt;Date&lt;/label&gt;
&lt;input type=&quot;date&quot; className=&quot;form-control w-25&quot; ID=&quot;TransportDate&quot; autoFocus required&gt;&lt;/input&gt;
&lt;/div&gt;



</details>


# 答案1
**得分**: 2

尝试使用 flex 布局,它更容易适应这种情况。

您的组件 JSX:

```html
<div className='form-container'>
    <div className='employee-id'>
        <label htmlFor='ID'>EMPLOYEE #</label>
        <input className="form-control w-25" id="ID" readOnly></input>
    </div>
    <form className='employee-details' data-transport-order="form">
        <div className="form-group">
            <label htmlFor='ID'>Invoice No.</label>
            <input className="form-control" id="ID" readOnly></input>
            <label htmlFor="TransportDate">Date</label>
            <input type="date" className="form-control w-25" id="TransportDate" autoFocus required></input>
        </div>
    </form>
</div>

样式:

.form-container {
  display: flex;
  flex-direction: row;
}

.employee-id {
  display: flex;
  flex-direction: column;
  border-right: 6px solid green;
  margin-right: 10px;
  padding-right: 10px;
}

.employee-details .form-group {
  display: flex;
  flex-direction: column;
}

结果:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    .form-container {
      display: flex;
      flex-direction: row;
    }
    
    .employee-id {
      display: flex;
      flex-direction: column;
      border-right: 6px solid green;
      margin-right: 10px;
      padding-right: 10px;
    }
    
    .employee-details .form-group {
      display: flex;
      flex-direction: column;
    }
  </style>
</head>

<body>
  <div id="root">
    <div class="App">
      <div class="form-container">
        <div class="employee-id"><label for="ID">EMPLOYEE #</label><input class="form-control w-25" id="ID" readonly=""></div>
        <form class="employee-details" data-transport-order="form">
          <div class="form-group"><label for="ID">Invoice No.</label><input class="form-control" id="ID" readonly=""><label for="TransportDate">Date</label><input type="date" class="form-control w-25" id="TransportDate" required=""></div>
        </form>
      </div>
    </div>
  </div>
</body>

</html>

<!-- end snippet -->

以上是您要翻译的内容。

英文:

Try using flex it's easier and a good fit of this case.

Your component JSX:

&lt;div className=&#39;form-container&#39;&gt;
&lt;div className=&#39;employee-id&#39;&gt;
&lt;label htmlFor=&#39;ID&#39;&gt;EMPLOYEE #&lt;/label&gt;
&lt;input className=&quot;form-control w-25&quot; id=&quot;ID&quot; readOnly&gt;&lt;/input&gt;
&lt;/div&gt;
&lt;form className=&#39;employee-details&#39; data-transport-order=&quot;form&quot;&gt;
&lt;div className=&quot;form-group&quot;&gt;
&lt;label htmlFor=&#39;ID&#39;&gt;Invoice No.&lt;/label&gt;
&lt;input className=&quot;form-control&quot; id=&quot;ID&quot; readOnly&gt;&lt;/input&gt;
&lt;label htmlFor=&quot;TransportDate&quot;&gt;Date&lt;/label&gt;
&lt;input type=&quot;date&quot; className=&quot;form-control w-25&quot; id=&quot;TransportDate&quot; autoFocus required&gt;&lt;/input&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;

Styles:

.form-container{
display: flex;
flex-direction: row;
}
.employee-id{
display: flex;
flex-direction: column;
border-right: 6px solid green;
margin-right: 10px;
padding-right: 10px;
}
.employee-details .form-group{
display: flex;
flex-direction: column;
}

Result

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;style&gt;    
.form-container {
display: flex;
flex-direction: row;
}
.employee-id {
display: flex;
flex-direction: column;
border-right: 6px solid green;
margin-right: 10px;
padding-right: 10px;
}
.employee-details .form-group {
display: flex;
flex-direction: column;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;root&quot;&gt;
&lt;div class=&quot;App&quot;&gt;
&lt;div class=&quot;form-container&quot;&gt;
&lt;div class=&quot;employee-id&quot;&gt;&lt;label for=&quot;ID&quot;&gt;EMPLOYEE #&lt;/label&gt;&lt;input class=&quot;form-control w-25&quot; id=&quot;ID&quot; readonly=&quot;&quot;&gt;&lt;/div&gt;
&lt;form class=&quot;employee-details&quot; data-transport-order=&quot;form&quot;&gt;
&lt;div class=&quot;form-group&quot;&gt;&lt;label for=&quot;ID&quot;&gt;Invoice No.&lt;/label&gt;&lt;input class=&quot;form-control&quot; id=&quot;ID&quot; readonly=&quot;&quot;&gt;&lt;label for=&quot;TransportDate&quot;&gt;Date&lt;/label&gt;&lt;input type=&quot;date&quot; class=&quot;form-control w-25&quot; id=&quot;TransportDate&quot; required=&quot;&quot;&gt;&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年4月4日 06:43:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924248.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定