简体   繁体   English

如何仅为图像应用css类

[英]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. 这里css类完全适用于输入文本字段,当鼠标悬停在文本字段上时,光标显示手形符号总输入字段,我只显示该图像的手形符号而不是整个文本字段。

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. 也许您可以将图像添加为常规图像(而不是bg)并使用一些位置:绝对和z-index将其放在文本框的后面或前面。

I suppose you could make it happen with JavaScript, but it would be quite a convoluted solution. 我想你可以用JavaScript实现它,但这将是一个非常复杂的解决方案。 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: CSS:

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

See http://jsfiddle.net/tNwTz/ for a demo. 有关演示,请参见http://jsfiddle.net/tNwTz/

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

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