使用 CSS 将 DIV 浮动到右下角

新手上路,请多包涵

我有三个 DIV,在 DIV 内部,我想将“了解更多”浮动到右下角,以便它位于灰色背景的顶部。

三格

CSS

 /* the div for LEARN MORE */
#trt {
    z-index: 9999999999999;
    position: relative;
    float: right;
    bottom: 0; // not working
    top: 12; //not working
}

/* the entire div */
.main .cols { padding-left: 2px; padding-right: 0px; padding-top: 10px; }
.main .cols .col { width: 315px; height: 108px; float: left;  background: url(images/tempf.png) no-repeat 0 0; }
.main .cols .col:after { content:''; width: 100%; clear: both; }
.main .cols .col + .col { padding-left: 20px; }
.main .cols .col img.hid { float: left; width: 129px; height: 108px;  }
.main .cols .col-cnt { width: 183px; float: right; }
.main .cols .col .more { font-weight: bold; color: #0206AA; }

HTML

 <div class="main">
    <section class="cols">
        <div class="col">
            <a href="link.aspx">
                <img class="hid" src="css/images/orgNews.png" alt="" />
            </a>
            <div class="col-cnt">
                <h3 style="color: #FFFFFF;">Organization News</h3>
                <p style="color: #FFFFFF;">Interfaith Medical Center related news and updates</p>
                <div id="trt">
                    <img src="css/images/arrow.png" width=11 height=11 align=absmiddle />
                    <a href="link.asp" class="more">Learn More</a>
                </div>
            </div>
        </div>
    </section>
</div>

CSS - 编辑后

.trt {
    z-index: 9999999999999;
    position: absolute;
    bottom: 3px;
    right: 3px;
}
...
.main .cols .col-cnt { width: 183px; float: right; position: relative; }
...

编辑后

这个 CSS 有效:

 .trt {
    z-index: 9999999999999;
    position: absolute;
    top: 85px;
    right: 3px;
}

原文由 Si8 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.8k
2 个回答

set col-cnt div to position: relative set trt to position: absolute; bottom:3px; right:3px; that should get you where you need to be.. also, trt 如果它被重用,应该是一个类

原文由 kingkode 发布,翻译遵循 CC BY-SA 3.0 许可协议

首先,您必须将#trt 的父级设置为相对。

 #parent-of-trt  {
   position: relative;
}

并将#trt 设置为绝对

#trt {
   position: absolute;
   left: 4px;
   bottom: 5px;
}

原文由 searching9x 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