如何将搜索框定位到我的规格?

时间:2016-03-26 15:07:32

标签: css wordpress

我在div中有搜索表单,但我似乎无法将它放在我想要的位置。使用“top”,“bottom”,“left”,“right”命令不起作用。命令“margin:0 auto;”将div放在x平面上但不放在y平面上。有人知道为什么会这样吗?我怎么能改变它?

CSS

#box {
    height: 60px;
    width: 100%;
}
#postcode-search {
    height: 60px;
    width: 510px;
    border: 3px solid yellow;
    margin: 0 auto;
}

input#item-search.form-control {
    height: 50px;
    width: 450px;
    border: 1px solid #fd0e35;
    padding: 0px;
    top: 400px;
    vertical-align: middle;
    font-size: 14px;
    text-align: center;

HTML

<div id="box">
    <div id="postcode-search">
        <?php get_search_form();?>
    </div>
</div>

2 个答案:

答案 0 :(得分:0)

您可以使用Flexbox

执行此操作

&#13;
&#13;
#postcode-search {
  height: 60px;
  width: 510px;
  border: 3px solid yellow;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
&#13;
<div id="box">
  <div id="postcode-search">
    Search box
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

#box {
  height: 60px;
  width: 100%;
}

#postcode-search {
  height: 60px;
  width: 510px;
  border: 3px solid yellow; 
  position: relative;
  text-align:center;
}

input#item-search.form-control {
  height: 50px;
  width: 450px;
  border: 1px solid #fd0e35;
  padding: 0px;
  top: 400px;
  vertical-align: middle;
  font-size: 14px;
  text-align: center;
}

#postcode-search > *{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
<div id="box">
  <div id="postcode-search">
    <form>
      <input id="item-search" class="form-control" />
    </form>
  </div>
</div>