简体   繁体   English

定位到动态div的底部

[英]Positioning to bottom of dynamic div

This is what I'm trying to achieve 这就是我要实现的目标

http://i.stack.imgur.com/e9xZa.jpg http://i.stack.imgur.com/e9xZa.jpg

I tried this 我试过了

jsfiddle.net/RUSm3/ jsfiddle.net/RUSm3/

but as you can see the date overlaps on the image. 但如您所见,日期在图像上重叠了。

So I added left:215px for the date 所以我添加了left:215px作为日期

jsfiddle.net/9aw29/ jsfiddle.net/9aw29/

It looks good but perhaps I don't have an image. 看起来不错,但也许我没有图像。 How can I get the date back to the far left? 如何将日期恢复到最左边? I'm trying to achieve this without php. 我试图在没有php的情况下实现这一目标。

If you have a div like this 如果您有这样的div

<div class="container">
    <div class="date">today</div>
</div>

with this css fragment your date div will be positioned to the bottom right of it's container. 有了这个CSS片段,您的日期div将位于其容器的右下角。

.container {
      position:relative;
    width: 100px;
    height: 180px;
    border: solid 1px black;
}
.date {
        bottom:10px;
        position:absolute;
        right:10px;
    }

You can verify it working here 您可以在这里验证它是否正常工作

I'm not sure what your markup is, but the easiest solution would be to have the heading, text and date all in one div (inside .entry ), and float the image to the left if it's there. 我不确定您的标记是什么,但是最简单的解决方案是将标题,文本和日期全部放在一个div (在.entry ),然后将图像浮动到左侧(如果有的话)。 The date would be positioned as you have already done in your example. 日期将按照示例中的位置进行定位。 When there is no image, the entire div will move flush left. 没有图像时,整个div将向左平移。

<div class="entry">
  <img [...] />
  <div>
    <h2>Heading</h2>
    <p>Entry text</p>
    <p class="date">[Date]</p>
  </div>
</div>

Here is what I came up with and will probably be a good jumping-off point for you. 这是我想出的,可能对您来说是一个很好的起点。 In short, wrap the two text areas in their own divs, and wrap them in a parent div. 简而言之,将两个文本区域包装在各自的div中,并将它们包装在父div中。 Float the parent div to the right and make it's position something other than static. 将父div浮动到右侧,并使它的位置不是静态的。 If the position is static, you cannot use the position: absolute attribute with it's children divs. 如果位置是静态的,则不能将position:absolute属性及其子div一起使用。

<style type="text/css">
    div.entry{
        float: left;
        position: relative;
        width: 40%;
    }
    img.left{
        float: left;
    }   
    div.right{
        float: right;
        display: inline;
        position: absolute;
        height: 100%;
        width: 50%;
    }   
    div.topRight{
    }   
    div.bottomRight{
        position: absolute;
        bottom: 0px;
    }   
</style>




<div class="entry">
  <img class="left" src="http://www.google.com/logos/2010/halloween10-ires.gif"/>
  <div class="right">
      <div class="topRight">
          Some stuff
      </div>
      <div class="bottomRight">
          Some other stuff
      </div>
  </div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM