相关疑难解决方法(0)

将div定位在其包含div的右侧

我知道这个问题听起来很基本,但我只是无法解决它.我有一个div容器,我试图将一个子div定位到右边.我尝试用相对定位容器div然后定位孩子div与绝对值,但父div失去其宽度.在此输入图像描述

请看一下上图,我需要div1将自己定位在divContainer的右边.我在divContainer中有其他嵌套的div,我只需要在右边提出div1.

div#divContainer{
    margin-left:auto;
    margin-right:auto;
    top: 0px;
    width:1000px;
    background:#666;
    position:relative;

}
div#div1{
    height:45px;width:200px;
    background:yellow;
    position:absolute;

}
Run Code Online (Sandbox Code Playgroud)

HTML代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title></title>

    </head>
    <body>
        <div id="divContainer">
            <div id="div1"></div> 
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html css

5
推荐指数
1
解决办法
5万
查看次数

标签 统计

css ×1

html ×1