改变input框默认css样式的方法

2023-05-22,

这篇文章将为大家详细讲解有关改变input框默认css样式的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

input能改变css样式,其修改css样式的方法:1、利用伪类元素改变radio样式;2、利用label指向input,并通过改变label样式来达到效果即可。

改变input框默认css样式的方法:

一:利用伪类元素改变radio样式 (此方法无需添加额外的标签,更便捷)

  .div input[type=radio]::after {
    position: absolute;
    width: 25px;
    height: 25px;
    background: url(../img/inputBG.jpg) no-repeat;
    background-size: 100% 100%;
  }

二:利用label指向input,通过改变label样式来达到效果

<html>  
    <input type="checkbox" checked="checked" id="aa"/><label for="aa"></label>
  </html>
  <style>
    input[type=checkbox]{
       visibility: hidden;
    }
    label{
      width:20px;
      height:20px;
      border:1px solid #707070;
    }
    input[type=checkbox]:checked + label{
      background: url(../img/duigou.jpg)no-repeat;
      background-size: 100% 100%;
    }
  </style>

关于“改变input框默认css样式的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

《改变input框默认css样式的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。