0

我在水平居中 DIV 时遇到问题。

我在这里提供了一个完整的例子。

它位于 SharePoint 2010 Standard 的内容编辑器 WebPart 中。

4

4 回答 4

1

http://fiddle.jshell.net/hdA7d/

<div class="weathercontainer">
        <div id="weather" class="items" onClick="window.open( 'http://www.weather.com/weather/today/33196','_blank' ); return false;  " >
        </div> 
</div>


.weathercontainer{
    width: 100%;
}
.items {
    width: 170px;
    margin: 0px auto;
    position: relative;
    cursor: pointer;
}
于 2013-09-30T13:28:40.403 回答
0

您可以只给绝对定位.items的左右位置 0 和自动边距:

.items {
    position:absolute;
    margin: 0px auto;
    left:0;
    right:0;
}

看到这个更新的小提琴

于 2013-09-30T13:24:29.867 回答
0

像这样

演示

css

.center
{
    left: 50%;
    position: absolute;
    top: 50%;
}

.center div
{
    border: 1px solid black;
    margin-left: -50%;
    margin-top: -50%;
    height: 100px;
    width: 100px;
}
于 2013-09-30T13:02:07.043 回答
0

检查这是否适合您。 点击这里

display: table-cell;
vertical-align: middle;
于 2013-09-30T13:49:57.587 回答