无法掩盖盒子阴影和输入字段之间的差距

发布于 2025-01-26 23:21:43 字数 2422 浏览 2 评论 0原文

尝试为课程(ODIN项目)创建基本网站布局。但是,我注意到他们的网站设计具有完美的盒子阴影,没有轻度差距。无论我尝试多少我尝试弄乱框Shadow属性设置,似乎都在盒子阴影和输入字段之间存在一个小的1-2px差距。这是非常明显的,有点破坏了设计。我是CSS的新手,希望有人经验丰富的人能将我带入一个好的解决方案。

.form-flex-container {
  display: flex;
  flex-direction: column;
  margin-bottom: 40px;
}
    
input {
  width: 215px;
  height: 20px;
  border-radius: 3px;

  border: 1.5px solid #e5e7eb;
}
input[type="text"] {
  padding-left: 9px;
}

input:focus {
  outline-color: #4a6ed6;
  border: none;
  box-shadow: 2px 2px 5px #bebebe;

}

label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #2e3a4b;
  margin-bottom: 3px;
  /* margin-left: 2px; */
  /* float: left; */
}
<form action="post">
  <div class="form-row-1">
    <div class="form-flex-container">
      <label for="first-name">First Name</label>
      <input type="text" name="first-name" id="first-name" />
    </div>
    <div class="form-flex-container">
      <label for="last-name">Last Name</label>
      <input type="text" name="last-name" id="last-name" />
    </div>
  </div>
  <div class="form-row-2">
    <div class="form-flex-container">
      <label for="email">Email</label>
      <input type="text" name="email" id="email" />
    </div>
    <div class="form-flex-container">
      <label for="phone-number">Phone Number</label>
      <input type="text" name="phone-number" id="phone-number" />
    </div>
  </div>
  <div class="form-row-3">
    <div class="form-flex-container">
      <label for="password">Password</label>
      <input type="text" name="password" id="password" />
    </div>
    <div class="form-flex-container">
      <label for="confirm-password">Confirm Password</label>
      <input type="text" name="confirm-password" id="confirm-password" />
    </div>
  </div>
</form>
    

我使盒子阴影变暗,这样您就可以更清楚地看到差距。

Trying to create a basic website layout for a course (Odin Project). However I noticed that their website design has a perfect box shadow with no light gap. Where as my design no matter how much I try to mess with the box shadow property settings seems to have a small 1-2px gap between the box shadow and input fields. This is very noticeable and sort of ruins the design. I am a novice at CSS and was hoping someone more experienced could direct me to a good solution.

.form-flex-container {
  display: flex;
  flex-direction: column;
  margin-bottom: 40px;
}
    
input {
  width: 215px;
  height: 20px;
  border-radius: 3px;

  border: 1.5px solid #e5e7eb;
}
input[type="text"] {
  padding-left: 9px;
}

input:focus {
  outline-color: #4a6ed6;
  border: none;
  box-shadow: 2px 2px 5px #bebebe;

}

label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #2e3a4b;
  margin-bottom: 3px;
  /* margin-left: 2px; */
  /* float: left; */
}
<form action="post">
  <div class="form-row-1">
    <div class="form-flex-container">
      <label for="first-name">First Name</label>
      <input type="text" name="first-name" id="first-name" />
    </div>
    <div class="form-flex-container">
      <label for="last-name">Last Name</label>
      <input type="text" name="last-name" id="last-name" />
    </div>
  </div>
  <div class="form-row-2">
    <div class="form-flex-container">
      <label for="email">Email</label>
      <input type="text" name="email" id="email" />
    </div>
    <div class="form-flex-container">
      <label for="phone-number">Phone Number</label>
      <input type="text" name="phone-number" id="phone-number" />
    </div>
  </div>
  <div class="form-row-3">
    <div class="form-flex-container">
      <label for="password">Password</label>
      <input type="text" name="password" id="password" />
    </div>
    <div class="form-flex-container">
      <label for="confirm-password">Confirm Password</label>
      <input type="text" name="confirm-password" id="confirm-password" />
    </div>
  </div>
</form>
    

I darkened the box shadow so you could see the gap more clearly.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

很酷不放纵 2025-02-02 23:21:43

所以我发现了什么问题。显然,由于某种原因,当我使用属性概述宽度概述时,它实际上并没有针对输入下的轮廓:focus选择器。我必须使用速记概述:1PX实心#4A6ED6;以摆脱差距。所以现在它起作用了。

参见文档。

So I discovered what was wrong. Apparently for some reason when I used the property outline-width and outline-color it wasn't actually targeting the outline under the input:focus selector. I had to use the shorthand outline: 1px solid #4a6ed6; to get rid of the gap. So now it works.

See outline property from MDN docs.

蓝眸 2025-02-02 23:21:43

而不是使用border:无您可以将其设置为1.5px实心#4A6ED6并删除uterline

input {
  width: 215px;
  height: 20px;
  border-radius: 3px;
  border: 1.5px solid #e5e7eb;
}

input:focus {
  // outline-color: #4a6ed6;
  outline: none;
  border: 1.5px solid #4a6ed6;
  box-shadow: 2px 2px 5px #bebebe;
}
<form action="post"> 
  <div class="form-row-1">
    <div class="form-flex-container">
      <input type="text" name="first-name" id="first-name" />
    </div>
  </div>
</form>

Instead of using border: none you can set it to 1.5px solid #4a6ed6 and remove the outline :

input {
  width: 215px;
  height: 20px;
  border-radius: 3px;
  border: 1.5px solid #e5e7eb;
}

input:focus {
  // outline-color: #4a6ed6;
  outline: none;
  border: 1.5px solid #4a6ed6;
  box-shadow: 2px 2px 5px #bebebe;
}
<form action="post"> 
  <div class="form-row-1">
    <div class="form-flex-container">
      <input type="text" name="first-name" id="first-name" />
    </div>
  </div>
</form>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文