老师,能帮我看一下目前代码又什么可以改进的吗,有些地方和效果图不一样。

老师,能帮我看一下目前代码又什么可以改进的吗,有些地方和效果图不一样。

html:

<!DOCTYPE html>

<html>

<head>

<title></title>

<link rel="stylesheet" type="text/css" href="css/index.css">

</head>

<body>

<div class="header">

<div class="top">

<a href="#"><img src="images/logo.png" alt="logo"></a>

</div>

<div class="nav">

<ul>

<li><a href="#">HOME</a></li>

<li><a href="#">ABOUT</a></li>

<li><a href="#">GALLERY</a></li>

<li><a href="#">FACULTY</a></li>

<li><a href="#">EVENTS</a></li>

<li><a href="#">CONTACT</a></li>

</ul>

</div>

</div>

<div class="main">

<div class="top">

<img src="images/banner3.jpg" alt="banner">

</div>

<div class="topLayer">


</div>

<div class="topLayer-top">

<form>

<input class="a1" type="text" id="" name="" placeholder="your Name"/><br>

<input class="a1" type="text" id="" name="" placeholder="your Phone"/><br>

<input class="a1" type="text" id="" name="" placeholder="your Email"/><br>

<input class="a2" type="text" id="" name="" placeholder="Writer Your Comment Here"/><br>

<input type="button" value="SEND MESSAGE">

</form>

</div>

<div class="middle"></div>

<div class="bottom"></div>

</div>

<div class="footer">

</div>

</body>

</html>


css:

*{

margin:0;

padding:0;

}

.header{

width:100%;

height: 70px;

background-color:#07cbc9;

}

.header .top{

float:left;

padding-left: 130px;

padding-top:15px;

}

.header .top img{

width:200px;

height:40px;

}

.header .nav{

float:right;

}

.header .nav ul{

margin-right:70px;

}

.header .nav ul li{

float:left;

padding-left:20px;

padding-right:16px;

box-sizing: border-box;

list-style: none;

height:70px;

line-height: 70px;

font-size:13px;

font-weight: bold;

color:#ffffff;

}

.header .nav ul li:hover{

background-color: #000;

}

.header .nav ul a:link{

text-decoration: none;

color: white;

}

.main .top{

width:100%;

height:500px;

}

.main .top img{

width:100%;

height:500px;

}

.main .topLayer{

width:100%;

height: 500px;

top:70px;

left:0px;

position: absolute;

background-color: #000;

opacity: 0.5;

}

.main .topLayer-top{

width:500px;

height:350px;

top:320px;

right: 50%;

position: absolute;

margin-top:-175px;

margin-right: -250px;

z-index: 2;

}

.main .topLayer-top .a1{

width:400px;

height:30px;

margin-top:20px;

margin-left:50px;

}

.main .topLayer-top .a2{

width:400px;

height:100px;

margin-top:20px;

margin-left: 50px

}

.main .topLayer-top input{

outline: none;

background: transparent;

}

input::-webkit-input-placeholder{

color: white;

}

.main .topLayer-top input[type="text"]{

color: white;

border: 1px solid white;

}

.main .topLayer-top input[type="button"]{

width:100px;

height:30px;

margin-top:25px;

margin-left:200px;

font-size: 10px;

color:white;

border: 1px solid white;

}

.main .topLayer-top input[type="text"]:hover{

border-color: #07cbc9;

}

.main .topLayer-top input[type="button"]:hover{

border:none;

background-color: #07cbc9;

}



正在回答

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

7回答

同学你好!

