Anyway to have a label respond to :focus CSS(无论如何都要有一个标签响应 :focus CSS)
问题描述
有没有办法让标签响应焦点.我有一些代码,其中文本字段具有不同的焦点样式.然而,标签也需要稍微不同的风格.我试过这个,但它没有影响标签.
Is there any way to have a label respond to focus. I have some code where the textfield has a different style on focus. The label also however needs a slightly different style. I tried this but it did not effect the label.
#header .search label {
background:url(http://www.golfbrowser.com/images/icons/search.png) left top no-repeat;
padding-left:20px;
height:20px;
float:right;
}
#header .search label:focus {
background:url(http://www.golfbrowser.com/images/icons/search-z.png) left top no-repeat;
padding-left:20px;
height:20px;
float:right;
}
#header .search input {
padding:0px;
border:0px;
width:140px;
height:20px;
float:left;
padding-right:10px;
background:url(http://www.golfbrowser.com/images/icons/searchbar.png) right top no-repeat;
}
#header .search input:focus {
padding:0px;
width:190px;
height:20px;
float:left;
padding-right:10px;
background:url(http://www.golfbrowser.com/images/icons/searchbar-z.png) right top no-repeat;
}
标签包含图像和圆角的其他部分,它也必须改变颜色才能使字段看起来正确.
The label contains an image and the other part of a round corner and it too must change colour in order for the field to look correct.
任何想法,
太棒了
推荐答案
您实际上无法将焦点放在标签上.它不是可聚焦的表单元素.此外,即使您可以这样做,那么之前的焦点(即您的输入)无论如何都会丢失到标签中.
You can't actually give focus to a label. It's not a focusable form element. Besides, even if you could do that, then whatever previously had focus (that means your input) would lose it to the label anyway.
您可能需要重新构建您的 HTML(并相应地修改您的 CSS),以便您可以选择 input:focus
,然后选择 该输入的相应标签.例如,如果您在输入后移动标签并为标签使用以下 CSS 选择器,您应该能够完成您想要的.
You may have to restructure your HTML (and modify your CSS accordingly) so that you can select input:focus
and then that input's corresponding label. For instance, if you moved your label after your input and used the following CSS selector for your label, you should be able to accomplish what you want.
#header .search input:focus + label
这篇关于无论如何都要有一个标签响应 :focus CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无论如何都要有一个标签响应 :focus CSS


基础教程推荐
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01