请问下左边透明的怎么在图片之上呢?除此之外代码还有什么地方需要优化吗?

请问下左边透明的怎么在图片之上呢?除此之外代码还有什么地方需要优化吗?

尝试过的解决方式:

尝试在左侧透明框,和中间的图片框加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>


正在回答

登陆购买课程后可参与讨论,去登陆

2回答

同学你好,问题解答如下:

1、在左侧透明框和中间的图片框加z-index无效的原因为:z-index 仅能在定位元素上有效,而代码中没有设置定位,所以加z-index是无效的。

2、代码中的问题如下:

(1)图片没有居中显示,

http://img1.sycdn.imooc.com//climg/603f55cb0986c7a313410605.jpg

原因:由于给图片设置了浮动,图片脱离了文档流,所以设置的margin:0 auto;就不生效了

修改:建议去掉图片的浮动设置如下图:

http://img1.sycdn.imooc.com//climg/603f55e1096ec53a04380245.jpg

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

http://img1.sycdn.imooc.com//climg/603f56020997111613030607.jpg

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

http://img1.sycdn.imooc.com//climg/603f5616095cb6a602930200.jpg

http://img1.sycdn.imooc.com//climg/603f562109f9662902620174.jpg

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

http://img1.sycdn.imooc.com//climg/603f563809b4e89102540213.jpg

代码修改如下:

http://img1.sycdn.imooc.com//climg/603f564e09137d7902940194.jpg

​祝学习愉快!

  • 从不学习 提问者 #1

    有一个疑问,前面按照老师说的都没问题,当给.box .right 设置绝对定位时,我觉得只设置right:0:就可以,但是不设置top属性就看不到右侧的东西了,这是为什么呢?

    2021-03-03 17:59:51
好帮手慕张 2021-03-03 19:24:11

同学你好,不设置top值是默认会在左侧和图片两个元素下面显示的,而代码中设置了overflow:hidden;属性,只设置right的话高度还是超出父元素的,超出父元素的部分被隐藏了,所以看不到右侧的。因此要设置top值才可以。

祝学习愉快!

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师