这一次整体的布局完成的很好,很清晰,接下来我们一起来分析一下定位的问题:

  1. 首先banner区上面的表单和遮罩层都需要使用绝对定位来定位到div.banner上面,根据之前所学的知识,如果子元素要相对于父元素定位,父元素应该设置为相对定位,子元素设置为绝对定位。因此在这里我们给父元素设置相对定位,然后子元素相对于父元素的左上角位置进行定位。修改后的代码:

    将div.banner设置为绝对定位

    http://img1.sycdn.imooc.com//climg/5d6f895800014e7502560092.jpg

    由于遮罩层是相对于父元素进行定位,所以这里将top设置为0即可

    http://img1.sycdn.imooc.com//climg/5d6f89bf0001800003490167.jpg

  2. 通过上面的设置布局已经可以很好地展现了,接下来可以将form表单在div.banner上向上移动一点会更好,因此减小top的值

    http://img1.sycdn.imooc.com//climg/5d6f8a3f0001306802580160.jpg

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~


提问者 精慕门618366 2019-09-04 17:31:53

HTML:


<!DOCTYPE html>

<html>

<head>

<title></title>

<link rel="stylesheet" type="text/css" href="css/index.css">

</head>

<body>

<div class="header">

<div class="top">

<a href="#"><img src="images/logo.png" alt="logo"></a>

</div>

<div class="nav">

<ul>

<li><a href="#">HOME</a></li>

<li><a href="#">ABOUT</a></li>

<li><a href="#">GALLERY</a></li>

<li><a href="#">FACULTY</a></li>

<li><a href="#">EVENTS</a></li>

<li><a href="#">CONTACT</a></li>

</ul>

</div>

</div>

<div class="banner">

<div class="top">

<img src="images/banner3.jpg" alt="banner">

</div>

<div class="topLayer">


</div>

<div class="topLayer-top">

<form>

<input class="a1" type="text" id="" name="" placeholder="your Name"/><br>

<input class="a1" type="text" id="" name="" placeholder="your Phone"/><br>

<input class="a1" type="text" id="" name="" placeholder="your Email"/><br>

<input class="a2" type="text" id="" name="" placeholder="Writer Your Comment Here"/><br>

<input type="button" value="SEND MESSAGE">

</form>

</div>

</div>

<div class="ABOUT">

<div class="a-top">

<div class="com1">

ABOUT<br>

</div>

<div class="com2">


</div>

<div class="com3">

Lorem Ipsum is simply text of the printing and typesetting<br>industy.Lorem Ipsum has been the industry's standard dummy<br>text ever since the 1500s.

</div>

</div>

</div>


</body>

</html>

CSS:

*{

margin:0;

padding:0;

}

.header{

width:100%;

height: 70px;

top:0px;

left:0px;

position:fixed;

background-color:#07cbc9;

z-index: 3;

}

.header .top{

float:left;

padding-left: 130px;

padding-top:15px;

}

.header .top img{

width:200px;

height:40px;

}

.header .nav{

float:right;

}

.header .nav ul{

margin-right:70px;

}

.header .nav ul li{

float:left;

padding-left:20px;

padding-right:16px;

box-sizing: border-box;

list-style: none;

height:70px;

line-height: 70px;

font-size:13px;

font-weight: bold;

color:#ffffff;

}

.header .nav ul li:hover{

background-color: #000;

}

.header .nav ul a{

text-decoration: none;

color: white;

}

.banner{

top:70px;

position: absolute;

}

.banner .top{

width:100%;

height:500px;

}

.banner .top img{

width:100%;

height:500px;

}

.banner .topLayer{

width:100%;

height: 500px;

top:70px;

left:0px;

position: absolute;

background-color: #000;

opacity: 0.5;

}

.banner .topLayer-top{

width:500px;

height:350px;

top:320px;

right: 50%;

position: absolute;

margin-top:-175px;

margin-right: -250px;

z-index: 2;

}

.banner .topLayer-top .a1{

width:400px;

height:30px;

margin-top:20px;

margin-left:50px;

}

.banner .topLayer-top .a2{

width:400px;

height:100px;

margin-top:20px;

margin-left: 50px

}

.banner .topLayer-top input{

outline: none;

background: transparent;

}

input::-webkit-input-placeholder{

color: white;

opacity: 0.5;

}

