html - 搜索框未在 css3 中定位

标签 html css

input[type=text] {
  margin-left: 63%;
  margin-top: -100%;
    width: 130px;
    box-sizing: border-box;
    border: 2px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    background-color: black;
    background-image: url('searchicon.png');

    background-repeat: no-repeat;
    padding: 12px 20px 12px 40px;
    -webkit-transition: width 0.4s ease-in-out;
    transition: width 0.4s ease-in-out;
}

input[type=text]:focus {
    width: 150px;
}
  <form>
      <input type="text" name="search" placeholder="Search..">
    </form>

即使在输入 margin-top -100% 之后,搜索框也不会上升。它在-10% 后停止上涨。任何帮助将不胜感激。提前致谢。 :)

最佳答案

使用“position:relative”和“top:-100px”。它会将您的搜索框向上移动。您可以根据需要增加“最高”值。

input[type=text] {
margin-left: 63%;
width: 130px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
font-size: 16px;
background-color: black;
background-image: url('searchicon.png');

background-repeat: no-repeat;
padding: 12px 20px 12px 40px;
-webkit-transition: width 0.4s ease-in-out;
transition: width 0.4s ease-in-out;
position: relative;
top: -100px;
}

input[type=text]:focus {
width: 150px;
}

关于html - 搜索框未在 css3 中定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35738772/

相关文章:

css - 当 parent 有特定的不透明度时计算 child 的不透明度

css - 如何命名仅包含@import 语句的 Sass 文件

javascript - HTML5 本地存储在 ie11 win 8.1 x64 中损坏?错误 : function expected

html - 如何将一个 div id 包裹在另一个 div id 周围?

javascript - AngularJS 中不显示背景图片

html - 导航栏导致滚动条

javascript - 使 map 响应

html - 修复了右侧边栏在响应式站点上折叠的问题

HTML CSS 放大/缩小问题

css - 在构建 VITE 应用程序时如何分配自定义 CSS 文件名?