Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使div浮到容器底部?_Html_Css - Fatal编程技术网

Html 如何使div浮到容器底部?

Html 如何使div浮到容器底部?,html,css,Html,Css,我多次使用float:right(或left)在容器顶部浮动图像和插入框。最近,我发现需要在另一个div的右下角浮动一个div,使用普通的文本换行符(文本只在上面和左边换行) 我认为这一定是相对容易的,即使float没有底值,但我还没有能够使用一些技术来实现,搜索web除了使用绝对定位之外没有其他方法,但这并没有给出正确的换行行为 我原以为这是一个非常普通的设计,但显然不是。如果没有人提出建议,我将不得不将我的文本拆分成单独的框,并手动对齐div,但这是相当不稳定的,我不愿意在需要的每一页上都这

我多次使用float:right(或left)在容器顶部浮动图像和插入框。最近,我发现需要在另一个div的右下角浮动一个div,使用普通的文本换行符(文本只在上面和左边换行)

我认为这一定是相对容易的,即使float没有底值,但我还没有能够使用一些技术来实现,搜索web除了使用绝对定位之外没有其他方法,但这并没有给出正确的换行行为

我原以为这是一个非常普通的设计,但显然不是。如果没有人提出建议,我将不得不将我的文本拆分成单独的框,并手动对齐div,但这是相当不稳定的,我不愿意在需要的每一页上都这样做


编辑:只是给来这里的人的一个提示。上面的问题是重复的,实际上不是重复的。文本环绕inset元素的要求使其完全不同。事实上,这里对投票最多的答案的回答清楚地说明了为什么链接问题中的答案作为对这个问题的回答是错误的。无论如何,这个问题似乎还没有一个通用的解决方案,但是这里和链接问题中的一些解决方案可能适用于特定情况。

将父div设置为
位置:relative
,然后将内部div设置为

position: absolute; 
bottom: 0;

…接下来:)

将div放在另一个div中,并将父div的样式设置为
位置:relative
然后在子div上设置以下CSS属性:
位置:绝对;底部:0

在与各种技术搏斗了几天后,我不得不说这似乎是不可能的。即使使用javascript(我不想这么做),这似乎也不可能

为了向那些可能还不了解的人澄清,这就是我要寻找的:在出版过程中,很常见的做法是布局插图(图片、表格、图形等),使其底部与块(或页面)文本最后一行的底部对齐文本以自然的方式在插图上下流动,这取决于插图在页面的哪一侧。在html/css中,使用float样式将inset的顶部与块的顶部对齐是很简单的,但令我惊讶的是,尽管这是一项常见的布局任务,但似乎不可能将文本和inset的底部对齐


我想,除非有人在最后一刻提出建议,否则我必须重新审视这个项目的设计目标。

如果您同意只将文本的最下面一行放在块的一侧(而不是完全放在块的周围和下面,如果不结束块并开始一个新的块,就不能这样做),将块浮动到父块的一个底角并非不可能。如果将某些内容放在块内的段落标记中,并希望将链接浮动到块的右下角,请将链接放在段落块内,并将其设置为float:right,然后在段落标记末尾下方放置一个div标记,并将clear:all设置为正好。最后一个div是确保父标记包围浮动标记

<div class="article" style="display: block;">
    <h3>title</h3>
        <p>
            text content
            <a href="#" style="display: block;float: right;">Read More</a>
        </p>
    <div style="clear: both;"></div>
</div>

标题

文本内容


这是一个很老的问题,但仍然。。。 可以将div浮动到页面底部,如下所示:

div{
  position: absolute; 
  height: 100px; 
  top: 100%; 
  margin-top:-100px; 
}
var innerBottom;
var totalHeight;
var hadToReduce = false;
var i = 0;
jQuery("#inner").css("position","static");
while(true) {

    // Prevent endless loop
    i++;
    if (i > 5000) { break; }

    totalHeight = jQuery('#outer').outerHeight();
    innerBottom = jQuery("#inner").position().top + jQuery("#inner").outerHeight();
    if (innerBottom < totalHeight) {
        if (hadToReduce !== true) { 
            jQuery(".pipe").css('height', '' + (jQuery(".pipe").height() + 1) + 'px');
        } else { break; }
    } else if (innerBottom > totalHeight) {
        jQuery(".pipe").css('height', '' + (jQuery(".pipe").height() - 1) + 'px');
        hadToReduce = true;
    } else { break; }
}

你可以看到魔法发生的地方。我认为您也可以将其浮动到父div的底部。

如果您需要相对对齐,而div仍然不能满足您的需要,只需使用表格并在您希望内容对齐到底部的单元格中设置valign=“bottom”。我知道这不是一个很好的回答你的问题,因为DIV应该取代表,但这就是我最近用图像标题所做的,到目前为止,它工作得非常完美。

不确定,但是如果你在子DIV上使用位置:相对而不是绝对,那么前面发布的一个场景似乎是可行的

#parent {
  width: 780px;
  height: 250px;
  background: yellow;
  border: solid 2px red;
}
#child {
  position: relative;
  height: 50px;
  width: 780px;
  top: 100%;
  margin-top: -50px;
  background: blue;
  border: solid 2px green;
}

这里面有一些文字。
这只是一些显示在页面底部的文本


没有桌子

我在第一次尝试时添加了
position:absolute;底部:0
到CSS中的div ID。我没有添加父样式
position:relative


