简体   繁体   English

CSS3垂直对齐

[英]CSS3 vertical alignment

I'm creating a server list and when i'm echoing out the servers i want the hr tag and the IP to be at the bottom of the div, How do i do that? 我正在创建一个服务器列表,当我回应服务器时,我希望hr标签和IP位于div的底部,我该怎么做?

Heres my code: 继承我的代码:

<div id='serverList'>
<div id='serverRank'>
    <b>Rank</b><hr /><span>1</span>
</div>
<div id='serverInfo'>
    <a href='?p=view&s=".$row['id']."'>".htmlentities($row['server_name'])."</a>
<hr />
".htmlentities(substr($row['server_description'],0,250))."
<div id='serverListBottom' valign='bottom'>
<hr />
<span id='frontInput'>IP: ".$row['server_ip']."</span></div>
</div>

And my CSS code: 我的CSS代码:

#serverList {
height:auto;
width:550px;
-webkit-box-shadow: 7px 7px 20px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    7px 7px 20px rgba(50, 50, 50, 0.75);
box-shadow:         7px 7px 20px rgba(50, 50, 50, 0.75);
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
margin-left:10%;
margin-right:auto;
text-decoration:none;
text-align:left;
min-height:100px;
height:170px;
margin-bottom:40px;
padding:0px;
}
#serverList a {
font-size:20px;
font-weight:bold;
text-decoration:none;
color:#222222;
}
#serverList a:hover {
font-size:20px;
font-weight:bold;
text-decoration:none;
color:#444444;
}
#serverRank{
border:solid 3px #F2F200;
padding:5px;
padding-left:10px;
float:left;
width:50px;
text-align:center;
-moz-border-radius-bottom-right: 20px;
-webkit-border-bottom-right-radius: 20px;
border-bottom-right-radius: 20px;
-moz-border-radius-top-left: 20px;
-webkit-border-top-left-radius: 20px;
border-top-left-radius: 20px;
-webkit-box-shadow: 4px 4px 10px rgba(240, 240, 50, 0.5);
-moz-box-shadow:    4px 4px 10px rgba(240, 240, 50, 0.5);
box-shadow:         4px 4px 10px rgba(240, 240, 50, 0.5);
}
#serverListBottom {
margin-bottom:0px;
}
#serverInfo {
float:right;
width:450px;
}
#frontInput {
color: rgb(0, 0, 0);
font-size: 14px;
padding: 2px;
text-shadow: 0px -1px 0px rgba(30, 30, 30, 0.8);
-webkit-border-radius-left: 5px;
-moz-border-radius-left: 5px;
border-radius-left: 5px;
background: rgb(219, 219, 219);
background: -moz-linear-gradient(90deg, rgb(219, 219, 219) 30%, rgb(240, 240, 240) 50%);
background: -webkit-linear-gradient(90deg, rgb(219, 219, 219) 30%, rgb(240, 240, 240) 50%);
background: -o-linear-gradient(90deg, rgb(219, 219, 219) 30%, rgb(240, 240, 240) 50%);
background: -ms-linear-gradient(90deg, rgb(219, 219, 219) 30%, rgb(240, 240, 240) 50%);
background: linear-gradient(0deg, rgb(219, 219, 219) 30%, rgb(240, 240, 240) 50%);
-webkit-box-shadow: -1px 1px 1px rgba(50, 50, 50, 0.75);
-moz-box-shadow:    -1px 1px 1px rgba(50, 50, 50, 0.75);
box-shadow:         -1px 1px 1px rgba(50, 50, 50, 0.75);
}
#frontInput:hover {
cursor:pointer;
}

You might be able to look in your head what this looks like, But what do i have to do on the #serverListBottom in order to make it be on the bottom of the #serverList div? 你可能会在脑海中看到它的样子,但是我必须在#serverListBottom上做什么才能让它在#serverList div的底部?

Hmm, I think this can be achieved with some quick use of relative and absolute positioning. 嗯,我认为这可以通过快速使用相对和绝对定位来实现。 Add these styles to #serverInfo : 将这些样式添加到#serverInfo

#serverInfo {
    height:100%;
    position:relative;
}

And replace the styles of #serverListBottom with this: 并将#serverListBottom的样式替换为:

#serverListBottom {
    position:absolute;
    bottom:0;
    left:0;
    right:0;
    padding:0 0 3px;
}

You can change the bottom padding to adjust how far you want the IP from the bottom. 您可以更改底部填充以调整IP底部的距离。 (You can also get rid of the deprecated "valign" attribute on #serverListBottom .) (您还可以删除#serverListBottom上已弃用的“valign”属性。)

I hope that's what you were looking for. 我希望这就是你要找的东西。 If not, feel free to say so, and I'll be happy to try to help you further. 如果没有,请随意说出来,我将很乐意为您提供进一步的帮助。

http://codepen.io/anon/pen/nicCa http://codepen.io/anon/pen/nicCa

Here is a codepen. 这是一个codepen。

I made the container position:relative and the text position:absolute; bottom:0; 我做了容器position:relative和文本position:absolute; bottom:0; position:absolute; bottom:0; .

exemple of a line aside a text: 除了文本之外的例行:

 <p><span>IP</span></p>
 p {
      border:inset 1px ;
      border-left:0;
      border-right:0;
      height:0;
      margin:1.5em 0.5em;
      text-align:right;
    }
    p span {
      padding:0 20px;
      vertical-align:20px;
      line-height:0;
      background:white;
    }

Where <p> could be : #serverListBottom 其中<p>可以是: #serverListBottom

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

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