我制作了一个复选框作为森林图像。我需要从html参数(数据森林)的森林checbox图像放置另一个透明背景,但我只能通过CSS来做到这一点。我已经尝试了很多解决方案,但没有人能正常工作。任何人有一些想法?如何在没有HTML的情况下将背景与文字叠加到另一个背景图像
悬停最终效果:
的jsfiddle:https://jsfiddle.net/ac9z8sgd/
HTML
<form action="action" method="get">
<input type="hidden" name="test" value="test" />
<ul>
<li><input id="checkbox" type="checkbox" name="forest_type" value="forest_1"><label for="checkbox_forest" data-forest="Estern forest">Forest 1</label></li>
</ul>
<button type="submit">Submit</button>
</form>
CSS
/* Default check button */
#checkbox + label {
background: url('http://i.imgur.com/Ds7gh7b.jpg?1');
background-repeat: no-repeat;
height: 250px;
width: 250px;
padding: 15px 15px;
display: inline-block;
position: relative;
}
/* Hover action */
#checkbox + label[data-forest]:hover {
background: rgba(0,0,0,0.8);
content: attr(data-forest);
display: inline-block;
font-size: 20px;
color: white;
position: relative;
}
那么,你的选择是错误的...'标签+ label'表明您正在寻找的是另一个标签的兄弟标签。你为什么不使用'#checkbox + label:hover'?如果你可以用这个问题创建一个jsfiddle,你很可能会得到更快的答案。 –
是的,它是旧版本。我更新了代码并粘贴jsfiddle链接。谢谢! – XingD123
你可以修改HTML吗? –