【问题标题】:Bottom-align right div elements in fluid-layout在流体布局中底部对齐右 div 元素
【发布时间】:2013-11-06 15:28:54
【问题描述】:

请问,有人可以帮忙吗?无论窗口大小如何调整,我都需要将我的 RH 图像导航对齐到始终位于浏览器窗口的底部。

我创建了一个包含 3 个 div 的父 .container(最大宽度 800 像素)的流畅布局:
- 顶部的顶桅
- 顶部桅杆下方的两个并排列 div (66:33)

  • LH:主体为左对齐列,
  • RH:导航栏右对齐——我需要底部对齐

最后是一个页脚 div(在主容器之外,跨越整个浏览器宽度)。

我的问题是导航元素(4 个重叠在一起的翻转图像)永远不会与浏览器的底部对齐,而是停留在 div 的顶部。

我尝试了以下 CSS 都无济于事:
vertical-align:0 bottom:0 padding-bottom:0 margin-bottom:0
我更喜欢 CSS 解决方案,它也不需要为 div 指定固定高度。请问有人可以帮忙吗?我已经为解决方案寻找了几个星期:(

由于我是新手,我无法在此处发布我所拥有的图像,所以我将尝试在下面绘制它。但这里还有一个指向我网站的屏幕截图的链接,目前使用以下代码:

http://hooboo.co.uk/Screengrab.jpg

画出来,我有的是:

    -----800px container span-------------------------
    +----topmast-------------------------------------+
    +----2/3 width------------+ +----1/3 width-------+
    | mainbody                | |  navigation (4-row)|
    | that                    | |  that is short     | 
    | is                      | +--------------------+
    | tall                    |    
    |                         |
    +-------------------------+
    --------------------------------------------------
+--------footer 100% browser width-----------------------+

我需要的是:

    -----800px container span-------------------------
    +----topmast-------------------------------------+
    +----2/3 width------------+ 
    | mainbody                | 
    | that                    |  
    | is                      | +----1/3 width-------+
    | tall                    | |  navigation (4-row)|   
    |                         | |  that is short     |
    +-------------------------+ +--------------------+
    --------------------------------------------------
+--------footer 100% browser width-----------------------+

这是我的 CSS:

.container {
width: 84%;
height: 100%;
max-width: 800px;
padding-left: 3%;
padding-right: 3%;
padding-top: 6%;
padding-bottom: 0%;
margin-bottom: 0%;
margin-left: auto;
margin-right: auto;
margin-top: auto; 
}

#topmast{ 
clear: both;
margin-left: 0;
margin-top: 25%;
height: auto;
width: 100%;
min-width: 240px;
min-height: auto;
display:block;
}


#navigation{ 
clear: right;
float:right;
width:33.125%;
height:600px; 
height:auto; 
max-width:265px;
vertical-align:bottom;
bottom: 0;
margin-bottom: 0;
padding-bottom: 0;
position:relative;
display:block;
}

#mainbody { 
clear: left;
margin-right:33.125%;
margin-top: 0%;
width: 65%;
display:block;
}

#footer { 
clear:both;
background-color:#333;
height:100px;
}

这是我的两列的 html:

<div id="navigation" align="right" style="vertical-align:bottom">  

<a href="mailto:email@url.com" target="_blank"   
onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Email','','00_assets/buttons/00_BUTTONS_EMAILO.png',1)">
<img src="00_assets/buttons/00_BUTTONS_EMAIL.png" alt="Email: email@url.com" 
width="100%" height="auto" id="Email" border="0" style="float: right;"/>
</a>

<a href="tel:+1234567890" target="_blank" 
onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Call','','00_assets/buttons/00_BUTTONS_CALLO.png',1)">
<img src="00_assets/buttons/00_BUTTONS_CALL.png" alt="Call: +1234567890" 
width="100%" height="auto" id="Call" border="0" style="float: right;"/>
</a>

<a href="https://url.com/screenname" target="_blank" 
onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Twitter','','00_assets/buttons/00_BUTTONS_TWEETO.png',1)">
<img src="00_assets/buttons/00_BUTTONS_TWEET.png" alt="Tweet us" 
width="100%" height="auto" id="Twitter" border=0 style="float: right;"/>
</a>

</div>

<div id="mainbody" align="left"> 
<h1>Welcome to website</h1>
<p class="Body"> Mainbody copy about website services goes here.</p>
</div>

请问有人可以帮忙吗?我也不知道如何使用 JsFiddle 来发布演示。网页设计还是有点新意。提前谢谢你。

【问题讨论】:

    标签: html css vertical-alignment fluid-layout fluid


    【解决方案1】:

    您可以在元素上使用display: inline-block; 之类的东西将它们放在一起,这也将支持vertical-align: bottom; 我看到您尝试使用的属性。

    看看这个jsFiddle演示这个。

    请注意,我删除了很多您正在使用的样式,最重要的是 float 属性。

    还请注意,我重新排列了您的 html 的顺序,以便导航部分不再位于主体之前,因为元素的浮动不再重新排列它们。

    然后,我将display: inline-block; 放在两个部分上,并将导航部分垂直对齐到底部。

    【讨论】:

    • 感谢布莱克这么快的回复。不幸的是,现在这样做是在底部对齐我的导航时,将其对齐到左侧主体 div 的底部。但是,如果正文副本在不滚动的情况下不适合浏览器,我需要将导航放在浏览器的底部,这样它就不会被剪裁。这有意义吗?现在我的图像在它们之间有一个中断,我认为这就是为什么我显示:阻止并浮动它们。这是另一个屏幕截图:link 谢谢你的帮助。
    猜你喜欢
    • 2012-11-30
    • 2015-06-21
    • 2017-02-16
    • 1970-01-01
    • 2021-10-14
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多