2-11编程练习

2-11编程练习

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>三列布局</title>
<style type="text/css">
body{
padding: 0;
margin: 0;
}
.head{
width: 100%;
height: 100px;
background-color: black;
position: fixed;
top: 0;
min-width: 1100px;
}
.logo{
 
float: left;
cursor: pointer;
}
.nav-bar{
float: right;
min-width: 750px;
height: 100px;
left: 0;
text-align: center;
line-height: 100px;
 
}
.navlist{
color: white;
float: left;
width: 150px;
height: 100px;
cursor: pointer;
}
    .container{
     width: 100%;
     height: 750px;
     margin-top: 100px;
     margin-bottom: 100px;
 
    }
    .left{
     width: 40%;
     height: 100%;
     background: #1a5acd;
     float: left;
    }
    .mid{
     width: 40%;
     height:100%;
     background: #5880f9;
     float: left;
    }
    .right{
     width: 20%;
     height: 100%;
     background: blue;
     float: right;
     border-left: solid red 2px;
text-align: center;
line-height: 750px;
 
    }
    .right-bar{
     width: 153px;
     height: 390px;
      
      
    }
 
   .foot{
   float: left;
   width: 100%;
   height: 100px;
   background-color: black;
   position: fixed;
   bottom: 0;
    
 
   }
   .foot-bar{
   float: left;
   width: 800px;
   height: 100px;
   position: absolute;
   left: 50%;
   margin-left: -400px;
    
   }
   .footlist{
   float: left;
   width: 160px;
   height: 100px;
   text-align: center;
   line-height: 100px;
   color: white;
   cursor: pointer;
 
   }
</style>
</head>
<body>
<div class="head">
<div class="logo"><img src="http://img1.sycdn.imooc.com/climg//58c0d2d900016ce303000100.png"></div>
<div class="nav-bar">
<div class="navlist">课程</div>
<div class="navlist">职业路径</div>
<div class="navlist">实战</div>
<div class="navlist">猿问</div>
<div class="navlist">手记</div>
</div>
</div>
<div class="container">
<div class="left">页面左侧</div>
<div class="mid">页面右侧</div>
<div class="right">
<div class="right-bar">
<h2>登录</h2>
<p><input type="text" name="username" placeholder="请输入登录账户"></p>
<p><input type="password" name="password" placeholder="输入密码"></p>
<p><input type="submit" name="submit" value="登录"></p>
</div>
</div>
</div>
<div class="foot">
<div class="foot-bar">
<div class="footlist">网站首页</div>
<div class="footlist">企业合作</div>
<div class="footlist">人才招聘</div>
<div class="footlist">联系我们</div>
<div class="footlist">常见问题</div>
<div class="footlist">友情链接</div>
</div>
</div>
</body>
</html>

在.right里,添加border-left,.right就会不知道挤到哪去了。

然后怎么才能让.right-bar居中啊。我写居中也是不知道跳到哪去了。

正在回答

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

2回答

第一个问题:

一、根据课程学习,使用 left、mid、right 的宽度 使用固定的宽度,来设置。或者如使用% ,边框使用 div 来代替,设置其宽度为1%。方法不唯一,可以多实践。

二、这种方法进阶课程才会讲解知识,现在可以作为了解和扩充。

注意 边框(border),我们不能用百分比去设置border边框的大小,只能用一个固定的值。因为如果所有的都使用百分比设置,那么我们留给border的空间也会是一个变化的值,也就是说当页面宽度变化时,border的值也会跟着变化,这样是有问题的。这使得我们没有办法去决定我们边框的宽度!

解决方案:

设置CSS的box-sizing属性值为“border-box”(可以网上查阅相关知识),这样就会把borders和padding全都包含在定义的宽高里面。即给 .right 添加box-sizing: border-box; 样式。

第二个问题:

根据上次建议,“把.right-bar 整个去掉,同时将 .right 中的 line-height: 750px; 去掉。”就可以居中了。

希望对你有帮助,祝学习愉快。如解决你的疑惑,欢迎采纳。

  • 莨菽菽 提问者 #1
    非常感谢!
    2017-06-02 15:14:17
小于飞飞 2017-06-01 10:12:42

你好,关于问题解决如下:

  1. right 没显示,因为被挤到下一行了(left、mid、right 的宽度已经 100% , 又给right 添加加了 border ,所以宽度超出100%,被挤到下面),修改建议,调整相应块宽度,给border 留出相应的宽度。

  2. 把.right-bar  去掉,因为限定了 登录的 宽度太小,所以居中不起作用,同时同时将 .right 中的 line-height: 750px; 去掉。

希望对你有帮助,祝学习愉快。如解决你的疑惑,欢迎采纳。

  • 提问者 莨菽菽 #1
    left、mid、right 的宽度已经 100%留出1%后,如果想让border完全填充留出的1%要怎么写呢?因为其他的都是百分比设置,不知道留出的1%具体的大小 2.把right-bar去掉之后怎么让登陆水平垂直居中呢?
    2017-06-01 11:14:21
  • 小于飞飞 回复 提问者 莨菽菽 #2
    已回答,祝学习愉快。
    2017-06-02 10:41:03
问题已解决,确定采纳
还有疑问,暂不采纳

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

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

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

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

帮助反馈 APP下载

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

公众号

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

在线咨询

领取优惠

免费试听

领取大纲

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