html搜索框居中功能实现
时间: 2023-11-21 18:56:20 浏览: 264
以下是两种HTML搜索框居中功能实现的例子:
1.使用flex布局实现搜索框居中
```html
<div style="display: flex; justify-content: center;">
<input type="text" placeholder="请输入商品">
<input type="button" value="搜索">
</div>
```
2.使用text-align属性实现搜索框居中
```html
<div style="text-align: center;">
<input type="text" placeholder="请输入商品">
<input type="button" value="搜索">
</div>
```
相关问题
html搜索框怎么居中
要使HTML搜索框居中,可以使用以下CSS样式:
```css
input[type="text"] {
width: 50%; /* 设置搜索框宽度 */
margin: 0 auto; /* 设置搜索框水平居中 */
display: block; /* 设置搜索框为块级元素,以便垂直居中 */
}
```
其中,`width`属性可以根据需要进行调整,`margin`属性设置为`0 auto`可以实现水平居中,`display`属性设置为`block`可以实现垂直居中。
uniapp 实现页面居中 搜索框
要在 uniapp 中实现页面居中搜索框,可以使用 flexbox 布局。以下是一个简单的代码示例:
```
<template>
<div class="container">
<form class="search-form">
<input type="text" class="search-input" placeholder="Search...">
<button type="submit" class="search-button"><i class="fa fa-search"></i></button>
</form>
</div>
</template>
<style>
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.search-form {
display: flex;
align-items: center;
border-radius: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.search-input {
flex: 1;
border: none;
font-size: 16px;
padding: 8px;
border-radius: 20px 0 0 20px;
outline: none;
}
.search-button {
background-color: #fff;
border: none;
margin: 0;
padding: 0;
font-size: 16px;
color: #666;
cursor: pointer;
outline: none;
border-radius: 0 20px 20px 0;
}
.search-button:hover {
color: #333;
}
.fa-search {
font-size: 16px;
}
</style>
```
在这个示例中,使用了一个 `<div>` 元素作为容器,使用 flexbox 布局将搜索框和容器居中。`<form>` 元素用于包含搜索框,`<input>` 元素用于创建实际的搜索框,`<button>` 元素用于提交搜索请求。CSS 代码对搜索框进行了样式设置,使其看起来更加美观。
你可以根据需要修改 CSS 代码中的颜色、字体大小和其他样式属性来适应你的网站风格。