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

我无法通过CSS更改项的宽度

  •  1
  • mchd  · 技术社区  · 8 年前

    我是前端开发的初学者,正在一个调查网站上工作。我的网站有很多输入字段,我想根据它们的性质改变它们的宽度,但由于某种原因,我不能这样做。该项不在灵活容器中,但正在更改 width 属性没有区别。

    我想改变我的宽度 input 我的领域 customerAge 使其足够小,仅能容纳2位数字。

    这是我的代码笔链接: https://codepen.io/omaroz92/full/VBWbae/

    对于为什么更改width属性中的值没有任何区别,我希望有详细的解释。

    body {
      background-color: #98AFC7;
    }
    
    #title {
      text-align: center;
      font-family: Arial, Times, serif;
      font-style: oblique;
      color: white;
    }
    
    #screen-belly {
      background-color: rgb(250, 250, 250);
      margin: 0 auto;
      border-radius: 4px;
      width: 75%;
      max-width: 1000px;
      padding: 10px;
      padding-top: 20px;
    }
    
    p {
      text-align: center;
      font-family: monospace, serif;
      font-size: 15px;
    }
    
    .container {
      width: 75%;
      max-width: 600px;
      margin: 0 auto;
    }
    
    .row {
      display: flex;
    }
    
    .customerAge {
      width: 100px;
    }
    
    input {
      flex: 1;
      height: 20px;
      min-width: 0;
      padding: 5px;
      margin: 10px;
      border: 1px solid #c0c0c0;
      border-radius: 2px;
    }
    <h1 id="title">Survey Form</h1>
    
    <div id="screen-belly">
      <p>Please take the short Survey to hep us improve our services</p>
    
      <div class="container">
    
        <div class="row">
          <input autofocus type="text" name="name" id="name" placeholder="First name" required>
          <input type="text" name="name" id="name" placeholder="Last Name" required>
        </div>
    
        <div class="row">
          <input type="text" name="email" id="email" placeholder="e-Mail address" required>
        </div>
    
        <div class="customerAge">
          <input type="number" name="age" id="Age" placeholder="age" required>
        </div>
      </div>
    </div>
    1 回复  |  直到 8 年前
        1
  •  1
  •   Mr Alihoseiny    8 年前

    你已经包装好了 Age 输入在 customerAge 但是你已经申请了 width 属性指向父级,而不是 input . 您可以在CSS代码中尝试此操作:

    .customerAge input#Age {
    
        width: 31px;
    }
    

    你可以改变 31px 到您想要的值。

    如果你感到困惑, input#Age 之后 .customerAge 意思是: 场与 年龄 里面的ID 顾客化 班级。