2017-04-19 65 views
-4

我無法居中對齊導航欄中的文本,它的行爲幾乎就像下拉菜單,而不是居中對齊。我找不到原因。無法居中對齊導航欄中的文本

此外,如果你可以幫助:我的社交媒體按鈕都顯示爲藍色,而不是在CSS表中的顏色。

這裏是我的代碼:

<DOCTYPE! html>   
<html>   
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">   
    <head>  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">  
    <title>Home</title> 
    <!--CSS Sheet--> 
    <style>   
    h1 { 
    font-size: 60; 
    text-align: center; 
    font-family: "Bodoni MT", Didot, "Didot LT STD", "Hoefler Text", Garamond, "Times New Roman", serif; 
    } 

    /* Top Navigation Bar*/ 
    .topnav { 
    background-color: #666666; 
    overflow: hidden; 
    } 
    .topnav a { 
    font-family: Rockwell, 'Courier Bold', Courier, Georgia, Times, 'Times New Roman', serif; 
    float: center; 
    display: block; 
    color: #f2f2f2; 
    text-align: center; 
    padding: 8px 16px; 
    text-decoration: none; 
    font-size: 17px; 
    } 
    .topnav a:hover { 
    background-color: #ddd; 
    color: black; 
    } 
    .topnav .icon { 
    display: none; 
    } 
    @media screen and (max-width: 600px) { 
    .topnav a:not(:first-child) {display: none;} 
    .topnav a.icon { 
    float: right; 
    display: block; 
    } 
    } 
    @media screen and (max-width: 600px) { 
    .topnav.responsive {position: relative;} 
    .topnav.responsive .icon { 
    position: absolute; 
    right: 0; 
    top: 0; 
    } 
    .topnav.responsive a { 
    float: none; 
    display: block; 
    text-align: left; 
    } 
    } 
    /*Slideshow*/ 
    /* Slideshow container */ 
    .slideshow-container { 
    max-width: 1000px; 
    position: relative; 
    margin: auto; 
    } 
    /* Caption text */ 
    .text { 
    color: #f2f2f2; 
    font-size: 15px; 
    padding: 8px 12px; 
    position: absolute; 
    bottom: 8px; 
    width: 100%; 
    text-align: center; 
    } 
    /* Number text (1/3 etc) */ 
    .numbertext { 
    color: #f2f2f2; 
    font-size: 12px; 
    padding: 8px 12px; 
    position: absolute; 
    top: 0; 
    } 

    /* The dots/bullets/indicators */ 
    .dot { 
    height: 13px; 
    width: 13px; 
    margin: 0 2px; 
    background-color: #bbb; 
    border-radius: 50%; 
    display: inline-block; 
    transition: background-color 0.6s ease; 
    } 

    .active { 
    background-color: #717171; 
    } 
    /* Fading animation */ 
    .fade { 
    -webkit-animation-name: fade; 
    -webkit-animation-duration: 1.5s; 
    animation-name: fade; 
    animation-duration: 1.5s; 
    } 

    @-webkit-keyframes fade { 
    from {opacity: .4} 
    to {opacity: 1} 
    } 

    @keyframes fade { 
    from {opacity: .4} 
    to {opacity: 1} 
    } 

    /* On smaller screens, decrease text size */ 
    @media only screen and (max-width: 300px) { 
    .text {font-size: 11px} 
    }   
    /*Social Media Buttons*/ 
    .fa { 
    padding: 20px; 
    font-size: 30px; 
    width: 30px; 
    text-align: center; 
    text-decoration: none; 
    margin: 5px 2px; 
    border-radius: 50%; 
    } 

    .fa:hover { 
    opacity: 0.7; 
    } 

    .fa-facebook { 
    background: #3B5998; 
    color: white; 
    } 

    .fa-twitter { 
    background: #55ACEE; 
    color: white; 
    } 

    fa-youtube { 
    background: #bb0000; 
    color: white; 
    } 

    .fa-instagram { 
    background: #125688; 
    color: white; 
    } 

    .fa-snapchat-ghost { 
    background: #fffc00; 
    color: white; 
    text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black; 
    } 

    /*End of Social Media Buttons*/ 

    /*Footer*/ 
    </style> 
    </head> 
    <body> 
    <br> 
    <!--Title/Logo--><h1>Tavernier Tech</h1> 
    <br> 
    <!--Navigation Bar-->  
    <div class="topnav" id="myTopnav">  
     <a href="#home">Home</a> 
     <a href="#articles">Articles</a> 
     <a href="#news">Shop</a> 
     <a href="#contact">Contact</a> 
     <a href="#about">About</a> 
     <a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">&#9776;</a> 
    </div> 

    <script> 
     function myFunction() { 
     var x = document.getElementById("myTopnav"); 
     if (x.className === "topnav") { 
     x.className += " responsive"; 
     } else { 
     x.className = "topnav"; 
     } 
     } 
    </script>  

    <br> 
    <!--Slideshow--> 
    <div class="slideshow-container"> 
     <div class="mySlides fade"> 
     <div class="numbertext"></div> 
     <img src="https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAATOAAAAJDE2NDQ3ZjkzLTljOTAtNDU2Mi04NGRlLTc5NWRkZTYwNzNlMQ.jpg" style="width:90%"> 
     <div class="text"></div> 
     </div> 
     <div class="mySlides fade"> 
     <div class="numbertext"></div> 
     <img src="http://www.ntech.net.au/wp-content/uploads/2015/07/network-switch-ethernet.jpg" style="width:90%"> 
     <div class="text"></div> 
     </div> 
    </div> 

    <br> 
    <div style="text-align:center"> 
     <span class="dot"></span> 
     <span class="dot"></span> 
    </div> 

    <script> 
     var slideIndex = 0; 
     showSlides(); 

     function showSlides() { 
     var i; 
     var slides = document.getElementsByClassName("mySlides"); 
     var dots = document.getElementsByClassName("dot"); 
     for (i = 0; i < slides.length; i++) { 
     slides[i].style.display = "none"; 
     } 
     slideIndex++; 
     if (slideIndex> slides.length) {slideIndex = 1}  
     for (i = 0; i < dots.length; i++) { 
     dots[i].className = dots[i].className.replace(" active", ""); 
     } 
     slides[slideIndex-1].style.display = "block"; 
     dots[slideIndex-1].className += " active"; 
     setTimeout(showSlides, 10000); // Change image every 10 seconds 
     } 
    </script> 
    <!--Footer--> 
    <footer class="">   
     <!--Social Media Buttons--> 
     <a href="#" class="fa fa-facebook-official"></a> 
     <a href="#" class="fa fa-twitter"></a> 
     <a href="#" class="fa fa-instagram"></a> 
     <a href="#" class="fa fa-youtube"></a>   
    </footer> 
    </body> 
</html> 
+2

可否請您嘗試減少您的代碼示例到相關的部分? –

+2

只能發佈相關代碼。 – nikamanish

+0

對不起。 –

回答

0

您需要更改CSS如下

添加的text-align = 「中心」 .topnav,所以現在應該讀

.topnav { 
background-color: #666666; 
overflow: hidden;text-align:center 
} 

從.topnav一,刪除

float: center; 
display: block; 

所以它現在讀取

.topnav a { 
font-family: Rockwell, 'Courier Bold', Courier, Georgia, Times, 'Times New Roman', serif; 
color: #f2f2f2; 
text-align: center; 
padding: 8px 16px; 
text-decoration: none; 
font-size: 17px; 
} 

這將中心的鏈接在你的資產淨值

要爲你的社交媒體鏈接設置的顏色,在你的CSS,添加以下.fa

color:white; 
background-color:#3B5998 

所以它現在讀取

.fa { 
padding: 20px; 
font-size: 30px; 
width: 30px; 
text-align: center; 
text-decoration: none; 
margin: 5px 2px; 
border-radius: 50%;color:white;background-color:#3B5998 
} 

希望這有助於

+0

Joel非常感謝你! –

+0

非常歡迎 – Joel