.banner .topLayer-top input[type="text"]{

color: white;

border: 1px solid white;

}

.banner .topLayer-top input[type="button"]{

width:100px;

height:30px;

margin-top:25px;

margin-left:200px;

font-size: 10px;

color:white;

border: 1px solid white;

opacity: 0.8;

}

.banner .topLayer-top input[type="text"]:hover{

border-color: #07cbc9;

}

.banner .topLayer-top input[type="button"]:hover{

border:none;

background-color: #07cbc9;

}


.ABOUT .a-top{

width:100%;

}

.ABOUT .a-top .com1{

font-size: 40px;

text-align: center;

font-weight: bold;

margin-top: 100px;

}

.ABOUT .a-top .com2{

background-color:#07cbc9;

width: 40px;

height: 2px;

margin:15px auto;

}

.ABOUT .a-top .com3{

font-size:15px;

text-align: center;

color:gray;

}



  • 提问者 精慕门618366 #1
    老师,我知道在img添加定位就会好使,但是我对整个bannerdiv定位就会出错。
    2019-09-04 17:33:30
提问者 精慕门618366 2019-09-04 17:13:15

这是截图:

http://img1.sycdn.imooc.com//climg/5d6f801f0001772018960807.jpg

提问者 精慕门618366 2019-09-04 17:12:39

老师我按照你说的重新分了块,还有你说图片会因为fixed上移,所以设置了img的绝对定位,我直接定位那个包含banner和表单的div为什么会这样呢?不可以直接定位那个大的div吗?ABOUT这几个字母也消失了。

spacer.gif

  • 同学重新分块之后,有些样式可能需要改变,同学贴一下最新的代码,老师帮同学看一些,给同学一些意见。祝学习愉快~
    2019-09-04 17:18:42
好帮手慕柯南 2019-09-04 16:48:29

同学你好!

1.首先来看一下同学的布局,同学的about是在banner区上面的表单下:

http://img1.sycdn.imooc.com//climg/5d6f794100013ed715460987.jpg

因此同学的margin-top设置的太小了,设置大一点就可以。

2.这里老师给同学一个建议:同学将顶部,banner区,about区等,都写为并列的div,然后在填充每一个div中具体的元素,这样布局会更好,同学那样按顺序写下来,如果随着页面的元素增多布局会换乱,不太好调整。同学按块分一下会更好。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

提问者 精慕门618366 2019-09-04 16:21:27

老师,那我在布局ABOUT几个字母时为什么会这样,我明明用了margin-top:40px;

http://img1.sycdn.imooc.com//climg/5d6f73fc00011c3f19190865.jpg

好帮手慕柯南 2019-09-04 15:24:08

同学你好!

整体完整还是不错,有一些小细节需要注意一下

  1. 导航栏需要固定在顶部,所以同学可以使用固定定位来是实现:

    http://img1.sycdn.imooc.com//climg/5d6f65960001254204470339.jpg

  2. 设置了定位banner区的布局会有一点变化,给图片一个绝对定位,并设置top即可

    http://img1.sycdn.imooc.com//climg/5d6f65e00001aa0b02300131.jpg

  3. 同学可以将banner区遮罩层的透明度,降低一些,改为0.3,可以将form表单中的边框宽度设置为2px,边框以及input框中的字体的颜色设置为gray,会更好看一点。

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~

  

  • 提问者 精慕门618366 #1
    老师,给banner添加绝对定位是因为fixed脱离了绝对定位?
    2019-09-04 15:59:20
  • 好帮手慕柯南 回复 提问者 精慕门618366 #2
    同学是因为给顶部设置了固定定位,所以导致图片上移了,所以同学给banner区的图片也设置一个定位,并设置一个top,就可以解决了这个问题。祝学习愉快~
    2019-09-04 16:01:48
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10204    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
微信客服

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

帮助反馈 APP下载

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

公众号

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

在线咨询

领取优惠

免费试听

领取大纲

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