html - 容器在 HTML/CSS 中的不同位置生成

标签 html css

问题:当我在容器中输入文本时,它们会处于不同的位置(这不是我想要的)。当他们有相同数量的字符时,他们会处于相同的位置。否则你会看到 fiddle ,我的代码列在那里。

JSFIddle:http://jsfiddle.net/7Lsg4mj9/2/

CSS 代码:

body {
    background:#1a1a1a;
    color: black; font-family: Optima,Segoe,"Segoe UI",Candara,Calibri,Arial,sans-serif; }

.header {
    margin:0px auto;
    width:700px;
    height:150px;
    background: rgba(0,173,255,0.5);
    border:2px solid white;

} 

#header h1 {
    font-family: times, Times New Roman, times-roman, georgia, serif;
    color: white;
    margin:0px;
    padding: 0px 0px 6px 0px;
    font-size: 51px;
    line-height:20px;
    letter-spacing:-2px;
    font-weight:bold; } 

#header h2 {
    font-family: Gill Sans, Verdana;
    font-size: 11px;
    line-height: 14px;
    text-transform: uppercase;
    letter-spacing:2px;
    font-weight: bold; }

.container {
    display:inline-block;
    margin:0px auto;
    width:233px;
    height:480px;
    background: rgba(0,193,255,0.5);
    border-bottom: 20px solid rgba(255,255,255,0.4);
    border-top: 20px solid rgba(255,255,255,0.4);
    -webkit-transition: background-color 2s ease;
    transition: background-color 2s ease; }

.container:hover {
        background: rgba(0,153,155,0.5);

}

.container:hover span {
        color:red;

}

.container:hover span{
     -o-transition: all 1s;
    -moz-transition: all 1s;
    -webkit-transition: all 1s;
    transition: all 500ms; }

#container h1 {
    margin-top:-15px;
    text-align:center;
    font-family: Gill Sans, Verdana;
    font-size: 11px;
    line-height: 14px;
    text-transform: uppercase;
    letter-spacing:2px;
    font-weight: bold; }

.footer {
    border:2px solid white;
    margin:0px auto;
    width:700px;
    height:75px;
    background: rgba(0,193,255,0.5);
    font-family: Gill Sans, Verdana;
    font-size: 11px;
    line-height: 14px;
    text-transform: uppercase;
    letter-spacing:2px;
    font-weight: bold;

}

添加一些额外的字符以绕过

最佳答案

inline-block 元素的默认垂直对齐方式是baseline。将 vertical-align:top; 应用于您的容器以获得所需的结果。

.container {
display:inline-block;
margin:0px auto;
width:233px;
height:480px;
background: rgba(0,193,255,0.5);
border-bottom: 20px solid rgba(255,255,255,0.4);
border-top: 20px solid rgba(255,255,255,0.4);
float:center;
-webkit-transition: background-color 2s ease;
transition: background-color 2s ease;
vertical-align:top;
}

DEMO

关于html - 容器在 HTML/CSS 中的不同位置生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916505/

相关文章:

php - 如何检查单选按钮是否包含正确答案?

php - 如何使 PHP 代码只运行一次

javascript - DHTML,多个 CSS 类,在 IE7 中

html - css:已知将文本大小设置为大 20%

html - 为什么 Firefox 在我的 div 上放一个水平滚动条?

javascript - Jquery 不会删除 div

html - IE9 : Issues with anchor tag sizing and li hover

html - 悬停时更改后内容的颜色和背景

javascript - 当我将 div 和 body 的边距设置为 0 时,div 有边距

css - 为什么 Compass CSS Blueprint 中有右边距?