input 和label配合的妙用

1:作为文字隐藏与否的开关;

如下代码:对div里面所包含的文字较多,一开始只展示小部分,当用户点击按钮时,进行全部内容的展示(按钮是以向下隐藏箭头的图片)

html代码如下

   <input type="checkbox" id="A1" >
    <div>
 lestias assumenda nesciunt maiores minus molestiae exercitationem, dolores odit similique. Quidem odit distinctio optio totam eaque reiciendis expedita, voluptatem impedit iste placeat voluptate eius fugit vero, ut minus laudantium ullam debitis dolor? Possimus inventore sit molestiae distinctio. Dolore perspiciatis commodi maiores eius incidunt aut quisquam tenetur neque. Magni voluptatibus omnis tempore quas quos! Quisquam, molestias. Natus, illo culpa tempore enim praesentium corrupti ipsum! Sed eveniet voluptate, minus tempora illum deleniti laudantium facere enim nesciunt, aliquid temporibus pariatur qui. Totam autem consequatur officiis libero magni sit asperiores magnam ipsum.
    </div>  
    <!-- <input type="checkbox" id="A1" > -->
    <label for="A1">
        <img src="向下箭头按钮.jpg" alt="">
    </label>
 
 
css代码如下:
div{
    width: 500px;
    height: 100px;
    margin: auto;
    border: 1px solid red;
    overflow: hidden;
}
 
 
input{
    display: none;
}
                               // 当input被选中的时候,img 按钮转180,向上
                                  input:checked~label>img{
                                         transform: rotate(180deg);
                                 }
// 当input被选中的时候,div内容显示(选择器;只能是兄弟,而不能是弟兄,也就是说可以选中前面的标签+后面的标签;不能选择后面的标签+前面的标签)
input:checked+div{
    height: auto;
}
 
2:点击效果展示,当一个图片被点击后,图片就被换掉(以此来提醒用户点击成功,增加用户体验)
HTML代码如下(p元素用来插入背景图片,作为用户点击的按钮):
<input type="checkbox" id="B2">
<label for="B2">
        <p></p>
</label>
 
CSS代码如下:
p{
   margin: 0;
   padding:0;
   width: 52px;
   height: 52px;
   background-image: url("点击前图片按钮.jpg")
}
#B2:checked+label>p{
    background-image: url("点击后图片按钮.jpg")
 }

input 被checked时和label配合的妙用的更多相关文章

  1. input是否checked与使用jquery的attr或prop方法无关

    最近在项目中有这样一个需求,用户在下单时可以选择优惠券,也可取消选择,并且可以多次选择,取消. 这是一个典型的input标签checked功能,博主使用radio元素实现此需求,但是优惠券只能选中,不 ...

  2. jquery attr方法和prop方法获取input的checked属性问题

    jquery attr方法和prop方法获取input的checked属性问题   问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法 ...

  3. java中 label 配合 break continue 使用方法

    转 https://www.jianshu.com/p/7954b61bc6ee java中 label 配合 break continue 使用的其实是比较少的. 这种做法在业务代码中比较少见. 在 ...

  4. HTML input="file" 浏览时只显示指定文件类型 xls、xlsx、csv

    html input="file" 浏览时只显示指定文件类型 xls.xlsx.csv <input id="fileSelect" type=" ...

  5. faster rcnn test demo ---repaired for video input and save the image, label, score et al. into .mat format

    faster rcnn test demo ---repaired for video input and save the image, label, score et al. into .mat ...

  6. Chrome浏览器,处理input自动填充时带黄色背景色

    /*Chrome浏览器打开网页,input自动赋值时,会带上屎黄色的背景色,下面是通过延长增加自动填充背景色的方式, 让用户感受不到样式的变化*/ input:-webkit-autofill, in ...

  7. input type="number"时,maxlength不起作用怎么解决

    最近小颖在做公司的angular项目时,发现当input type="number"时,maxlength不起作用,百度了下解决方式,顺便记录下,以便后期查看嘻嘻 <inpu ...

  8. react中IOS手机里面两个input同时存在时,聚焦focus失效解决办法

    最近在做webapp搜索功能时,用到两个input同时存在时,轻点input聚焦时,ios手机软键盘弹起又失效,一直在寻找合理的解决办法,现在最简单的总结回顾: <一>bug显示 < ...

  9. 阻止移动端input按钮聚焦时唤起软键盘的方法

    一.设置input为readonly 二.使用JS代码,在input按钮fous时就让其blur

随机推荐

  1. ISO/IEC 9899:2011 条款6.8.4——选择语句

    6.8.4 选择语句 语法 1.selection-statement: if    (    expression    )    statement if    (    expression   ...

  2. Qt编写气体安全管理系统23-类型设置

    一.前言 类型设置这个功能模块大大拓展了整个系统的灵活性,将整个系统中所有用到的控制器型号.探测器数量.探测器型号.气体种类.气体符号都存储到数据库表中,用户在类型设置中可以自由添加删除和修改,这样后 ...

  3. django项目mysite

    项目建立 建立项目mysite 各文件和目录解释: 外层的mysite/目录与Django无关,只是你项目的容器,可以任意重命名. manage.py:一个命令行工具,用于与Django进行不同方式的 ...

  4. LeetCode_401. Binary Watch

    401. Binary Watch Easy A binary watch has 4 LEDs on the top which represent the hours (0-11), and th ...

  5. SpringMVC:学习笔记(11)——依赖注入与@Autowired

    SpringMVC:学习笔记(11)——依赖注入与@Autowired 使用@Autowired 从Spring2.5开始,它引入了一种全新的依赖注入方式,即通过@Autowired注解.这个注解允许 ...

  6. centos umount 卸载出错

    target is busy. (In some cases useful info about processes that use the device ) or fuser()) 解决 fuse ...

  7. IDEA 创建JAVA Maven Web 工程

    转载自https://www.cnblogs.com/1314wamm/p/7475771.html 步骤一:首先先创建一个project,上次我说过了创建一个project就是一个工作空间,在这里就 ...

  8. PHP正则匹配价格

    /** * 匹配价格 * @param $price * @return bool */ public static function checkPrice($price) { // 不能小于0 if ...

  9. vue利用keep-alive/beforeRouteLeave前进刷新后退不刷新(缓存)

      keep-alive缓存 在vue中默认router-link进入页面组件都是不缓存的.对于数据不会更新的页面.可以使用keep-alive来缓存以提高性能. 在项目src/router/inde ...

  10. DjangoRestful 递归嵌套序列化器实现

    **** 由于博客园不支持markdown语法,所以推荐以下链接阅读: 原创 https://blog.csdn.net/weixin_42495873/article/details/8943354 ...