简体   繁体   中英

How to apply css class for image only

.calendarList {  
       background-image: url('/resource3/hpsc/common/images/calendar.png');
       background-position: 135px 50%;
       background-repeat: no-repeat;
       cursor:pointer;
}

<input type="text" id="toDatepicker" class="calendarList" name="searchEndDate" size="20" >

Here the css class is applying totally to input text fields, when mouse over on text field, the cursor is showing hand symbol total input field, I what to show the hand symbol for that image only not for whole text field.

I don't think it's possible what you're trying to do.

Maybe you can add the image as a regular image (not as bg) and use some position: absolute and z-index to place it behind or in front of the textbox.

I suppose you could make it happen with JavaScript, but it would be quite a convoluted solution. It's easier if you make the image a label instead of a background picture and position it on top of the input field.

<input type="text" id="toDatepicker" class="calendarList" name="searchEndDate" size="20" >
<label for="toDatepicker" id="datepickerLabel>
    <img src="/resource3/hpsc/common/images/calendar.png" />
</label>

CSS:

#datepickerLabel {
    position:relative;
    left:-20px;
    cursor:pointer;
}

See http://jsfiddle.net/tNwTz/ for a demo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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