2017-04-15 189 views
0

下面是我的css文件的代碼。由於增加字體大小,標題不斷下降?

@-webkit-keyframes change { 
    83.3%,95.96% {transform:translate3d(0,-10%,0);} 
} 

body { 
    background-color: #3A457C; 
} 

.nav ul { 
    list-style: none; 
    background-color: #444; 
    text-align: center; 
    padding: 0; 
    margin: 0; 
} 
.nav li { 
    font-family: 'Oswald', sans-serif; 
    font-size: 1.2em; 
    line-height: 40px; 
    height: 40px; 
    border-bottom: 1px solid #888; 
} 

.nav a { 
    text-decoration: none; 
    color: #fff; 
    display: block; 
    transition: .3s background-color; 
} 

.nav a:hover { 
    background-color: #fff; 
    color: #444; 
} 

.nav a.active { 
    background-color: #fff; 
    color: #444; 
    cursor: default; 
} 

@media screen and (min-width: 600px) { 
    .nav li { 
    width: 120px; 
    border-bottom: none; 
    height: 50px; 
    line-height: 50px; 
    font-size: 1.4em; 
    } 

    /* Option 1 - Display Inline */ 
    .nav li { 
    display: inline-block; 
    margin-right: -4px; 
    } 

    /* Options 2 - Float 
    .nav li { 
    float: left; 
    } 
    .nav ul { 
    overflow: auto; 
    width: 600px; 
    margin: 0 auto; 
    } 
    .nav { 
    background-color: #444; 
    } 
    */ 
} 

h1, h2, p { 
    font-family: 'Ubuntu', sans-serif; 
    color: white; 
} 

h1 { 
    font-size: 150px; 
    text-align: center; 
    -webkit-animation-name: change; 
    animation-duration: .5s; 
    line-height: 300px; 
} 

h2 { 
    font-size: 50px; 
    text-align: center; 
} 

p { 
    margin-left: 500px; 
    margin-right: 500px; 
    font-size: 22px; 
} 

.header { 
    cursor: pointer; 
    background-image: url("http://www.lib.usf.edu/tutoring/files/2015/08/Tutoring-main-banner-02.png"); 
    background-position: center center; 
    height: 325px; 
    line-height:0px; 
} 

/* 
#left { 
    position: fixed; 
    top: 392px; 
    left: 0px; 
    width: 25%; 
    height: 100%; 
    background-color: white; 
    z-index: 1; 
} 

#top { 
    position: fixed; 
    width: 100%; 
    top: 0px; 
    left: 0px; 
    right: 0px; 
    height:8%; 
    background-color: white; 
} 

#hardLeft { 
    position: fixed; 
    width: .35%; 
    top:0px; 
    left: 0px; 
    right: 0px; 
    height: 100%; 
    background-color: white; 
} 

#hardRight { 
    position: right-side; 
    background-color: white; 
}*/ 

而低於現在的問題是HTML文件

<!DOCTYPE html> 
<html> 
    <div class="nav"> 
     <ul> 
     <li class = "home"> <a class = "active" href = "J:\Website1\html\home\index.html">Home</a></li> 
     <li class = "about"> <a href = "J:\Website1\html\about\about.html">About</a></li> 
     </ul> 
    </div> 

    <head> 
     <title>Home - Tutor</title> 
     <link href = "J:\Website1\css\indexStyle.css" type = "text/css" rel = "stylesheet"/> 
     <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> 
    </head> 

    <body> 
     <div id = "background" onclick = 'window.location.href="J:\\Website1\\html\\home\\index.html"'> 
      <div class = "header"> 
       <h1>Trouble? Tutor.</h1> 
      </div> 
     </div> 
     <h2>About</h2> 
     <p>My name is John Antonio Anselmo, and I currently go to Battlefield High School in Haymarket, Virginia. I'm currently enlisted in Battlefield's IT Program with a plan to study Cyber Security, Computer Science, 
     and Business at the Massachusetts Institute of Technology (MIT), or Virginia Tech (VT). I have exceeded in the maths and sciences since a very young age, and continue to.</p> 
    </body> 
</html> 

的問題是代碼,因爲我一直在增加H1的字體大小,標題保持從的頂部越來越遠頁面,我想保持h1字體大小爲150px,但在頁面頂部有標題。它看起來像this,但我想它看起來像this,除了我希望h1(麻煩?導師)爲150px。

回答

0

添加margin: 0;並將line-height更改爲1margin正在創建與背景的差距,而line-height正在向下移動文本。

