麻烦老师检查代码
来源:4-6 自由编程
烟波皓渺
2021-02-20 15:40:49
麻烦老师检查一下代码,看还有哪里可以优化的。
另外我有几个疑惑
为什么有时候用 margin:0 auto;不能实现居中,比如最下面的按钮 我用这个方法就不能,我就只能硬算像素了
文本框里提示文字怎么设置边距,现在顶格有点丑
相关代码:
html
相关代码:
<section class="banner">
<img src="images/banner3.jpg">
<div class="mask"></div>
<div class="form">
<input class="comp tx" type="text" placeholder="your Name">
<input class="comp tx" type="text" placeholder="your Phone">
<input class="comp tx" type="text" placeholder="your Email">
<textarea class="comp txar" placeholder="Write Your Comment Here"></textarea>
<input class="comp btn" type="button" value="SEND MESSAGE">
</div>
</section>
css
/* banner区域 */
.banner{
position: relative;
width:100%;
height:600px;
overflow: hidden;
}
.banner img{
position: absolute;
width:100%;
height:600px;
}
.banner .mask{
position: absolute;
width:100%;
height:600px;
background:rgba(0, 0, 0, 0.5)
}
.banner .form{
position: absolute;
width:504px;
height:312px;
margin-top: 100px;
left:50%;
margin-left:-252px;
}
.banner .form .comp{
display:block;
margin-bottom: 25px;
}
.banner .form .tx{
background: none;
border:1px solid #808080;
width:502px;
height:38px;
}
.banner .form .txar{
background: none;
border:1px solid #808080;
width:502px;
height:108px;
}
.banner .form .btn{
position: absolute;
background: none;
border:1px solid #808080;
width:198px;
height:38px;
color: #808080;
left:251px;
margin-left:-99px;
}
1回答
同学你好,代码布局以及实现效果可以,不需要修改了。
针对提问解答如下:
1、按钮默认为行内块元素,不能使用margin:0 auto;实现居中;如果设置了absolute定位,margin:0 auto;也是无效的。但是代码中已经按钮设置为块元素

就可以用这种方式设置,如下

2、文本框里提示文字可以通过缩进样式来设置间距,如下

祝学习愉快!
相似问题