麻烦老师帮忙看下,代码正确吗。谢谢

来源:4-6 自由编程

叫我丽红

2021-04-16 15:39:10

相关截图:

http://img.mukewang.com/climg/60793f1909c89c8c13340563.jpg

相关代码:

html
<!-- Banner区域 -->
<div class="banner">
<img class="picture" src="images/banner3.jpg" alt="">

<div class="center">
<h2>遮罩层</h2>
</div>

<div class="list">

<form action="" method="POST">
<input type="text" placeholder="your Name">
<input type="text" placeholder="your Phone">
<input type="email" placeholder="your email">
<textarea rows="10" cols="30" placeholder="write your content here"></textarea>
<input class="last" type="submit" placeholder="send messang">
</form>
</div>

</div>


css:
/* banner区域 */
.banner{
width: 100%;
position: relative;
}

.banner .picture{
width:100%;
}

.banner .center{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 1px solid red;
background-color:rgba(0, 0, 0, 0.5)

}

.banner .list{
background: none;
}

.banner .list form{
position: absolute;
width: 504px;
height: 310px;
top: 50%;
left: 50%;
margin-top: -155px;
margin-left: -252px;
text-align: center;
}

.banner .list form input{
width: 504px;
height: 40px;
background-color:rgba(0,0,0,0.3);
margin-bottom: 10px;
border: 1px solid #808080;
color:#808080;

}

.banner .list form textarea{
width: 504px;
height: 110px;
background-color:rgba(0,0,0,0.3);
margin-bottom: 10px;
border: 1px solid #808080;
color:#808080;

}


.banner .list form .last{
width: 200px;
height: 40px;
background-color:rgba(0,0,0,0.3);
margin-bottom: 10px;
border: 1px solid #808080;
color:#808080;

}


写回答

1回答

好帮手慕慕子

2021-04-16

同学你好,代码整体思路是可以的,还有如下几点需要注意:

1、由于img标签自带间距,导致遮罩层图片下方之间存在间隙,效果不美观。

http://img.mukewang.com/climg/607948040949ec3f06320160.jpg

建议:给图片添加display:block;属性消除间隙。

http://img.mukewang.com/climg/6079483309d1876f03980145.jpg

2、由于内层元素边框也占据页面宽度,导致实际宽度超出了外层盒子的宽度,导致表单整体居中存在误差。如下图所示:

http://img.mukewang.com/climg/6079486e091b3c7a07950438.jpg

建议:调整form标签的宽高,让其刚好包裹子元素。

http://img.mukewang.com/climg/6079491a093bc8f705170424.jpg

3、使用background:none;属性去掉表单项的背景,效果更美观

http://img.mukewang.com/climg/60794938091e0f7e08250318.jpg

http://img.mukewang.com/climg/6079497b09f0df8709010590.jpg

4、样式相同的代码可以书写在一起,简化代码书写,示例:

http://img.mukewang.com/climg/607949ef09864ecc06640656.jpg

5、建议优化:去掉最外层盒子设置的红色边框,效果会更美观,示例:

http://img.mukewang.com/climg/60794a1609c850b605430233.jpg

祝学习愉快~

0

0 学习 · 15276 问题

查看课程