2017-04-24 105 views
1

我有問題對齊下拉菜單。它沒有正確對齊,並且依賴於分辨率而流動。不知道是什麼原因造成的。Bootstrap下拉不對齊

FullHD

Tablet view

.nav .dropdown { 
 
     margin-top: -0.5rem; 
 
    } 
 

 
    .btn { 
 
     padding: 2px 10px; 
 
     background-color: transparent; 
 
     border: none; 
 
    } 
 
    
 
    img { 
 
     height: 2.5rem; 
 
     filter: greyscale(100%); 
 
    } 
 
    
 
    img:first-child { 
 
     padding-right: 1px; 
 
    } 
 
    
 
    .dropdown-menu { 
 
     min-width: 1rem 
 
    }
<div class="col-xs-2 col-sm-2 col-md-2 col-md-offset-1 col-sm-offset-1 col-xs-offset-1"> 
 
    <div class="dropdown"> 
 
     <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> 
 
      <img src="img/united-kingdom.svg" alt="UK version"> 
 
      <span class="caret"></span> 
 
     </button> 
 
     <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1"> 
 
      <li><a href="#"><img src="img/united-states.svg" alt="usa version"></a></li> 
 
     </ul> 
 
    </div> 
 
</div>

回答

0

添加相對於主DIV位置和位置絕對個人下拉元素

.nav 
.dropdown{ 
    margin-top: -0.5rem; 
    position: relative; // for keeping it alligned on same line 
} 
.btn{ 
    padding: 2px 10px 
    background-color: transparent 
    border: none 
} 
img{ 
    height: 2.5rem 
    filter: grayscale(100%) 
} 
img:first-child{ 
    padding-right: 1px 
} 
.dropdown-menu{ 
    min-width: 1rem 
    position: absoulute // for keeping it aligned on same line 
} 
+1

感謝。它有點工作。我注意到有一個.open類,我需要調整其寬度 –

+0

歡迎。很高興它對你有效。 –