Html I';我在尝试将div与CSS垂直对齐时遇到问题

Html I';我在尝试将div与CSS垂直对齐时遇到问题,html,css,alignment,Html,Css,Alignment,您好,我正在尝试将“container2”分区与“cointainer”的底部对齐,但我遇到了问题,我不知道在哪里,需要帮助吗 HTML <div id="container"> <div id="container2"> <p>Text</p> </div> </div> 添加 #container { position: relative; } #container2 { posi

您好,我正在尝试将“container2”分区与“cointainer”的底部对齐,但我遇到了问题,我不知道在哪里,需要帮助吗

HTML

<div id="container">

     <div id="container2">
         <p>Text</p>
    </div>
</div>

添加

#container { position: relative; }
#container2 { position: absolute; bottom: 0; }
或者简单地使用表格

添加

#container { position: relative; }
#container2 { position: absolute; bottom: 0; }
或者简单地使用表格

添加

#container { position: relative; }
#container2 { position: absolute; bottom: 0; }
或者简单地使用表格

添加

#container { position: relative; }
#container2 { position: absolute; bottom: 0; }
或者简单地使用表格


您必须设置边距顶部(您知道两种高度)或使用定位,我选择了第二种变体

#container {postition: relative}
#container2 {position: absolute; bottom: 0; left: 25%;}

您必须设置页边距顶部(您知道两种高度)或使用定位,我选择了第二种变体

#container {postition: relative}
#container2 {position: absolute; bottom: 0; left: 25%;}

您必须设置页边距顶部(您知道两种高度)或使用定位,我选择了第二种变体

#container {postition: relative}
#container2 {position: absolute; bottom: 0; left: 25%;}

您必须设置页边距顶部(您知道两种高度)或使用定位,我选择了第二种变体

#container {postition: relative}
#container2 {position: absolute; bottom: 0; left: 25%;}

您可以设置相对于容器2的位置

工作小提琴


您可以设置相对于容器2的位置

工作小提琴


您可以设置相对于容器2的位置

工作小提琴


您可以设置相对于容器2的位置

工作小提琴


在当前结构中,必须使用
position:absolute
定位子对象

CSS

#container{
/*Colors*/
background-color:rgb(129, 159, 255);
/*Size Box*/
width:400px;
height:200px;
margin:0 auto;
overflow:auto; }

 #container2{
 /*Colors*/
 background-color:black;
 color:white;
 /*Size Box*/
 width:50%;
 height:50%;
 padding:20px;
 margin:0 auto;
 overflow:auto;  }
#container{
    /*Colors*/
    background-color:rgb(129, 159, 255);

    /*Size Box*/
    width:400px;
    height:200px;

    margin:0 auto;
    overflow:auto;
    position: relative;


}

#container2{
    /*Colors*/
    background-color:black;
    color:white;

    /*Size Box*/
    width:50%;
    height:50%;

    padding:20px;
    margin:0 auto;
    overflow:auto; 
    position: absolute;
    bottom:0;
    left:50%;
    margin-left: -25%;

}

在当前结构中,必须使用
position:absolute
定位子对象

CSS

#container{
/*Colors*/
background-color:rgb(129, 159, 255);
/*Size Box*/
width:400px;
height:200px;
margin:0 auto;
overflow:auto; }

 #container2{
 /*Colors*/
 background-color:black;
 color:white;
 /*Size Box*/
 width:50%;
 height:50%;
 padding:20px;
 margin:0 auto;
 overflow:auto;  }
#container{
    /*Colors*/
    background-color:rgb(129, 159, 255);

    /*Size Box*/
    width:400px;
    height:200px;

    margin:0 auto;
    overflow:auto;
    position: relative;


}

#container2{
    /*Colors*/
    background-color:black;
    color:white;

    /*Size Box*/
    width:50%;
    height:50%;

    padding:20px;
    margin:0 auto;
    overflow:auto; 
    position: absolute;
    bottom:0;
    left:50%;
    margin-left: -25%;

}

在当前结构中,必须使用
position:absolute
定位子对象

CSS

#container{
/*Colors*/
background-color:rgb(129, 159, 255);
/*Size Box*/
width:400px;
height:200px;
margin:0 auto;
overflow:auto; }

 #container2{
 /*Colors*/
 background-color:black;
 color:white;
 /*Size Box*/
 width:50%;
 height:50%;
 padding:20px;
 margin:0 auto;
 overflow:auto;  }
#container{
    /*Colors*/
    background-color:rgb(129, 159, 255);

    /*Size Box*/
    width:400px;
    height:200px;

    margin:0 auto;
    overflow:auto;
    position: relative;


}

#container2{
    /*Colors*/
    background-color:black;
    color:white;

    /*Size Box*/
    width:50%;
    height:50%;

    padding:20px;
    margin:0 auto;
    overflow:auto; 
    position: absolute;
    bottom:0;
    left:50%;
    margin-left: -25%;

}

在当前结构中,必须使用
position:absolute
定位子对象

CSS

#container{
/*Colors*/
background-color:rgb(129, 159, 255);
/*Size Box*/
width:400px;
height:200px;
margin:0 auto;
overflow:auto; }

 #container2{
 /*Colors*/
 background-color:black;
 color:white;
 /*Size Box*/
 width:50%;
 height:50%;
 padding:20px;
 margin:0 auto;
 overflow:auto;  }
#container{
    /*Colors*/
    background-color:rgb(129, 159, 255);

    /*Size Box*/
    width:400px;
    height:200px;

    margin:0 auto;
    overflow:auto;
    position: relative;


}

#container2{
    /*Colors*/
    background-color:black;
    color:white;

    /*Size Box*/
    width:50%;
    height:50%;

    padding:20px;
    margin:0 auto;
    overflow:auto; 
    position: absolute;
    bottom:0;
    left:50%;
    margin-left: -25%;

}

如果不想使用绝对位置;您可以这样做:

css
如果不想使用绝对位置;您可以这样做:

css
如果不想使用绝对位置;您可以这样做:

css
如果不想使用绝对位置;您可以这样做:

css
谢谢这正是我想要的:谢谢!这正是我想要的:谢谢!这正是我想要的:谢谢!这正是我想要的:D