2012-08-27 61 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