麻烦老师帮忙看下,代码正确吗。谢谢
来源:4-6 自由编程
叫我丽红
2021-04-16 15:39:10
相关截图:
相关代码:
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标签自带间距,导致遮罩层图片下方之间存在间隙,效果不美观。
建议:给图片添加display:block;属性消除间隙。
2、由于内层元素边框也占据页面宽度,导致实际宽度超出了外层盒子的宽度,导致表单整体居中存在误差。如下图所示:
建议:调整form标签的宽高,让其刚好包裹子元素。
3、使用background:none;属性去掉表单项的背景,效果更美观
4、样式相同的代码可以书写在一起,简化代码书写,示例:
5、建议优化:去掉最外层盒子设置的红色边框,效果会更美观,示例:
祝学习愉快~
相似问题
回答 1
回答 1
回答 1
回答 1
回答 1