@-webkit-keyframes change { 
 
    83.3%,95.96% {transform:translate3d(0,-10%,0);} 
 
} 
 

 
body { 
 
    background-color: #3A457C; 
 
} 
 

 
.nav ul { 
 
    list-style: none; 
 
    background-color: #444; 
 
    text-align: center; 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 
.nav li { 
 
    font-family: 'Oswald', sans-serif; 
 
    font-size: 1.2em; 
 
    line-height: 40px; 
 
    height: 40px; 
 
    border-bottom: 1px solid #888; 
 
} 
 

 
.nav a { 
 
    text-decoration: none; 
 
    color: #fff; 
 
    display: block; 
 
    transition: .3s background-color; 
 
} 
 

 
.nav a:hover { 
 
    background-color: #fff; 
 
    color: #444; 
 
} 
 

 
.nav a.active { 
 
    background-color: #fff; 
 
    color: #444; 
 
    cursor: default; 
 
} 
 

 
@media screen and (min-width: 600px) { 
 
    .nav li { 
 
    width: 120px; 
 
    border-bottom: none; 
 
    height: 50px; 
 
    line-height: 50px; 
 
    font-size: 1.4em; 
 
    } 
 

 
    /* Option 1 - Display Inline */ 
 
    .nav li { 
 
    display: inline-block; 
 
    margin-right: -4px; 
 
    } 
 

 
    /* Options 2 - Float 
 
    .nav li { 
 
    float: left; 
 
    } 
 
    .nav ul { 
 
    overflow: auto; 
 
    width: 600px; 
 
    margin: 0 auto; 
 
    } 
 
    .nav { 
 
    background-color: #444; 
 
    } 
 
    */ 
 
} 
 

 
h1, h2, p { 
 
    font-family: 'Ubuntu', sans-serif; 
 
    color: white; 
 
} 
 

 
h1 { 
 
    font-size:150px; 
 
    text-align: center; 
 
    -webkit-animation-name: change; 
 
    animation-duration: .5s; 
 
    line-height: 1; 
 
    margin: 0; 
 
} 
 

 
h2 { 
 
    font-size: 50px; 
 
    text-align: center; 
 
} 
 

 
p { 
 
    margin-left: 500px; 
 
    margin-right: 500px; 
 
    font-size: 22px; 
 
} 
 

 
.header { 
 
    cursor: pointer; 
 
    background-image: url("http://www.lib.usf.edu/tutoring/files/2015/08/Tutoring-main-banner-02.png"); 
 
    background-position: center center; 
 
    height: 325px; 
 
    line-height:0px; 
 
}
<html> 
 
    <div class="nav"> 
 
     <ul> 
 
     <li class = "home"> <a class = "active" href = "J:\Website1\html\home\index.html">Home</a></li> 
 
     <li class = "about"> <a href = "J:\Website1\html\about\about.html">About</a></li> 
 
     </ul> 
 
    </div> 
 

 
    <head> 
 
     <title>Home - Tutor</title> 
 
     <link href = "J:\Website1\css\indexStyle.css" type = "text/css" rel = "stylesheet"/> 
 
     <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> 
 
    </head> 
 

 
    <body> 
 
     <div id = "background" onclick = 'window.location.href="J:\\Website1\\html\\home\\index.html"'> 
 
      <div class = "header"> 
 
       <h1>Trouble? Tutor.</h1> 
 
      </div> 
 
     </div> 
 
     <h2>About</h2> 
 
     <p>My name is John Antonio Anselmo, and I currently go to Battlefield High School in Haymarket, Virginia. I'm currently enlisted in Battlefield's IT Program with a plan to study Cyber Security, Computer Science, 
 
     and Business at the Massachusetts Institute of Technology (MIT), or Virginia Tech (VT). I have exceeded in the maths and sciences since a very young age, and continue to.</p> 
 
    </body> 
 
</html>

+1

THANK YOU!我感到很愚蠢,錯過了這一點。我會確保將來記住這一點。 –

0

那空空間由H1標籤的默認保證金所致。 所以加上margin:0;對H1的風格

順便說一句,你的html代碼是奇怪的。

HTML文檔應該是這樣的。

<html> 
     <head></head> <!-- Header for html contains meta, title, link, etc.. --> 
     <body></body> <!-- Actual contents which would be printed on screen --> 
</html> 

所以你的HTML會更好。

<!DOCTYPE html> 

<head> 
    <title>Home - Tutor</title> 
    <link href = "test.css" type = "text/css" rel = "stylesheet"/> 
    <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> 
</head> 

<body> 
    <div class="nav"> 
    <ul> 
     <li class = "home"> <a class = "active" href = "J:\Website1\html\home\index.html">Home</a></li> 
     <li class = "about"> <a href = "J:\Website1\html\about\about.html">About</a></li> 
    </ul> 
    </div> 
    <div id = "background" onclick = 'window.location.href="J:\\Website1\\html\\home\\index.html"'> 
     <div class = "header"> 
      <h1>Trouble? Tutor.</h1> 
     </div> 
    </div> 
    <h2>About</h2> 
    <p>My name is John Antonio Anselmo, and I currently go to Battlefield High School in Haymarket, Virginia. I'm currently enlisted in Battlefield's IT Program with a plan to study Cyber Security, Computer Science, 
    and Business at the Massachusetts Institute of Technology (MIT), or Virginia Tech (VT). I have exceeded in the maths and sciences since a very young age, and continue to.</p> 
</body>