<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>/* 整个浏览器页面 */html,body {background-color: #00005d;height: 100%;margin: 0;}.page {/* 定宽 */width: 1100px;margin-top: 0;margin-bottom: 0;margin-right: auto;margin-left: auto;/* margin:0,auto; 不支持margin的多个属性值,F12显示属性值无效*/height: 100%;}header {background-color: #869dc7;height: 150px;/* 原图像素254*150 */background-image: url(images/lighthouselogo.jpg);background-repeat: no-repeat;}h1 {color: #00005d;font-size: 55px;font-family: Verdana, Geneva, Tahoma, sans-serif;font-weight: bold;text-align: center;line-height: 150px;margin: 0;}aside {background-color: #b3c7e6;width: 180px;margin: 0;/* height: 620px; */height: calc(100% - 150px - 50px);float: left;}main {background-color: white;width: 920px;/* height: 620px; */height: calc(100% - 150px - 50px);float: right;}h2 {color: #90a5cb;padding-top: 10px;padding-left: 20px;font-weight: bold;font-size: 25px;}main p {padding-left: 20px;font-family: Verdana, Geneva, Tahoma, sans-serif;font-size: 18px;}footer {background-color: #869dc7;height: 50px;/* 如果不加clear属性,会受到中间元素float影响移动到上边 */clear: both;/* 水平居中 */text-align: center;/* 无法利用margin:0,auto;属性 借助line-height=height */line-height: 50px;font-family: Arial, Helvetica, sans-serif;font-size: 14px;color: #00005d;}</style>
</head><body><section class="page"><header><h1>Lighthouse Island Bistro</h1></header><!-- <div class="middle"> --><aside><ulstyle="list-style: none;font-family: Arial, Helvetica, sans-serif;font-weight: bold;color: white;font-size: 20px;"><li style="color: #eae9ea;">Home</li><li>Menu</li><li>Directions</li><li>Contact</li></ul></aside><main><div style="float: right;clear: both;"><img src="images/lighthouseisland.jpg" style="padding: 20px;padding-top:40px;height: 400px;"></div><h2 style="padding-top: 20px;">Locally Roasted Free-Trade Coffee</h2><p>Indulge in the aroma of freshly ground roast coffee. Specialty drinks are available hot or cold.</p><h2>Specialty Pastries</h2><p>Enjoy a selection of our fresh-baked, organic pastries, including fresh-fruit muffins, scones,croissants, and cinammon rolls.</p><h2>Lunchtime is Anytime</h2><p>Savor delicious wraps and sandwiches on hearty, whole-grain breads with locally-grown salad, fruit,and vegetables.</p><h2>Panoramic View</h2><p>Take in some scenery! The top of our lighthouse offers a panoramic view of the countryside.Challenge your friends to climb our 100-stair tower.</p></main><!-- </div> --><footer>Copyright © 2021</footer></section>
</body></html>
定宽浮动布局,设计页面在整个浏览器页面水平居中位置,浏览器页面缩小时,仍水平居中,出现水平滚动条,显示不到的页面内容可以通过滚动条调节。
已知header高度、footer高度,使得aside的高度处于页面中间,并且不出现垂直滚动条?
cal(相对高度百分比 - 同级别元素高度1 - 同级别元素高度2);
相对高度100%--是相对父元素的高度,要求向上追溯父元素的时候有一个确切的数值(html的高度设置为100%时就是整个浏览器页面高度);另外还需要注意margin等高度,相对高度是相对父元素内容区的高度,所以要排除元素margin、padding等高度影响。