看小红书觉得有趣就做了一份
主要用到的就是给元素添加事件,并且复习CSS中的定位基础
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box {
width: 500px;
height: 300px;
background-color: rgb(185, 181, 181);
margin: 100px auto;
position: relative;
}
.box2 {
width: 500px;
height: 300px;
margin: 0px auto;
/* 会继承父盒子的margin */
position: absolute;
top: 0px;
left: 0px;
background-color: skyblue;
}
.tu {
width: 400px;
height: 130px;
margin-left: 20px;
position: absolute;
top: 60px;
left: 20px;
font-size: 20px;
font-weight: 800;
}
.box2 img {
width: 150px;
height: 150px;
vertical-align: text-bottom
/* 注意用到图片与文字的对齐,不能让图片浮动起来 */
}
.qe1 {
font-size: 30px;
text-align: center;
padding-top: 50px
}
.close {
width: 30px;
height: 30px;
/* background-image: url(关闭.png);
background-position: center;
background-repeat: no-repeat; */
background-color: white;
font-size: 20px;
position: absolute;
top: 0px;
right: 0px;
border: 1px solid grey
}
.ans1,
.ans2 {
font-size: 20px;
width: 100px;
height: 30px;
text-align: center;
line-height: 30px;
}
.ans1 {
position: absolute;
left: 50px;
bottom: 80px;
}
.ans2 {
position: absolute;
right: 50px;
bottom: 80px;
}
.xbox {
width: 400px;
height: 200px;
background-color: red;
position: absolute;
top: 50px;
left: 50px;
text-align: center;
}
.ch {
font-size: 20px;
}
.ch2 {
width: 150px;
height: 30px;
margin-top: 40px;
}
</style>
</head>
<body>
<div class="box">
<p class="qe1">你觉得你<strong>漂亮</strong>吗</p>
<button class="close">x</button>
<button class="ans1">我最漂亮</button>
<button class="ans2">不觉得</button>
<div class="xbox" style="display:none">
<p class="ch">点我没用,快点选</p>
<button class="ch2">回去重选</button></div>
<div class="box2" style="display:none">
<div class="tu"> <img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp5.itc.cn%2Fimages01%2F20201121%2F80d1111d323e4235a919a53658f1283b.jpeg&refer=http%3A%2F%2Fp5.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1648173756&t=d48c7d99df838b33a5450b32c253a0f0"
alt=""> 嗯!!!!你自己知道就好
</div>
</div>
</div>
<script>
var ans1 = document.querySelector('.ans1')
var ans2 = document.querySelector('.ans2')
console.log(ans2.innerText)
ans1.onmouseover = function() {
if (ans1.innerHTML == '我最漂亮') {
ans1.innerHTML = '不觉得'
ans2.innerHTML = '我最漂亮'
}
}
ans1.onmouseout = function() {
if (ans1.innerHTML == '不觉得') {
ans1.innerHTML = '我最漂亮'
ans2.innerHTML = '不觉得'
}
}
var box2 = document.querySelector('.box2')
ans1.onclick = function() {
box2.style.display = 'block'
}
ans2.onclick = function() {
box2.style.display = 'block'
}
var close = document.querySelector('.close')
var xbox = document.querySelector('.xbox')
close.onclick = function() {
xbox.style.display = 'block'
}
var ch2 = document.querySelector('.ch2')
ch2.onclick = function() {
xbox.style.display = 'none'
}
</script>
</body>
</html>