html - 使用 CSS 对齐多个元素

标签 html css css-float

全部,

我正在尝试对齐一些元素,向右浮动和内联,但运气不佳。

这是我正在尝试做的事情(请参阅右侧浅蓝色标题内的 3 个元素)

enter image description here

我要结束这个:

enter image description here

实例 http://jsfiddle.net/castonzo/3G4jb/

我的 HTML

 <div id="addCounselorSection">
     <div class="blue-toolbar">
         <span class="blue-toolbar-title">Club Counselors</span>
         <div class="blue-toolbar-search-tools">
             <div class="blue-toolbar-search-tools-title">Find counselors</div>
             <div><input type="text" /></div>
             <div class="blue-toolbar-search-tools-link"><a href="#">Add</a></div>

         </div>
     </div> 
 </div>

我的 CSS

/****** Toolbar ****************/
.blue-toolbar {

    background-color: #086CA1;
    border: 1px solid #235B79;
    height: 45px;
    width: auto;
    margin-bottom: 13px;
    margin-top: 20px;
    position: relative;
}

.blue-toolbar-title {

    position: absolute; 
    bottom: 0; 
    left: 0; 
    float:left; 
    padding-left:5px; 
    padding-bottom:4px; 
    color:#ffffff; 
    font-weight:bold; 
    font-size:18px;
}

.blue-toolbar-search-tools {

    float: right;
    width: auto;
    display: block;
}

.blue-toolbar-search-tools-title {

    color:#ffffff; 
    font-weight:bold; 
    font-size:14px;
    float: left;
    position: absolute; 
    bottom: 0;
    right: 0;
}

.blue-toolbar-search-tools a{
    color:#ffffff;
    font-weight:bold;

}

最佳答案

移除绝对定位并将所有三个子元素的displayblock更改为inline-block。至于垂直定位,只要给父元素加上边距就可以了。

UPDATED EXAMPLE HERE

.blue-toolbar-search-tools {
    float: right;
    margin:16px 10px;
}
.blue-toolbar-search-tools > div {
    display:inline-block;
}

关于html - 使用 CSS 对齐多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544198/

相关文章:

html - Internet Explorer 10,自动调整文本区域大小

html - SCSS : How to combine @for with @each?

css - 如何使 Facebook Like Box 响应?

css - 在 IE/Firefox Mobile 和 Firefox Desktop 中显示不同颜色的文本 (!)

html - 如何将文本定位到右侧?

php - 而在 Mysql 中只提取最后的结果?

css - 设置 div 相对于另一个 div 文本的宽度,如表 td

c# - 制作每列宽度不同的表格,在 asp.net 的 gridview 中保持表格的整体宽度不变

css - 极其基本的 HTML 格式

CSS 过渡旋转仅在 div 向左浮动时才有效