Pure css to realize slide show and press button to change color

Method 1: use a link anchor to realize + jquery to realize button color change by pressing

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script type="text/javascript"src="http://Apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js "> < / script > <! -- import jQuery Library -- >
  <title></title>
  <style type="text/css">
  	*{
  		padding: 0;
  		margin: 0;
  	}
  	body{
  		padding: 50px;
  	}
  	a{
  		list-style: none;
  		text-decoration: none;
  		color: #000000;
  		display: inline-block;
  		width: 60px;
  		height: 20px;
  		font-size: 14px;
  		text-align: center;
  	}
  	.content{
  		width: 200px;
  		height: 200px;
  		overflow: hidden;
  	}
  	#a1{
  		width: 200px;
  		height: 200px;
  		background: greenyellow;
  	}
  	#a2{
  		width: 200px;
  		height: 200px;
  		background: orange;
  	}
  	.end{
  		background: blue ;
  		color: #fff;
  	}
  </style>
  <script type="text/javascript">
		$(function(){
			  $("a").click(function(){
			    $("a").eq($(this).index()).addClass("end").siblings().removeClass("end");
			  })
			})
	</script>
</head>
<body>
  <div> 
   <a href="#A1 "class =" end "> first page</a>
  <a href="#A2 "> page 2</a>
  <div class="content">
  	<div id="a1">
  		
  	</div>
  	<div id="a2">
  		
  	</div>
  </div>
 
</body>
</html>

Method 2: use input button and checked selector

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
    <title></title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        .tab{
            width: 300px;
            height: 150px;
            margin-left: 30px;
            margin-top: 30px;
            border: 1px solid #eee;
            position: relative;
            overflow: hidden;
        }
        input[type='radio']{
            display: none;
        }
        .tab label{
            display: block;
            cursor: pointer;
            position: absolute;
            width: 60px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            border: 1px solid #eee;
        }
        .one{
            left: 0;
            top: 0;
        }
        .two{
            left: 60px;
            top: 0;
        }
        input[type='radio']:checked~div[class^='mod']{
            display: block;
        }
        input[type='radio']:checked~label{
            background: green;
            color: #fff;
        }
        [class^='mod']{/*[class^='']Matches each element whose attribute value begins with the specified value*/
            position: absolute;
            top: 40px;
            left: 20px;
            display: none;
        }
        .mod-1{
        	width: 200px;
        	height: 80px;
        	background: blueviolet;
        }
         .mod-2{
        	width: 200px;
        	height: 80px;
        	background: yellow;
        }
    </style>
</head>
<body>
    <div class="tab">
        <div>
            <input type="radio" id="rd" name="tab" checked>
            <label for="rd" class="one">First chapter</label>
            <div class="mod-1">
                
            </div>
        </div>
        <div>
            <input type="radio" id="rds" name="tab">
            <label for="rds" class="two">Second sheets</label>
            <div class="mod-2">
                
            </div>
        </div>
    </div>
</body>
</html>

Add: there are also some common css property selectors as follows:

  • [attribute~=value] select the element with the specified vocabulary in the attribute value

  • [attribute|=value] selects an element with an attribute value starting with the specified value, which must be the entire word.

  • [attribute$=value] matches each element whose attribute value ends with the specified value

  • [attribute*=value] matches each element of the attribute value that contains the specified value

Tags: Attribute JQuery Javascript IE

Posted on Fri, 10 Jan 2020 10:59:17 -0500 by smarques