简体   繁体   English

HTML 搜索元素样式

[英]HTML Search element styling

I´m trying to build a search element together with a button, something like:我正在尝试与按钮一起构建搜索元素,例如:

Except that I need to change the background color of the search icon (blue, gray, whatever...).除了我需要更改搜索图标的背景颜色(蓝色、灰色等等……)。

Here is my code so far and the result:到目前为止,这是我的代码和结果:

 .searchWrap { position: absolute; border: thin solid #f2f2f2; border-radius: 5px; top: 5px; left: 5px; } .searchTerm { float: left; border-style: none; padding: 5px; height: 20px; outline: none; } .searchButton { right: -50px; width: 30px; height: 20px; border: 1px solid #f2f2f2; background: #f2f2f2; border-radius: 5px; text-align: center; color: #ccc; vertical-align: middle; cursor: pointer; }
 <div className="searchWrap"> <input type="text" className="searchTerm" placeholder="Search..." /> <button type="submit" className="searchButton"> <Icon name='search' /> </button> </div>

I'm using React.我正在使用反应。 Here is my result so far:这是我到目前为止的结果:

在此处输入图片说明

The external border is rounded, ok, that's what I need, but the separation between the searchTerm and the searchButton is also rounded, and I need a plain separator here, something like:外部边框是圆角的,好吧,这就是我需要的,但是searchTerm和searchButton之间的间隔也是圆角的,我这里需要一个普通的分隔符,比如:

在此处输入图片说明

I'm using font awesome here, so the code isn't spaced like your screenshot, but looks like you have your own library you're using with react for that icon and your spacing is fine.我在这里使用了很棒的字体,所以代码的间距不像你的屏幕截图,但看起来你有自己的库,你正在使用该图标的反应并且你的间距很好。

All you need to do is use border-radius: 0 5px 5px 0 to keep the left side borders from rounding, and assign a border-left on the .searchButton to draw the vertical line.您需要做的就是使用border-radius: 0 5px 5px 0来防止左侧边框四舍五入,并在.searchButton上指定一个border-left来绘制垂直线。 I changed the border color so it's more prominent, but you can use whatever color you want.我更改了边框颜色,使其更加突出,但您可以使用任何您想要的颜色。

 *{margin:0;padding:0;} .searchWrap { position: absolute; top: 5px; left: 5px; } .searchTerm { float: left; border-style: none; padding: 5px; height: 20px; outline: none; margin-left: 3px; border: thin solid #ddd; border-width: thin 0 thin thin; border-radius: 5px 0 0 5px; } .searchButton { right: -50px; width: 30px; height: 32px; border: 1px solid #f2f2f2; background: #f2f2f2; border-radius: 0 5px 5px 0; text-align: center; color: #ccc; vertical-align: middle; cursor: pointer; border: thin solid #ddd; } .searchTerm:focus, .searchTerm:focus + .searchButton { border-color: red; }
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="searchWrap"> <input type="text" class="searchTerm" placeholder="Search..." /> <button type="submit" class="searchButton"> <i class="fa fa-search"></i> </button> </div>

Try this for the search button css instead of border-radius试试这个搜索按钮 css 而不是border-radius

.searchButton {
    ...
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    ...
}

Can you use bootstrap?你可以使用引导程序吗? Relatively simple, and once you have it, modify the css the way you want it.比较简单,一旦有了,就按照你想要的方式修改css。

https://v4-alpha.getbootstrap.com/components/input-group/#button-addons https://v4-alpha.getbootstrap.com/components/input-group/#button-addons

Bootstrap is strongly recommended for this.为此,强烈建议使用 Bootstrap。 See http://getbootstrap.com/components/#input-groups .请参阅http://getbootstrap.com/components/#input-groups Coupled with FontAwesome, you could do something like this:结合 FontAwesome,您可以执行以下操作:

<div class="input-group">
  <input type="text" class="form-control" placeholder="Search for...">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">
      <span class="fa fa-search"></span>
      <span class="sr-only">Search</span>
    </button>
  </span>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM