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居中啊。我写居中也是不知道跳到哪去了。
正在回答
第一个问题:
一、根据课程学习,使用 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; 去掉。”就可以居中了。
希望对你有帮助,祝学习愉快。如解决你的疑惑,欢迎采纳。
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