嗨,我正在尝试将文本放在底部<div>
.无论是vertical-align:text-bottom;
或vertical-align:bottom;
麻烦在于它是我的导航按钮,如果我按下它然后它们会不对齐.
有没有办法用我的CSS解决这个问题?
a:link {color:#452809}
a:hover {text-decoration:underline;color:#f00}
a:visited {color:#3886e0}
.fleft {float:left}
.fright {float:right}
.clear {clear:both}
* {border:0;margin:0}
**body {font:12px Tahoma,Arial,Helvetica,sans-serif;color:#666;background:#3cb40d}
#main {margin:0 auto;width:780px;background:#fff url(images/vitalbodyhealth.gif) no-repeat center top}
#header {width:780px;margin:10px; height:210px}
#logo {padding-right:10px;text-align:right;padding-bottom:9px;height:150px;vertical-align:text-bottom}
#logo a {text-decoration:none;text-transform:lowercase;font-style:italic;font-size:16px;color:#fff;font-weight:bold}
#logo H2 a {font-size:10px}
#buttons {padding-top:0px;height:40px;width:780px}
#buttons li {display:inline}
#buttons a {display:block;float:left;width:80px;height:26px;text-align:center;text-decoration:none;color:#fff;font-weight:bold;font-size:14px;padding-top:0px;margin-left:12px}
#buttons a:hover {width:80px;height:36px;text-decoration:underline}
#content {width:720px;margin:0 auto;padding:20px}**
.inner_copy {border:0;color:#f00;float:right;width:50%!important;margin:-100% 0 0 0;overflow:hidden;line-height:0;padding:0;font-size:11px}
#left {width:450px;padding:10px; background:#EFEFEF}
#left H1, #left H2 {color:#3cb40d;margin:0}
#left H1 {font-size:24px;padding:0}
#left H2 {font-size:18px;padding-top:10px}
#left a {color:#3886e0}
#left a:hover {text-decoration:none;color:#f00}
#left a:visited {color:#3886e0}
#right {float:right;width:240px; background:#EFEFEF}
#sidebar {width:240px;background:#EFEFEF}
#sidebar ul {margin:0;padding:0;list-style:none}
#sidebar li {margin-bottom:15px}
#sidebar li ul {padding:10px;border-top:none}
#sidebar li li {margin:0;padding:3px 0}
#sidebar li h2 {height:36px;margin:0;padding:10px 0 0 20px;background:#47872B;font-size:18px;color:#fff}
#sidebar a:link, #sidebar a:visited {text-decoration:none}
#sidebar a:hover {text-decoration:underline}
#sidebar li a {padding-left:10px;background:url(images/img09.gif) no-repeat 1px 5px}
#footer {background:#452809;height:47px;width:780px;margin:0 auto;font-size:10px;color:#fff;padding-top:23px;text-align:center;}
#footer div {padding:10px 38px}
#footer a {color:#fff;font-size:10px;text-decoration:none}
.padding {padding:10px;color:#f00;font-weight:bold}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
:)
tot*_*dli 39
Flexbox是针对这些问题而创建的:
#container {
height: 150px;/*Only for the demo.*/
background-color:green;/*Only for the demo.*/
display: flex;
justify-content: center;
align-items: flex-end;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
<span>Text align to center bottom.</span>
</div>
Run Code Online (Sandbox Code Playgroud)
如果您不想弄乱桌面显示,那么您可以创建一个<div>
相对定位的父容器内部,使用绝对定位将其放置在底部,然后将其设置为100%宽,这样您就可以将text-align
它放到中心:
#container {
height: 150px;/*Only for the demo.*/
background-color:green;/*Only for the demo.*/
position: relative;
}
#text {
position: absolute;
bottom: 0;
width: 100%;
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
<div id="container">
<span id="text">Text align to center bottom.</span>
</div>
Run Code Online (Sandbox Code Playgroud)
asp*_*aga 32
要vertical-align
正确使用,您应该在table
标签上进行.但是有一种方法可以让其他html标签表现为一个表格,为它们分配一个css display:table
给你的父母和display:table-cell
你的孩子.然后vertical-align:bottom
将对那个孩子起作用.
HTML:
??????<div class="parent">
<div class="child">
This text is vertically aligned to bottom.
</div>
</div>????????????????????????
Run Code Online (Sandbox Code Playgroud)
CSS:
?.parent {
width: 300px;
height: 50px;
display:? table;
border: 1px solid red;
}
.child {
display: table-cell;
vertical-align: bottom;
}?
Run Code Online (Sandbox Code Playgroud)
这是一个实例:链接演示
垂直对齐仅在某些特定情况下有效。使其发挥作用的最简单方法是display: table
在父元素的 CSS 和display: table-cell;
子元素中进行设置,然后应用垂直对齐属性。