2012-08-27 60 views
1

我搜索了這個,但沒有找到解決方案。 我有一個文本錨點。中心對齊在一個div內的錨文本

錨點的高度和寬度由JS上的DOM負載設置 我需要垂直和水平居中的錨內文本。

遵循許多有關居中元素的教程。他們都沒有工作。

這裏是我的html

<a href="#" class="wpsc_category_grid_item" title="Category1"> 
    <span>Category1</span> 
</a> 

我的CSS

.wpsc_category_grid_item { 
    background: #000; 
    margin:1px; 
    float:left; 
    text-align: center; 
    display:table; 
} 

.wpsc_category_grid_item span{ 
    display: table-cell; 
    vertical-align: middle; 
    width:100%; 
    height:100%; 
    color:#fff; 
    text-align: center; 
    font-weight: bold; 
    text-decoration: none; 
} 

我需要這些文本,垂直居中以及..

enter image description here

+1

縱橫中心頁面上或者一些其他元素裏面? –

+2

不是以什麼瀏覽器爲中心?它在Firefox和Chrome中顯示爲我居中http://jsfiddle.net/fYpub/ – Duopixel

回答

2

我做了一個js fiddle你的代碼。它的工作我添加

width: 100%; 
height:100%; 

.wpsc_category_grid_item

+0

有時它只是要求找到一個你一直在尋找幾個小時的解決方案,並突然發生作用,結果WP插件重置了'將'wpsc_category_grid_item'的屬性從'table'顯示到'block'。固定。接受答案,謝謝! – Broncha