[英]How I use FontAwesome in input :before?
I want to use FontAwesome in :before
( \\F002
Hand glass mark). 我想在:before
使用FontAwesome( \\F002
手玻璃标记)。 But it doesn't work. 但它不起作用。 (:focus works) (:重点工作)
What do I missing? 我错过了什么?
.font-awesome { border-radius: 15px; border: 1px solid gray; padding: 0 15px 0 30px; line-height: 30px; outline: none; } .font-awesome:focus { border-color: lightblue; } .font-awesome:before { font-family: FontAwesome; content: "\\f002"; }
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> <input type="text" class="font-awesome" />
You cant apply pseudo class :before
:after
on input
tag. 你不能应用伪类:before
在input
标签:before
:after
。 Its invalid. 它无效。
Pseudo classes are only for container elements. 伪类仅用于容器元素。 You can not use them in elements like
<input>
,<img>
etc. 你不能在<input>
,<img>
等元素中使用它们。
Try to use span
for icon and wrap this into a label
尝试使用span
作为图标并将其包装成label
Stack Snippet 堆栈代码段
label input { border-radius: 15px; border: 1px solid gray; padding: 0 15px 0 30px; line-height: 30px; outline: none; } .font-awesome:focus { border-color: lightblue; } .font-awesome:before { font: normal normal normal 14px/1 FontAwesome; content: "\\f002"; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"> <label><input type="text" class="" /><span class="font-awesome"></span></label>
I changed my code by Bhuwan's advice. 我按照Bhuwan的建议改变了我的代码。 (I put the icon on left inside.) (我把图标放在里面。)
CSS: CSS:
.keyword {
border-radius: 15px;
border: 1px solid lightgray;
padding: 0 15px 0 30px;
line-height: 30px;
outline: none;
}
.keyword:focus {
border-color: MediumTurquoise;
}
.search_icon:before {
font: normal normal normal 15px/1 FontAwesome;
content: "\f002";
color: lightgray;
position: absolute;
top: 16px;
left: 16px;
}
HTML: HTML:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<label>
<span class="search_icon" />
<input type="text" class="keyword" />
</label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.