代码之家  ›  专栏  ›  技术社区  ›  XMehdi01

如何使水平线分开标签和输入?

  •  0
  • XMehdi01  · 技术社区  · 3 年前

    我想做一个包含 label input 隔着 中间点着的水平线。
    与描述字段类似: enter image description here 我用过的 网格 具有 span (这是一条水平线)并给出 1fr 占据所有的空间 标签 输入 ;
    这就是我迄今为止所尝试的:

    .field {
      display: grid;
      grid-template-columns: 20% 1fr 40%;
      font-family: "Segoe UI";
    }
    .field span {
      height: 0px;
      width: 100%;
      border: 4px dotted gray;
      border-top: 10px;
    }
    label {
      text-transform: capitalize;
      font-size: 1.5rem;
      color: rgb(65, 65, 65);
    }
    input {
      outline: 1px solid rgb(81, 81, 81);
      border: none;
      color: rgb(81, 81, 81);
      font-size: 1.6rem;
      padding: 3px;
    }
    input:focus {
      outline: 1.3px solid rgb(0, 131, 143);
    }
    <div class="field">
      <label for="Description"> Description </label>
      <span></span><!--This is horizontal dotted line -->
      <input type="text" id="Description" />
    </div>

    但它似乎与上图中的预期输出不完全相同,任何关于如何使水平线更受欢迎的建议!

    1 回复  |  直到 3 年前
        1
  •  1
  •   Gabriel Nuñez de Andrade    3 年前

    enter image description here

    我用flex box和 align-items: center 而不是网格

    .field {
      display: flex;
      align-items: center;
      ...
    }
    

    并在跨度上添加了X轴边距

    .field span {
      margin: 0 16px;
      ...
    }
    

    您还可以更改跨度边框颜色的不透明度,使其更接近所附着的图像

    .field span {
      border: 4px dotted rgba(128, 128, 128, 0.23);
      ...
    }