一方面我希望“眼睛”图标像现在这样显示(在按钮上方,所以我认为 z-index 不会有帮助),但另一方面我想要按钮在它的所有表面都可以点击,这意味着在眼睛区域也是如此。
还有,有没有更好的定位眼睛的方法?一旦我使用不同的文本然后“单击我”,我将不得不相应地设置眼睛的绝对位置。有什么方法可以更好地定义它?
<form action="1.php" method="POST" target="_blank">
<input type="submit" class="button" value="Click Me"><span class="fa fa-eye fa-lg foo" "></span>
</form>
.foo{
color:red;
font-size:1.7em;
position: absolute;
height: 11px;
top: 18px;
left: 15px;
pointer-events: none;
}
.button {
display: inline-block;
zoom: 1;
line-height: normal;
white-space: nowrap;
vertical-align: baseline;
text-align: center;
cursor: pointer;
-webkit-user-drag: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
font-family: inherit;
font-family: arial;
font-size: 17px;
padding: .5em .9em .5em 2em;
text-decoration: none;
border-radius: 4px;
text-shadow: 0 1px 1px rgba(0, 0, 0, .2);
}
最佳答案
就使其可点击而言,您可以添加 pointer-events: none
到元素。这实际上允许您点击元素。
.foo {
pointer-events: none;
color: red;
/* Other styles.. */
}
支持这个属性可以found here .
另一种选择是将这两个元素包装在一个label
中。单击标签时,将触发 input
元素,从而解决问题。
<label>
<span class="fa fa-eye fa-lg foo"></span>
<input type="submit" class="button" value="Click Me"/>
</label>
关于html - 如何使按钮上方的 <Span> 可点击(作为按钮)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25964250/