包含 div 底部的位置 div
Position div at bottom of containing div
我在将我的 dT(Date/Time) div 放在包含 div 的底部时遇到问题。我试过设置 bottom: 0px;
无济于事。下面是我正在使用的 html 和 css 代码。
HTML:
<div class='container'>
<aside>
<img id="user-pic" src="images/blank-user.jpg">
<a href="#">@User_Name</a>
<div id="trend"><h6>TRENDING</h6></div>
</aside>
<section class="main">
</section>
</div>
CSS:
#dT{
width:inherit;
bottom: 0px;
border-top: gray;
background-color: gray;
font-size: small;
}
.container{
margin-top: 80px;
}
section{
margin: auto;
width: 400px;
clear: left;
top: 100px;
}
.tweet{
width: 450px;
height: 225px;
background-color: #FFFFFF;
border: 4px solid #F1433F;
border-top-left-radius: 20px;
border-bottom-right-radius: 20px;
margin-bottom: 15px;
padding: 25px 15px 0px 15px;
}
.tweetContent{
width: inherit;
height: inherit;
margin: 5px 5px 0 5px;
border-bottom: 1px solid #EEEEEE;
border-top: 1px solid #EEEEEE;
}
我的代码中有一些 JQuery 元素我没有设置,因为我认为它不会对 div 的定位产生任何影响。
看来代码的 jquery 方面可能与它有关,所以在这里。
更新:删除 JQuery 因为它不相关。
您应该添加 position: relative 或 position: absolute 属性 以使 bottom: 0px 有效
#dT{
width:inherit;
bottom: 0px;
border-top: gray;
background-color: gray;
font-size: small;
position: relative;
}
将 position:relative
添加到 #dT
元素的父级。仅当它是相对的时,您才能使用 left
、 right
、 bottom
和 top
控制子元素。
更新:
并向要使用 left
更改位置的子元素添加 position:absolute
P.S : 需要为包含#dT的div添加relative
,为#dT
添加absolute
#parentofdT
{
position:relative;
}
#dT
{
position:absolute
}
用 position:absolute;
轻松搞定:https://jsfiddle.net/1Lsnjou9/
祝你好运。
使用位置 属性,如绝对位置或相对位置,以便使用顶部、左侧、右侧、底部属性
我在将我的 dT(Date/Time) div 放在包含 div 的底部时遇到问题。我试过设置 bottom: 0px;
无济于事。下面是我正在使用的 html 和 css 代码。
HTML:
<div class='container'>
<aside>
<img id="user-pic" src="images/blank-user.jpg">
<a href="#">@User_Name</a>
<div id="trend"><h6>TRENDING</h6></div>
</aside>
<section class="main">
</section>
</div>
CSS:
#dT{
width:inherit;
bottom: 0px;
border-top: gray;
background-color: gray;
font-size: small;
}
.container{
margin-top: 80px;
}
section{
margin: auto;
width: 400px;
clear: left;
top: 100px;
}
.tweet{
width: 450px;
height: 225px;
background-color: #FFFFFF;
border: 4px solid #F1433F;
border-top-left-radius: 20px;
border-bottom-right-radius: 20px;
margin-bottom: 15px;
padding: 25px 15px 0px 15px;
}
.tweetContent{
width: inherit;
height: inherit;
margin: 5px 5px 0 5px;
border-bottom: 1px solid #EEEEEE;
border-top: 1px solid #EEEEEE;
}
我的代码中有一些 JQuery 元素我没有设置,因为我认为它不会对 div 的定位产生任何影响。
看来代码的 jquery 方面可能与它有关,所以在这里。
更新:删除 JQuery 因为它不相关。
您应该添加 position: relative 或 position: absolute 属性 以使 bottom: 0px 有效
#dT{
width:inherit;
bottom: 0px;
border-top: gray;
background-color: gray;
font-size: small;
position: relative;
}
将 position:relative
添加到 #dT
元素的父级。仅当它是相对的时,您才能使用 left
、 right
、 bottom
和 top
控制子元素。
更新:
并向要使用 left
更改位置的子元素添加 position:absolute
P.S : 需要为包含#dT的div添加relative
,为#dT
absolute
#parentofdT
{
position:relative;
}
#dT
{
position:absolute
}
用 position:absolute;
轻松搞定:https://jsfiddle.net/1Lsnjou9/
祝你好运。
使用位置 属性,如绝对位置或相对位置,以便使用顶部、左侧、右侧、底部属性