将DIV表居中放在另一个固定表的下方

时间:2012-10-18 03:27:54

标签: css html

所以我有一个使用此CSS设置的div表,如下所示,以便它居中并固定在页面顶部。我可以设置另一个div并使其居中,但我无法让DIV低于顶级。有什么建议?

这是顶级DIV的css:

  

.fixedtop
{
    position: fixed;
    top: 0px;
    left: 50%;
    margin: 0 0 0 -400px;
    background-image: url(bannerlogo.jpg);
    width:800px;
    height: 414;
}

这是我测试的最新css:

  

.fixedcenter
{
        position:center;
    margin-top: 414px;
    width:800px;
    height: 414px;
}

我还尝试使用填充和搞乱边距来进行居中。非常感谢所有帮助。

2 个答案:

答案 0 :(得分:0)

如果使用“position”,则正确的值为:static,relative和absolute。如果你的div的高度不会变化,那么你可以使用position:absolute并使用“top”指定位置

示例:您可以为第二个元素执行类似的操作:

.fixedcenter2 { position:absolute; margin-top: 414px; width:800px; height: 414px; top: 424px //It will be positioned 20px below the first.
}

答案 1 :(得分:0)

试试这个:

.fixedtop
{
    margin-left: auto;  
    margin-right: auto; 
    border: 1px solid black; /* I only added the borders so that I could*/
                             /* see what was happening more easily.*/
    background-image: url(bannerlogo.jpg); 
    width: 800px; 
    height: 414px;
}

.fixedcenter
{
    border: 1px solid black; 
    margin-left: auto; 
    margin-right: auto; 
    width: 800px; 
    height: 414px;
}

看起来像这样:

2 divs