简体   繁体   English

在浮动容器内对齐元素的绝对底部(带有左右浮动)

[英]Aligning element absolute bottom inside floated container (with left and right floats)

I want to align text to the bottom of a container. 我想将文本对齐到容器的底部。 I know I can use position: relative; 我知道我可以使用position: relative; on the container, and position: absolute; bottom: 0; 在容器上,并且position: absolute; bottom: 0; position: absolute; bottom: 0; on the inner element to accomplish this. 在内部元素上实现这一目标。 But, I have floated elements like such: 但是,我浮动了以下元素:

    float: left;                 .align-bottom (and also float: left)
++++++++++++++++++++++++++++++++++++++++++++++++
+     #blah                    |               +
+                              |               +
+ Title            btn1 btn2   | TEXT          +
++++++++++++++++++++++++++++++++++++++++++++++++

Where the floated element on the left has a non-fixed size. 左侧浮动元素的大小不固定的情况。

How can I align TEXT to the bottom of the right container using CSS and HTML? 如何使用CSS和HTML将TEXT对齐到正确容器的底部?

So far I've tried: 到目前为止,我已经尝试过:

.align-bottom {
  /* the 2nd floated element, on right side */
  position: relative;
  overflow: auto;
  height: 100%;
}
.align-bottom div {
  position: absolute;
  bottom: 0;
}

CSSDesk: http://cssdesk.com/kNE98 (like jsFiddle, but no JS) CSSDesk: http ://cssdesk.com/kNE98(例如jsFiddle,但没有JS)

I've seen a few questions somewhat related (not many two floating containers though) including: Vertical Align with Absolute Positioning but it wasn't much help because the floated sections were the same height. 我已经看到一些相关的问题(尽管没有两个浮动容器),包括: 垂直对齐与绝对定位,但这并没有太大帮助,因为浮动部分的高度相同。

body{position:relative}
.align-bottom {
  position: absolute;
  bottom: -50px;
}

Dont check in on CSSDesk because the iframe has height 100% and it would send the bottom div to the bottom of the page. 不要在CSSDesk上签入,因为iframe的高度为100%,并且会将底部div发送到页面底部。 But with this code the div will be at the bottom of the body. 但是使用此代码,div将位于主体的底部。

So I added a parent wrapper around the two columns you want to be the same height, along with a cf (clearfix) class that makes the wrapper be the full height of the floated element. 因此,我在希望具有相同高度的两列周围添加了一个父包装器,以及一个cf(clearfix)类,该类使该包装器成为浮动元素的完整高度。 Then I set the width (29%) of the element to make it sit nicely on the right side of the "left" div. 然后,设置元素的宽度(29%),使其恰好位于“ left” div的右侧。 Using position absolute and setting it to bottom: 0 allowed it to sit nicely. 使用绝对位置并将其设置为底部:0使其放置良好。

Here is the cssdesk link with the correct code: http://cssdesk.com/SjSFQ 这是带有正确代码的cssdesk链接: http ://cssdesk.com/SjSFQ

Regards 问候

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

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