请问下左边透明的怎么在图片之上呢?除此之外代码还有什么地方需要优化吗?
尝试过的解决方式:
尝试在左侧透明框,和中间的图片框加z-index,但是无效
相关代码:
<!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>
.top {
margin: 0px auto;
height: 200px;
}
.top p {
font-size: 32px;
text-align: center;
font-weight: bold;
}
.top .line {
width: 50px;
height: 2px;
background-color: #07cbc9;
margin: 10px auto;
}
.top span {
display: inline-block;
width: 500px;
height: 100px;
text-align: center;
position: relative;
left: 50%;
margin-left: -250px;
font-size: 14px;
}
.box {
overflow: hidden;
width: 1201px;
height: 464px;
margin: 0 auto;
}
.box .left {
float: left;
width: 200px;
height: 300px;
}
.box .left .left-t p {
font-size: 32px;
font-weight: bold;
}
.box .left .left-b {
float: left;
width: 300px;
height: 180px;
border: 1px solid gray;
background: rgba(255, 255, 255, .5);
padding: 20px;
z-index: 222;
}
.box .left .left-b button {
width: 140px;
height: 40px;
background-color: #000;
color: #fff;
}
.box .center {
float: left;
width: 650px;
height: 434px;
text-align: center;
margin: 30px auto;
z-index: 111;
background: url("img/bb3.jpg");
}
.box .right {
float: right;
}
.box .right .right-t,
.box .right .right-b {
width: 260px;
height: 200px;
border: 1px solid skyblue;
margin-top: 20px;
}
.box .right .right-t p:first-child,
.box .right .right-b P:first-child {
font-size: 32px;
text-align: center;
font-weight: bold;
}
.box .right .right-t p:last-child,
.box .right .right-b P:last-child {
text-align: center;
}
.box .right .right-t .line,
.box .right .right-b .line {
width: 50px;
height: 2px;
background-color: #07cbc9;
margin: 10px auto;
}
</style>
</head>
<body>
<div class="top">
<p>ABOUT</p>
<div class="line"></div>
<span>boream Ipsum is simply dummy text of the printing and typesetting industry.Lorem Ipsum has been the industy's standard dummy text ever since the 1500s</span>
</div>
<div class="box">
<div class="left">
<div class="left-t">
<p>A WORDS ABOUT US</p>
</div>
<div class="left-b">
<p>parent disgnissim biberra est,sed bibendum ligula congue non.Sed ac nisl er felis gravida commodo?Suspendisse eget ulliamcrper ipsum,Suspendisse diam amet.</p>
<button>EXPIORE</button>
</div>
</div>
<div class="center">
<!-- <img src="img/bb3.jpg" alt=""> -->
</div>
<div class="right">
<div class="right-t">
<p>70000</p>
<div class="line"></div>
<p>Student</p>
</div>
<div class="right-b">
<p>600</p>
<div class="line"></div>
<p>Facully</p>
</div>
</div>
</div>
</body>
</html>
18
收起
正在回答
2回答
同学你好,问题解答如下:
1、在左侧透明框和中间的图片框加z-index无效的原因为:z-index 仅能在定位元素上有效,而代码中没有设置定位,所以加z-index是无效的。
2、代码中的问题如下:
(1)图片没有居中显示,

原因:由于给图片设置了浮动,图片脱离了文档流,所以设置的margin:0 auto;就不生效了
修改:建议去掉图片的浮动设置如下图:

去掉浮动后,右边的数字部分由于超出父元素被隐藏

建议给.box设置相对定位,给右边的数字盒子设置绝对定位,如下图:


3、另外还有一个需要优化的地方,左侧按钮可以去掉默认边框,更美观一些

代码修改如下:

祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星