css 在表单条目旁边有竖条

wnavrhmk  于 2023-04-08  发布在  其他
关注(0)|答案(1)|浏览(89)

我试图创建一个网页,它是一个表单,但员工ID是从表单的其余部分分开的一个垂直栏,跨越整个页面。x1c 0d1x然而,当我尝试这样做与绿色垂直栏,它看起来像

。任何帮助将不胜感激!!

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

<label htmlFor='ID'>EMPLOYEE #</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'>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>
zy1mlcev

zy1mlcev1#

尝试使用flex,它更容易,也很适合这种情况。
您的组件JSX:

<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;
}

结果

<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>

相关问题