搜索框里面左边是文字 右边是一个搜索字体图标 用css怎么实现?
时间: 2024-04-15 09:31:08 浏览: 16
您可以使用CSS中的flex布局来实现搜索框左侧是文字,右侧是搜索图标的效果。以下是一个示例代码:
HTML:
```html
<div class="search-box">
<input type="text" placeholder="搜索">
<div class="search-icon">
<i class="fa fa-search"></i>
</div>
</div>
```
CSS:
```css
.search-box {
display: flex;
align-items: center;
width: 300px;
border: 1px solid #ccc;
border-radius: 4px;
padding: 5px;
}
input[type="text"] {
flex-grow: 1;
border: none;
outline: none;
}
.search-icon {
padding: 0 10px;
}
.fa-search {
color: #999;
}
```
在这个示例中,我们使用了一个`div`元素作为搜索框容器,并使用flex布局来处理元素的排列。输入框使用`input`元素,通过设置`flex-grow: 1;`使其占据剩余的空间。搜索图标使用了Font Awesome提供的图标,您可以根据自己的需求更换图标。
请注意,这只是一个示例代码,您可以根据自己的需求进行样式调整和扩展。
相关问题
用css写一个左边是图片右边是文字介绍的代码
可以使用CSS的flexbox布局来实现左侧图片右侧文字的布局。
HTML结构:
```
<div class="container">
<img src="image.jpg" alt="image">
<div class="text">
<h2>标题</h2>
<p>文本内容</p>
</div>
</div>
```
CSS样式:
```
.container {
display: flex;
align-items: center; /* 垂直居中 */
}
img {
width: 50%; /* 图片占据50%的宽度 */
margin-right: 20px; /* 图片与文本之间的间距 */
}
.text {
flex: 1; /* 剩余空间全部占据 */
}
```
可以根据需要调整图片和文字的大小、颜色、字体等样式。
styele里写css页面中间放一个搜索框 搜索框右边是蓝色按钮
你可以这样写:
HTML 代码:
```html
<div class="search-box">
<input type="text" placeholder="搜索...">
<button class="btn-blue">搜索</button>
</div>
```
CSS 代码:
```css
.search-box {
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
max-width: 400px;
}
input[type="text"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px 0 0 5px;
width: 100%;
font-size: 16px;
}
.btn-blue {
background-color: blue;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 0 5px 5px 0;
font-size: 16px;
cursor: pointer;
}
```
这里用了 flexbox 布局,将搜索框和按钮放在一起,并居中显示。搜索框的样式为灰色边框和圆角左侧,按钮的样式为蓝色背景和白色字体。