它在Firefox和IE8中都能完美工作,但还没有在IE7中试用过

我也尝试了之前发布的这个场景

div {
  position: absolute; 
  height: 100px; 
  top: 100%; 
  margin-top:-100px; 
}
加载页面时,绝对定位会将div固定在浏览器的最低部分,但当向下滚动页面时,如果页面较长,则不会随之滚动。我改变了定位为相对的,它的作品完美。div在装载时会直接到达底部,因此在到达底部之前,您不会真正看到它

div {
      position: relative;
      height:100px; /* Or the height of your image */
      top: 100%;
      margin-top: -100px;
}

这会在页面底部放置一个固定的div,并在向下滚动时固定在底部

#div {
    left: 0;
    position: fixed;
    text-align: center;
    bottom: 0;
    width: 100%;
}

我知道这东西很旧,但我最近遇到了这个问题

使用绝对位置divs的建议真的很傻,因为整个浮动的东西都有点跟绝对位置失分

现在,我没有找到一个通用的解决方案,但是在很多情况下,prople使用浮动div只是为了显示一行中的内容,比如一系列span元素。你不能垂直对齐它

要实现类似的效果,可以这样做:不要使div浮动,而是将其display属性设置为
inline block
。然后,您可以将其垂直对齐,无论您喜欢什么。您只需将父级的div属性
垂直对齐
设置为
顶部
底部
中间
基线


我希望这对某人有所帮助

另一个答案是明智地使用表格和行跨度。通过设置所有表格cel
<table>
<tr>
   <td valign="top">
     this is just some random text
     <br> that should be a couple of lines long and
     <br> is at the top of where we need the bottom tag line
   </td>
   <td rowspan="2">
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     this<br/>
     is really<br/>
     tall
  </td>
</tr>
<tr>
  <td valign="bottom">
      now this is the tagline we need on the bottom
  </td>
</tr>
</table>
<div>
<div style="float:right;height:200px;"></div>
<div style="float:right;clear:right;">Floated content</div>
<p>Other content</p>
</div>
<style>
.sidebar-left{float:left;width:200px}
.content-right{float:right;width:700px}

.footer{clear:both;position:relative;height:1px;width:900px}
.bottom-element{position:absolute;top:-200px;left:0;height:200px;}

</style>

<div class="sidebar-left"> <p>content...</p></div>
<div class="content-right"> <p>content content content content...</p></div>

<div class="footer">
    <div class="bottom-element">bottom-element-in-sidebar</div>
</div>
$("header .pipe").each(function(){
    $(this).next(".cutout").css("position","static");       
    $(this).height($(this).parent().height()-$(this).next(".cutout").height());                                                 
});
header{
    position: relative; 
}

header img.cutout{
    float:right;
    position:absolute;
    bottom:0;
    right:0;
    clear:right
}
header .pipe{
    width:0px; 
    float:right

}
#outer {
    position: relative; 
}

#inner {
    float:right;
    position:absolute;
    bottom:0;
    right:0;
    clear:right
}

.pipe {
    width:0px; 
    float:right

}
var innerBottom;
var totalHeight;
var hadToReduce = false;
var i = 0;
jQuery("#inner").css("position","static");
while(true) {

    // Prevent endless loop
    i++;
    if (i > 5000) { break; }

    totalHeight = jQuery('#outer').outerHeight();
    innerBottom = jQuery("#inner").position().top + jQuery("#inner").outerHeight();
    if (innerBottom < totalHeight) {
        if (hadToReduce !== true) { 
            jQuery(".pipe").css('height', '' + (jQuery(".pipe").height() + 1) + 'px');
        } else { break; }
    } else if (innerBottom > totalHeight) {
        jQuery(".pipe").css('height', '' + (jQuery(".pipe").height() - 1) + 'px');
        hadToReduce = true;
    } else { break; }
}
-moz-transform:rotate(180deg);
-webkit-transform:rotate(180deg);
-o-transform:rotate(180deg);
-ms-transform:rotate(180deg);
filter:progid:DXImageTransform.Microsoft.BasicImage(rotation=2);
<div class="elastic">
  <div class="elastic_col valign-bottom">
    bottom-aligned content.
  </div>
</div>
.elastic {
  display: table;
}
.elastic_col {
  display: table-cell;
}
.valign-bottom {
  vertical-align: bottom;
}
<style>
  #footer {
    height:30px;
    margin: 0;
    clear: both;
    width:100%;
    position: relative;
    bottom:-10;
  }
</style>

<div id="footer" >Sportkin - the registry for sport</div>
outer {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100%;
}
.space {
    float: right;
    height: 75%;  
}
.floateable {
    width: 40%;
    height: 25%;
    float: right;
    clear: right;  
 }
<style>
        #MainDiv
        {
            height: 300px;
            width: 300px;
            background-color: Red;
            position: relative;
        }

        #footerDiv
        {
            height: 50px;
            width: 300px;
            background-color: green;
            float: right;
            position: absolute;
            bottom: 0px;
        }
    </style>


<div id="MainDiv">
     <div id="footerDiv">
     </div>
</div>
.container {
  display: flex;
}
.bottom {
  align-self: flex-end;
}
 <div class="container" style="margin-top: 700px;  text-align-last: center; ">
      <p>My footer Here</p>  
 </div>