【问题标题】:Change Border Color on div without button using Javascript使用Javascript更改没有按钮的div上的边框颜色
【发布时间】:2021-07-06 01:55:18
【问题描述】:

单击时,我需要帮助在 .wpcf7-list-item 元素上添加边框颜色。我试过 :focus & :active 并且它仍然不显示边框。 ff。是我的代码:

Contact Form 7 Multi-Steps:

<div style="display:inline; text-align:center">[radio firstpage class:firstgroup use_label_element default:1 "Spitzlift" "Rollstuhllift" "Weiß ich noch nicht"]</div>

Page Inspector:

<span class="wpcf7-form-control wpcf7-radio firstgroup">
   <span class="wpcf7-list-item first">
      <label><input type="radio" name="firstpage" value="Spitzlift" checked="checked"><span class="wpcf7-list-item-label">Spitzlift</span></label>
   </span>

   <span class="wpcf7-list-item"><label><input type="radio" name="firstpage" value="Rollstuhllift"><span class="wpcf7-list-item-label">Rollstuhllift</span></label>
   </span>

   <span class="wpcf7-list-item last"><label><input type="radio" name="firstpage" value="Weiß ich noch nicht"><span class="wpcf7-list-item-label">Weiß ich noch nicht</span></label>
   </span>
</span>

Here's the code I used in CSS:
.firstgroup span.wpcf7-list-item:active {
   border:2px solid #05b3cf
}

【问题讨论】:

  • 我欢迎使用 javascript 答案来使其工作。 Onclick 事件不起作用,因为它仅在触发时适用于按钮。谢谢!

标签: javascript css hover focus


【解决方案1】:

这可以单独通过 CSS 来实现。您可以为:checked 单选按钮使用::before 伪元素并为其应用边框。

请注意,您需要确保父项具有 position: relative 样式,以便 ::before 元素为 position: absolute 并拉伸以填充其整个父元素..

.wpcf7-list-item {
  position: relative;
  padding: 4px;
}

.wpcf7-list-item input[type="radio"]:checked::before {
  content: ' ';
  position: absolute;
  display: block;
  top:0;
  right:0;
  left: 0;
  bottom: 0;
  border: solid 1px red;
}
<span class="wpcf7-form-control wpcf7-radio firstgroup">
   <span class="wpcf7-list-item first">
      <label><input type="radio" name="firstpage" value="Spitzlift" checked="checked"><span class="wpcf7-list-item-label">Spitzlift</span></label>
   </span>

   <span class="wpcf7-list-item"><label><input type="radio" name="firstpage" value="Rollstuhllift"><span class="wpcf7-list-item-label">Rollstuhllift</span></label>
   </span>

   <span class="wpcf7-list-item last"><label><input type="radio" name="firstpage" value="Weiß ich noch nicht"><span class="wpcf7-list-item-label">Weiß ich noch nicht</span></label>
   </span>
</span>

【讨论】:

  • 您的 CSS 完美运行。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2010-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多