2014-02-18 63 views
0

我有一個div內的linkbutton。我已將div的高度設置爲&,使其看起來像使用css的正方形。我也通過CSS設置了高度& linkBut​​ton的寬度。另外我的LinkBut​​to display propery被設置爲阻止(要在整個控件中獲得超鏈接效果)。 現在我想要的是垂直和水平居中LinkBut​​ton文本。linkbutton的中心內容

我嘗試了所有可能的div和linkbutton屬性沒有運氣。 唯一的方法是我可以做到這一點是設置填充(頂部,左側,右側),但隨後它混淆了佈局。

.divblock 
{ 
    background-color :#EEEEEE; 
    border:2px solid; 
    width : 90px; 
    height :80px; 
} 

.Linkbutton 
{ 
    text-decoration: none ; 
    color :black !important; 
    display:block; 
    width : 85px; 
    height :80px; 
} 

ASPX:

<div id="myDiv" runat="server"> 

      <asp:DataList ID="dl1" runat="server" RepeatDirection="Horizontal"  ItemStyle-CssClass ="Items" ItemStyle-HorizontalAlign="Center"> 
       <ItemTemplate> 
        **<div class ="divblock">** 
        <asp:LinkButton **CssClass="Linkbutton"** OnCommand="PresItems_Command"  ID="TestLB1" runat="server" Text="Test" /> 
        </div> 
       </ItemTemplate> 
</asp:DataList> 
</div> 
+0

does text-align:center; vertical-align:middle;不行? – Popo

回答

0

這裏是一個解決方案,它可以爲你工作:

Demo Fiddle

HTML:

<div class="divblock"> 
    <a href="" class="linkbutton">Lorem ipsum.</a> 
</div> 

CSS:

.divblock { 
    //other styles 

    display: table; 
    text-align: center; 
} 

.linkbutton { 
    //other styles 

    display: table-cell; 
    vertical-align: middle; 
} 
+0

這工作就像一個魅力!非常感謝 – voddy