gpt4 book ai didi

php - 无法在 div 中将搜索栏居中

转载 作者:太空宇宙 更新时间:2023-11-04 11:03:18 24 4
gpt4 key购买 nike

我的网站标题中有一个搜索栏。它是 div 中的输入。我似乎无法弄清楚如何将搜索栏居中放置在 div 的中间。我已经在响应方面完美地设置了它,所以除了居中之外我不想改变它的定位方式。任何帮助将不胜感激。

enter image description here

HTML:

<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<div>
<label hidden="true" for="s">Search for:</label>
<input placeholder="I want to go see lighthouses" class="text" type="text" value="I want to go see lighthouses" name="I want to go see lighthouses" id="s" onfocus="(this.value == 'I want to go see lighthouses') && (this.value = '')" onblur="(this.value == '') && (this.value = 'I want to go see lighthouses')" />
<input hidden="true" type="submit" class="submit" name="Submit" value="Search!" />
</div>
</form>

CSS:

#searchform div {
shadow: 4px 7px 4px #000000;
position: absolute;
width: 100%;
bottom: 90px;
}

#searchform .text {
font-family: 'Merriweather';
background: white url('images/search-img.png') no-repeat;
background-position: 96% center;
font-size: 220%;
color: #B7B7B7;
border-radius: 50px;
padding-left: 35px;
height: 75px;
width: 600px;
max-width: 100%;
display: inline-block;
margin: 0 auto;
}

#searchform .text:focus {
background-image: none;
}

#searchform .text img {
margin-right: 25px;
}

最佳答案

text-align 添加到包装 div 以使内联内容居中。

   #searchform div {
position: absolute;
width: 100%;
bottom: 90px;
text-align: center/* Text align here */
}


#searchform .text {
font-family: 'Merriweather';
background: white url('images/search-img.png') no-repeat;
background-position: 96% center;
font-size: 220%;
color: #B7B7B7;
border-radius: 50px;
padding-left: 35px;
height: 75px;
width: 100%; /* Updated thiese two widths, better for your responsive design */
max-width: 600px;
display: inline-block;
margin: 0 auto;
}
#searchform .text:focus {
background-image: none;
}
#searchform .text img {
margin-right: 25px;
}
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<div>
<label hidden="true" for="s">Search for:</label>
<input placeholder="I want to go see lighthouses" class="text" type="text" value="I want to go see lighthouses" name="I want to go see lighthouses" id="s" onfocus="(this.value == 'I want to go see lighthouses') && (this.value = '')" onblur="(this.value == '') && (this.value = 'I want to go see lighthouses')"
/>
<input hidden="true" type="submit" class="submit" name="Submit" value="Search!" />
</div>
</form>

关于php - 无法在 div 中将搜索栏居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34160248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com