2017-07-30 18 views
0

ドロップダウンメニューバーに問題があり、ドロップダウンが正しく整列していません。ドロップダウンメニューが正しく整列していません

+0

あなたはHTMLコードを投稿できます – pratikpawar

+0

あなたはCSSとHTMLを使って実行しているフィーリングかスニペットを貼り付けることができますか? – Tushar

+0

はあなたのコードを共有しています。スクリーンショットではお手伝いできません。 – Ehsan

答えて

0

Modified code on JSFiddle

HTML

<div class="container"> 
    <a href="index.html">Home</a> 
    <div class="dropdown"> 
    <button class="dropbtn">Recipes</button> 
    <div class="dropdown-content"> 
     <a href="recipe1.html"> Choc Chip Cookie</a> 
     <a href="recipe2.html">Choc Brownie</a> 
     <a href="recipe3.html"> Choc Pretzels </a> 

    </div> 
    </div> 
    <a href="gallery.html">Gallery</a> 
    <a href="contact.html">Contact</a> 
</div> 

CSS

.container { 
    overflow: hidden; 
    background-color: #3399CC; 
    border-style: solid; 
    border-color: black; 
    border-width: medium; 
    width: 50%; 
    margin: auto; 
    text-align: center; 
    font-family: 'Lobster',cursive; 
} 

.container a { 
    float: left; 
    font-size: 22px; 
    color: black; 
    text-align: center; 
    padding: 10px 14px; 
    text-decoration: none; 
    align-content: center; 
    width: 21%; /* Modified by me to change the width of Home, Gallery and Contact element */ 
    display: block; 
} 

.dropdown { 
    float: left; 
    overflow: hidden; 
    width: 24%; /* Modified by me to change the width of Recipe element */ 
} 

.dropdown .dropbtn { 
    font-size: 22px;  
    border: none; 
    outline: none; 
    color: black; 
    padding: 10px 14px; 
    background-color: inherit; 
    font-family: 'Lobster',cursive; 

} 

.container a:hover, .dropdown:hover { /* Modified by me. Change the background color of dropdown element instead of the button */ 
    background-color: #52C3EC; 
} 

.dropdown-content { 
    display: none; 
    position: absolute; 
    background-color: #3399CC; 
    min-width: 160px; 
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); 
    z-index: 1; 
    width: 250px; 
} 

.dropdown-content a { 
    float: none; 
    color: black; 
    text-align: left; 
    padding: 10px 14px; 
    padding-left: 40px; /* Modified by me to align the list item in the dropdown menu */ 
    text-decoration: none; 
    display: block; 
    width: 78%; /* Modified by me to change the width of the list item in the dropdown menu */ 
} 

.dropdown-content a:hover { 
    background-color: #52C3EC; 
} 

.dropdown:hover .dropdown-content { 
    display: block; 
} 

私はあなたのページの構造、それらに使用される唯一のCSSコードを変更していませんよ。私は、コードのどの部分を私が変更と共に修正したのかをマークしました。

空き領域と連絡先の最後が表示されます。これは、サイズをパーセンテージで拡大するのは難しいためです。単位をピクセルに変更することで修正できます。私はあなたに決定を残します。

結果は、サイズ制約のためJSFiddleではなくブラウザで最もよく表示されます。

関連する問題