您好,請問幾個問題。 1.為什麼我使用position:relative,網頁會出現很大的空白,我該如何解決。 2.使用絕對位置,我該如何讓我的網頁隨著比例縮放。
問題1 :
問題2:
這是網頁全開的時候
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>佳加安全帽</title>
<link rel = "stylesheet" href = "style.css">
</head>
<body class = "page">
<div class = "navbar">
<div class="container">
<div class = "logo">
<a href = "#"><img src = "jiajia.jpg"/></a>
</div>
<div class="menu">
<ul class="choose">
<li><a href = "">所有商品</a></li>
<li><a href = "">特價商品</a></li>
<li><a href = "">安全帽</a></li>
<li><a href = "">藍芽耳機</a></li>
<li><a href = "">裝備衣物</a></li>
<li><a href = "">配件</a></li>
<li><a href = "">包包</a></li>
</ul>
</div>
<div class="user">
<ul>
<li><a href = "">Log in 登入</a></li>
<li>|</li>
<li><a href = "">Sign up 註冊</a></li>
</ul>
</div>
</div>
</div>
<div class="background">
<div class="content">
<h1>在危險的世界中,給你多一份安全</h1>
</br>
</br>
<p>留下您的email,獲得新商品及最新優惠資訊</p>
</br>
<input type= "email" name = "email" value = "Your email">
</br>
<input class="submit" type = "submit" name= "submit" value = "訂閱">
</div>
</div>
</body>
</html>
CSS: ``` *{ margin: 0px; padding: 0px; list-style-type: none; text-decoration: none; }
.navbar{ background-color: #272727; height: 50px; width: 100%; }
.logo img{ height: 50px; }
.menu{ position: relative; top: -50px; line-height: 45px; left: 500px; }
.menu li{ float: left; }
.menu a{ color: #D9B300; display: block; padding: 0 10px; }
.menu a:hover{ background-color: #D9B300; color: #272727; }
.user{ position: relative; top: -50px; left: 800px; line-height: 45px; }
.user li{ float: left; color: #D9B300; }
.user a{ color: #D9B300; display: block; padding: 0 10px; }
.user a:hover{ background-color: #D9B300; color: #272727; }
h1{ color: white; }
p{ color: white; }
.background{ background-image: url("motor.jpg"); background-size: cover; background-repeat: no-repeat; height: 660px; text-align: center; }
.content input{ width: 400px; height: 40px; }
.content h1{ font-size: 40px; }
.content p{ font-size: 20px; }
.content{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.submit{ font-weight: bold; font-size: 20px; background-color: #D9B300; color: #272727; border-radius: 10px; border: 0px; }
.submit:hover{ background-color: #272727; color: #D9B300; }
在研究排版的時候,應該要一小塊一小塊研究
舉例來說,把這塊整個刪掉
<div class="user">
<ul>
<li><a href = "">Log in 登入</a></li>
<li>|</li>
<li><a href = "">Sign up 註冊</a></li>
</ul>
</div>
就會發現,其實版面算整齊,並沒有太大問題
所以要從這一塊的寫法,開始研究、改寫
為了讓「登入、註冊」往右邊靠,你這樣寫 css
這種寫法,在螢幕寬度少於 800px 時,一定會破版,光是這邊的寫法就要先改