Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make <Span> above a button, clickable (as the button)?

See this fiddle

I want the "eye" icon on the one hand to appear as it is now (above the button, so I don't think a z-index would help), yet on the other hand I want to have the button clickable at all its surface, meaning in the eye area as well.

Also, is there a better way to position the eye? as once I'm using different text then "Click me", I would have to accordingly set the absolute position of the eye. any way to define it better?

<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);
}
like image 546
rockyraw Avatar asked Dec 12 '22 03:12

rockyraw


1 Answers

In terms of making it clickable, you could add pointer-events: none to the element. This essentially allows you to click through the element.

Updated Example

.foo {
    pointer-events: none;
    color: red;
    /* Other styles.. */
}

Support for this property can be found here.


Another option would be to wrap both of the elements in a label. When the label is clicked, the input element is triggered, thereby resolving the issue.

Example Here

<label>
    <span class="fa fa-eye fa-lg foo"></span>
    <input type="submit" class="button" value="Click Me"/>
</label>
like image 90
Josh Crozier Avatar answered Jan 06 '23 10:01

Josh Crozier