2017-10-13 24 views
1

Ich versuche, die Nav-Absätze zu zentrieren, wird es nicht zentrieren. Ich habe jetzt viele Dinge ausprobiert, kann aber das Ergebnis nicht finden.Kann nicht zentrieren

Hier ist meine CSS:

header { 
 
    background: #444444; 
 
    z-index: 100; 
 
    transition: height 600ms 0s ease; 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
} 
 

 
#head { 
 
    font-family: quicksand; 
 
    text-align: center; 
 
} 
 

 
nav { 
 
    background: #333333; 
 
    position: fixed; 
 
    top: 82px; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
} 
 

 
.navs { 
 
    font-family: quicksand; 
 
    font-size: 18px; 
 
    text-align: center; 
 
    display: inline-block; 
 
} 
 

 
a, 
 
a:link, 
 
a:visited, 
 
a:hover { 
 
    text-decoration: none; 
 
    color: white; 
 
    font-family: quicksand 
 
} 
 

 
#left { 
 
    margin-right: 15px; 
 
} 
 

 
Here is my HTML :
<header> 
 
    <h1 id="head">Resume - Mathias Nicolajsen</h1> 
 
</header> 
 
<nav> 
 
    <a href="diagonaler.html"><strong><p class="navs" id="left">Projecter</p></strong></a> 
 
    <strong><p class="navs">Omkring mig</p></strong> 
 
</nav> 
 
<p>Lavet af Mathias Nicolajsen</p>

Wie kann ich das tun?

+0

haben Sie versucht ** margin: 0 auto ** mit ** float: keine ** – LSKhan

+0

können Sie bitte teilen Sie html Snippet – LSKhan

Antwort

0

Gerade text-align: center; zu nav { } fügen Sie die Elemente hinzuzufügen, zu zentrieren.

0

header { 
 
    background: #444444; 
 
    z-index: 100; 
 
    transition: height 600ms 0s ease; 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
} 
 

 
#head { 
 
    font-family: quicksand; 
 
    text-align: center; 
 
} 
 

 
nav { 
 
    background: #333333; 
 
    position: fixed; 
 
    top: 82px; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
    text-align: center; 
 
} 
 

 
.navs { 
 
    font-family: quicksand; 
 
    font-size: 18px; 
 
    text-align: center; 
 
    display: inline-block; 
 
} 
 

 
a, 
 
a:link, 
 
a:visited, 
 
a:hover { 
 
    text-decoration: none; 
 
    color: white; 
 
    font-family: quicksand 
 
} 
 

 
#left { 
 
    margin-right: 15px; 
 
}
<header> 
 
    <h1 id="head">Resume - Mathias Nicolajsen</h1> 
 
</header> 
 
<nav> 
 
    <a href="diagonaler.html"><strong><p class="navs" id="left">Projecter</p></strong></a> 
 
    <strong><p class="navs">Omkring mig</p></strong> 
 
</nav> 
 
<p>Lavet af Mathias Nicolajsen</p>

Try text-align: center

-1

Versuchen Sie es. Nur mit text-align: center; wird Ihr Problem gelöst.

header { 
 
    background: #444444; 
 
    z-index: 100; 
 
    transition: height 600ms 0s ease; 
 
    position: fixed; 
 
    top: 0; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
} 
 

 
#head { 
 
    font-family: quicksand; 
 
    text-align: center; 
 
} 
 

 
nav { 
 
    background: #333333; 
 
    position: fixed; 
 
    top: 82px; 
 
    right: 0; 
 
    left: 0; 
 
    color: #ffffff; 
 
    text-align: center; 
 
} 
 

 
.navs { 
 
    font-family: quicksand; 
 
    font-size: 18px; 
 
    text-align: center; 
 
    display: inline-block; 
 
} 
 

 
a, 
 
a:link, 
 
a:visited, 
 
a:hover { 
 
    text-decoration: none; 
 
    color: white; 
 
    font-family: quicksand 
 
} 
 

 
#left { 
 
    margin-right: 15px; 
 
}
<header> 
 
    <h1 id="head">Resume - Mathias Nicolajsen</h1> 
 
</header> 
 
<nav> 
 
    <a href="diagonaler.html"><strong><p class="navs" id="left">Projecter</p></strong></a> 
 
    <strong><p class="navs">Omkring mig</p></strong> 
 
</nav> 
 
<p>Lavet af Mathias Nicolajsen</p>

+0

Haben Sie keinen Unterschied zwischen Ihrer Antwort und upvoted Antwort gesehen. deshalb gewählt. –

+0

Wer meine Antwort abstimmt, sollte wissen, bevor ich gebe, dass, als ich anfing, es durch das Snippet zu beantworten, keine Antwort zu dieser Zeit gepostet wurde. Wenn andere die gleiche Antwort schnell als meine Post geben und wenn mein Beitrag einige Zeit für Snippet brauchte, bedeutet das nicht, dass dies eine falsche Antwort oder eine Kopie ist. Wenn Sie es abgelehnt haben, werden andere es nicht als hilfreich erachten. Als ich gepostet habe, dass andere die gleiche Antwort haben, kann ich auch abstimmen oder meine Antwort löschen. Stattdessen hielt ich es offen und dachte, es könnte anderen helfen. Es ist dein Ruf, wenn du sie wählst, aber auch andere Bedingungen berücksichtigen solltest. – nabanita

0

Ersetzen Sie einfach Ihre nav mit folgendem CSS

nav { 
     background: #333333; 
     position: fixed; 
     top: 82px; 
     right: 0; 
     left: 0; 
     color: #ffffff; 
     text-align: center; 
    } 
Verwandte Themen