1
0
mirror of https://github.com/Daotin/Web.git synced 2024-10-30 04:24:45 +08:00
Web-main/QF Phase 1/06-一屏网页.md
2018-10-21 17:31:04 +08:00

220 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

一屏网页
需要在css最开始加入下面核心代码
```html
html,body {
height:100%;
}
```
示例代码1
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="./css/base.css">
<style>
html,
body {
height: 100%;
}
.aic {
height: 90%;
background-color: pink;
}
.menu {
height: 10%;
background-color: brown;
}
.menu ul {
width: 80%;
height: 100%;
background-color: #ff0;
margin: 0 auto;
}
.menu li {
float: left;
height: 100%;
width: 12.5%;
position: relative;
}
.menu a {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<div class="menu">
<ul>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
</ul>
</div>
<div class="aic"></div>
</body>
</html>
```
![](images/2.png)
上面这个不好li的宽度设置百分比li的个数确定了。
示例代码2
下面的代码将ul的高度确定比如设置为文字的高度而不是百分比高度然后将ul定位后li就自动定位了然后设置li的margin即可。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="./css/base.css">
<style>
html,
body {
height: 100%;
}
.aic {
height: 90%;
background-color: pink;
}
.menu {
height: 10%;
background-color: brown;
position: relative;
}
.menu ul {
width: 100%;
height: 30px;
line-height: 30px;
text-align: center;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
.menu li {
display: inline-block;
margin: 0 10px;
}
</style>
</head>
<body>
<div class="menu">
<ul>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
<li>
<a href="javascript:;">首页</a>
</li>
</ul>
</div>
<div class="aic"></div>
</body>
</html>
```
![](images/3.png)
20181012
**上面的ul宽度是不确定的而li需要一行显示并且居中显示**
**那么就设置ultext-align:center; 设置 lidisplay:inline-block.**
**此时有个问题就是 li 之间有间距解决办法就是设置ulfont-size:0;**
vertical-align:top;是没法解决的,它解决的是上下的问题。