2012-10-24 29 views
0

當懸停時,此菜單項正在移動。如何在懸停時如何使項目靜止而不移動。 當放置特定的寬度和高度時,會發生同樣的事情。 這是新的JSFiddle鏈接。 http://jsfiddle.net/tagaawang/zTCCf/3/分頁項目懸停並添加邊框

/CSS/

<style type="text/css"> 
     .div{margin:0 auto;position:relative;margin-top:40px;} 
    .pagination{height: 42px; 
     clear: right; 
     top: -21px; 
     left: 0; 
     position: absolute;} 
    .pagination ul{width: 100%;max-height: 42px;} 
    .pagination li{font-family: 'Open Sans', sans-serif; 
     list-style: none; 
     cursor: pointer; 
     font-weight: 600; 
     line-height: 23px; 
     text-indent: 8px; 
     color: white; 
     background-color: #0083DE; 
     height: 26px; 
     font-size: 14px;display: inline-block; 
     width: 26px;margin-left:10px; } 
    .pagination li.selected{background-color: white; 
     border: 4px solid #F0F0F0; 
     padding: 5px; 
     position: relative; 
     font-weight: 600; 
     color: #0F7ABE; 
     font-family: 'Open Sans', sans-serif;} 
    .pagination li:hover{background-color: #0083DE; 
     border: 4px solid #F0F0F0; 
     padding: 5px; 
     position: relative; 
     font-weight: 600; 
     color: #ffffff; 
     font-family: 'Open Sans', sans-serif;}​ 
    </style> 

HTML

<div class="div"> 
<div class="pagination"> 
    <ul> 
    <li>1</li> 
    <li class="selected">2</li> 
    <li>3</li> 
    <li>4</li> 
    <li>5</li> 
    </ul> 
</div> 
</div> 

+2

我在IE9,Firefox 16.0.1或Chrome 22.0.1229.94中沒有看到這一點。什麼瀏覽器? – jmeas

+0

您錯過了jsFiddle中的一些CSS代碼。問題在於你在懸停時添加了一個「邊框」。除非設置了「{box-sizing:border-box}」,否則'border'不包含在元素的寬度中。 – Gareth

回答

4

根據你的代碼,和/或選擇的狀態與邊框一起去懸停4px:

border: 4px solid #F0F0F0; 

這導致4像素的位移offcourse,解決方法:

具有相同的顏色添加邊框,爲你的網站的佔位符的背景,然後徘徊的時候,改變border-color

.pagination li{ 
    border: 4px solid #fff; 
} 
.pagination li.selected, .pagination li:hover { 
    border-color: #F0F0F0; 
} 
+0

懸停狀態下還有一個「padding:5px」,增加了運動。 – Gareth

+0

好的建議。但是背景有紋理。不管怎樣,我只是試試這個,希望QA不介意邊界。謝謝。 – kedomonzter

+0

錯過了一個填充,這應該是當然在初始狀態。 – Mark