2016-11-30 31 views
0

我正在使用響應式網頁。我正在使用自定義導航欄,如下所示;Navbar圖標在某些眉毛中未顯示

 function myFunction() { 
 
     var x = document.getElementById("myTopnav"); 
 
     if (x.className === "topnav") { 
 
      x.className += " responsive"; 
 
     } else { 
 
      x.className = "topnav"; 
 
     } 
 
     }
/* Remove margins and padding from the list, and add a black background color */ 
 

 
ul.topnav { 
 
    list-style-type: none; 
 
    margin: 10; 
 
    padding: 10; 
 
    overflow: hidden; 
 
} 
 
/* Float the list items side by side */ 
 

 
ul.topnav li { 
 
    float: left; 
 
    margin: 10; 
 
    padding: 10; 
 
} 
 
/* Style the links inside the list items */ 
 

 
ul.topnav li a { 
 
    display: inline-block; 
 
    color: #f2f2f2; 
 
    text-align: center; 
 
    padding: 14px 16px; 
 
    text-decoration: none; 
 
    transition: 0.3s; 
 
    font-size: 40px; 
 
} 
 
/* Change background color of links on hover */ 
 

 
/* ul.topnav li a:hover {background-color: #fff;} 
 
    
 
    /* Hide the list item that contains the link that should open and close the topnav on small screens */ 
 

 
ul.topnav li.icon { 
 
    display: none; 
 
} 
 
/* When the screen is less than 680 pixels wide, hide all list items, except for the first one ("Home"). Show the list item that contains the link to open and close the topnav (li.icon) */ 
 

 
@media screen and (max-width: 680px) { 
 
    ul.topnav li:not(:first-child) { 
 
    display: none; 
 
    } 
 
    ul.topnav li.icon { 
 
    float: right; 
 
    display: inline-block; 
 
    } 
 
} 
 
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens */ 
 

 
@media screen and (max-width: 680px) { 
 
    ul.topnav.responsive { 
 
    position: relative; 
 
    } 
 
    ul.topnav.responsive li.icon { 
 
    position: absolute; 
 
    right: 0; 
 
    top: 0; 
 
    } 
 
    ul.topnav.responsive li { 
 
    float: none; 
 
    display: inline; 
 
    } 
 
    ul.topnav.responsive li a { 
 
    display: block; 
 
    text-align: left; 
 
    }
<ul class="topnav" id="myTopnav"> 
 
    <li> 
 
    <a href="#news"> 
 
     <img class="img-responsive" width="60px" src="imagenes/botones/logo_hera.png" /> 
 
    </a> 
 
    </li> 
 
    <li> 
 
    <a href="#news"> 
 
     <img class="img-responsive" width="180px" src="imagenes/botones/doctores_boton.png" /> 
 
    </a> 
 
    </li> 
 
    <li> 
 
    <a href="#news"> 
 
     <img class="img-responsive" width="180px" src="imagenes/botones/hospitales_boton.png" /> 
 
    </a> 
 
    </li> 
 
    <li> 
 
    <a href="#news"> 
 
     <img class="img-responsive" width="180px" src="imagenes/botones/farmacias_boton.png" /> 
 
    </a> 
 
    </li> 
 
    <li> 
 
    <a href="#news"> 
 
     <img class="img-responsive" width="180px" src="imagenes/botones/laboratorios_boton.png" /> 
 
    </a> 
 
    </li> 
 

 
    <li class="icon"> 
 
    <a href="javascript:void(0);" onclick="myFunction()">&#9776;</a> 
 
    </li> 
 
</ul>

在我的電腦和我的iPhone,我可以看到導航欄圖標,我想:

iPhone屏幕截圖: enter image description here

但我的Android設備上,它看起來如下:

enter image description here

沒有可見的導航欄圖標。

我的代碼有什麼問題?

編輯:

我知道切換圖標是存在的,但不可見。它的工作原理,當觸及

+0

嘗試在'display:inline-block;'行 – khuderm

+0

@khuderm中添加'!important',如下所示:display:inline-block!important; ?沒有變化,但謝謝 – mvasco

+0

也許是媒體屏幕的問題?只是在這裏猜測。嘗試用明確的寬度進行測試,看看你是否找到了一些東西。 –

回答

0

請使用此代碼在您的樣式表添加

@media screen and (max-width: 680px) { 
ul.topnav li.icon { 
display: block; 
} 
} 
+0

謝謝,添加到代碼中但沒有更改。 – mvasco

0

既然你已經給float:rigt圖標它被推過裝置寬度機器人。添加一個保證金權利解決了我的問題。

@media screen and (max-width: 680px) 
ul.topnav li.icon { 
    float: right; 
    margin-right: 10%; 
    display: inline-block !important; 
} 

還有一個無效的屬性我ul.topnav發現是margin和padding值只是計劃的數值。請使用下面的代碼片段

ul.topnav { 
    list-style-type: none; 
    margin: 0; 
    padding: 10px; 
    width: 100%; 
    display: inline-block; 
} 
+0

謝謝你,沒有改變你的建議,我知道切換圖標在那裏,但不可見。它在觸摸時起作用。 – mvasco

+0

我現場編輯了你的網址http://herasalud.com/#news。它的工作正常。也許清除您的緩存;) –

+0

我知道它在大多數設備上工作正常,但不是在5.5英寸的Android手機上。在我的PC上,在我的Mac上,在我的iPhone上,它工作正常。 – mvasco

0

試試這個 -

@media screen and (max-width: 680px) { 
    ul.topnav li:not(:first-child) { 
    display: none; 
    } 

    ul.topnav li { 
    float:right; 
    } 

    ul.topnav li.icon { 
    display: inline-block; 
    } 
} 

https://jsfiddle.net/chris2001/Lc57jw4c/1/

不知道這是你想要什麼,雖然。

+0

謝謝,但切換圖標在5.5英寸android設備上不可見 – mvasco