html - input::before 元素不显示

标签 html css

<分区>

input::before 元素未显示。我不确定为什么:

input::before {
  content: "this is before";
  position: absolute;
}

body {
  background-color: Royalblue; /*#f0f0f0;*/
  margin: 0px;
}

form {
  position: relative;  
  top: 90px;
  margin: 0 auto;
  width: 280px;
  height: 340px; 
  border: 1px solid #B0C4DE;
  background: royalblue;   
  border-radius: 0px;
  border-radius: 10px 10px 10px 10px;
}

/* Main EFFECT ================================ */


input {
  position: relative;
  top: 0px;
  left: 0px;   
  font-family: 'Montserrat', sans-serif;
  border: 0; 
  border-bottom: 1px solid black;
  background: transparent;
  font-size: 15px;                     
  height: 25px; 
  width: 180px;
  outline: 0; 
  z-index: 1; 
  color: black;
}


span {
  position: absolute;
  top: 7px;
  left: 0px;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
/*  z-index: 1; */
  color: white; 
  transition: top .5s ease, font-size .5s ease;     
}


input::before {
  content: "this is before";
  position: absolute;
}

.child {
    position: relative;
    width: 65%;
    top: 30px;
    margin: 0 auto;
/*    margin-bottom: 30px;*/
}
<body>
  <form class="parent">     
    <div class="child">
      <input type="text" id="username" required /> 
        <span>Username</span>
    </div>
   </form>     
</body>

最佳答案

我的理解:输入是 replaced元素。替换是指内容被浏览器的默认小部件(此处为文本框)替换。 您可以使用包装元素解决此问题 <input/> .这是一个例子和它的 fiddle 。

HTML

<span class="input-container">
    <input type="text" id="username" required /> 
</span>

CSS

span.input-container:before {
  content: "|";
  border: 1px solid blue;
}

请更改值以适合您的风格。

fiddle :https://jsfiddle.net/4csrwy0f/7/

关于html - input::before 元素不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52397482/

上一篇:html - 如何在移动应用程序上保持设计比例?

下一篇:html - 在 HTML 中对齐多个 CSS 卡片

相关文章:

html - 是否可以在没有js的情况下使一个元素与另一个元素具有相同的宽度?

html - 为什么 CSS 规则被禁用

html - 第一个 child 选择不起作用

Javascript - session.getAttribute 返回未定义的值

html - 垃圾邮件机器人和输入表单

javascript - 在使用 HTTP/2 时,缩小和连接 JS/CSS 文件以及对图像使用 sprite 是否仍然提供性能优势?

javascript - 调整多边形点路径(svg)内的图像大小并使其不被剪裁

html - 在表格 td 标签中使用制表符

javascript - 保存AngularJS后如何在页面上显示新数据

html - 按钮对齐文本下方的背景图像