2011-12-08 37 views
1

這些按鈕由span做出我想要的所有如何讓所有按鈕的高度相同?

enter image description here

同一高度如何獲得呢?在這裏的jsfiddle例如玩http://jsfiddle.net/jitendravyas/Apz9e/16/

/* setting the width and height of the SELECT element to match the replacing graphics */ 
span.select, select.select { 

width:auto ; 
     height:auto ; 
    font:3.2em Arial, Helvetica, sans-serif; 
    font-weight:bold; 
    padding:7% 7% 
} 


select.select{ 
     position:relative; 
     z-index:10; 

     line-height:1; 

} 

select option {padding-top:3px; border-bottom:1px solid red} 

/* dynamically created SPAN, placed below the SELECT */ 
span.select{ 
    position:absolute; 
    bottom:0; 
    float:left; 
    left:2px; 
    line-height:1; 
    text-indent:10px 
    background: #ffffff; 
background: url('images/color-arrow.png') no-repeat, -moz-linear-gradient(top, #ffffff 0%, #a9a9a9 100%); 
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ffffff), color-stop(100%,#a9a9a9)); 
background: -webkit-linear-gradient(top, #ffffff 0%,#a9a9a9 100%); 
background: linear-gradient(top, #ffffff 0%,#a9a9a9 100%); 
    cursor:default; 
    z-index:1; 
    border:#dadada 1px solid; 
    border-radius:6px;  
    background-position: 100% center; 
    text-shadow:0px 1px 1px #fff; white-space:nowrap; 
     diaplay:block 
    } 
+0

你的跨度有不同的墊襯,設置填充爲固定值,而不是在課堂上「span.select,select.select」 7%測試「填充:24px的24px的」 –

+0

@RaduMariş - 看到我對薩瓦斯的評論回答 –

回答

3

顯然,這是因爲您選擇的填充提供了百分比寬度。基本上,當你這樣做時,填充將根據內容的寬度設置。說你的寬度是100px那麼你的情況下填充將是7px。或者當它是1000px時,它將是70px。嘗試給select.select元素提供固定的填充,而不是使用百分比。這將解決你的問題。

同樣,如果你真的要使用百分比填充,然後設置一個固定的寬度。它也會起作用。

**編輯**

以下是你的問題的簡單解決方法。

// on window resize 
$(window).resize(function() { 
    var max = 0; 
    // get the height of the longest select.select 
    $("select.select").each(function() { 
     var h = $(this).height(); 
     if (h > max) 
      max = h; 
    }); 
    // set the height of all select.select to max height 
    $("select.select").height(h); 
}); 
+0

,但因爲我在響應式網站中使用這些按鈕。在重新調整瀏覽器/屏幕尺寸時,按鈕的寬度,高度和字體大小會增加和減少。所以我在'%'中給''填充'以保持比例 –

+1

@JitendraVyas問題在於您沒有減小瀏覽器調整大小時的字體大小。如果你打算調整一切,那麼你還應該調整字體的大小,以使它看起來更像是proportinal。如果你會減小字體大小,那麼填充將不會相同,但至少看起來更成比例。 –

+0

我也在減小字體大小。在實際執行中。但問題不是字體大小,你可以在當前的例子中看到。字體大小對於所有按鈕都是相同的,但高度仍然不相等。 –

相關問題