CSS 输入字段设计

发布于 2025-01-13 06:06:39 字数 1437 浏览 3 评论 0原文

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

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

发布评论

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

评论(2

朕就是辣么酷 2025-01-20 06:06:40

您可以尝试在表单元素中使用 fieldset。

<fieldset>
  <legend>
    <label for="username">Username</label>
  </legend>
  <input type="text" id="username" name="username">
</fieldset>

之后,您可以尝试在 css 中编辑样式。可能是为了去掉输入的边框并更改框的宽度。

You can try to use fieldset in your form element.

<fieldset>
  <legend>
    <label for="username">Username</label>
  </legend>
  <input type="text" id="username" name="username">
</fieldset>

After that, you can try to edit your styling in your css. Probably to take out the border of the input and change the width of the box.

还不是爱你 2025-01-20 06:06:40

使用 :before 进行基本演示。

input {
  border: transparent;
  text-align: left;
}

input::placeholder {
  text-align: center;
}

input:focus {
  outline: transparent;
}

.line {
  border: 1px solid black;
  border-radius: 5px;
  width: fit-content;
  padding: 10px 0px 5px 0px;
}

.line:before {
  content: "username";
  position: absolute;
  top: 0;
  left: 20px;
  background-color: white;
  padding: 0 2px;
}
<div class="line">
<input type="text" placeholder="[email protected]">
</div>

Basic demonstration using :before.

input {
  border: transparent;
  text-align: left;
}

input::placeholder {
  text-align: center;
}

input:focus {
  outline: transparent;
}

.line {
  border: 1px solid black;
  border-radius: 5px;
  width: fit-content;
  padding: 10px 0px 5px 0px;
}

.line:before {
  content: "username";
  position: absolute;
  top: 0;
  left: 20px;
  background-color: white;
  padding: 0 2px;
}
<div class="line">
<input type="text" placeholder="[email protected]">
</div>

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