HTML/CSS 对齐(内联、水平)和保持右对齐

标签 html css alignment

我试图让这些图标在页眉中并排放置,并在中间(垂直)对齐,并保持在页面的右侧(也许是 float 的?)

http://jsfiddle.net/qNWeV/1/

这是我想要完成的图像:

What I'm trying to accomplish

<!-- HEADER -->
    <div class="header">
        <img class="center-header" src="images/center_header.png" />

        <!-- BUTTONS (header) -->
        <div class="header-buttons-right">
            <!-- Notification Icon -->
            <div class="notify-div" class="right-margin"> <span id="notify-span"> 1 </span> </div>
            <div class="gear-settings"> <!-- Gear Settings --> </div>
            <div class="menu-button"> <!-- Menu Button --> </div>
        </div>

    </div>


/* ******************* */
/*        TOP-NAV      */
/* ******************* */
.header {
    background-color:rgb(243,243,243);
    width:100%;
    height:60px;
    border-color:rgb(243,243,243);
    border-width:2px;
    /* Firefox v1.0+ */
    -moz-border-radius:0%;
    /* Safari v3.0+ and by Chrome v0.2+ */
    -webkit-border-radius:0%/3%;
    /* Firefox v4.0+ , Safari v5.0+ , Chrome v4.0+ , Opera v10.5+  and by IE v9.0+ */
    border-radius:0%/3%;
    border-style:solid;
}
.center-header {
    position: fixed;
    z-index: 1002;
    left: 50%;
    top: -45px;
    margin-left: -135px;
}
.header-buttons-right {
    float: right;
}
.notify-div {
    width: 24px;
    height: 24px;
    background: url('../images/notify-round.png') no-repeat center;
    text-align: center;
}
    #notify-span {
        position: relative;
        top: 3px;
        font-family:"Futura LT Bold";
        font-size:12px;
        font-weight:bold;
        line-height:117%;
        color:rgb(255,255,255);
    }
.gear-settings {
    background: url('../images/gear-settings.png') no-repeat center;
    width: 24px;
    height: 24px;
    display: inline-block;
}
.menu-button {
    background: url('../images/menu.png') no-repeat center;
    width: 24px;
    height: 21px;
}

最佳答案

HTML:

<!-- HEADER -->
<div class="header"> 
    <img class="center-header" src="images/center_header.png" /> 
                <!-- BUTTONS (header) -->
    <div class="header-buttons-right"> 
        <!-- Notification Icon -->
        <span class="notify-div right-margin">
            <span id="notify-span"> 1 </span> 
        </span>
        <span class="gear-settings"> G</span>
        <span class="menu-button">M</span>
    </div>
</div>

CSS:

/* ******************* */
/*        TOP-NAV      */
/* ******************* */

.header {
    background-color: rgb(243,243,243);
    width: 100%;
    height: 60px;
    line-height: 60px;
    border:2px solid rgb(243,243,243);
/* Firefox v1.0+ */
-moz-border-radius:0%;
/* Safari v3.0+ and by Chrome v0.2+ */
-webkit-border-radius:0%/3%;
/* Firefox v4.0+ , Safari v5.0+ , Chrome v4.0+ , Opera v10.5+  and by IE v9.0+ */
border-radius:0%/3%;
}
.center-header {
    position: fixed;
    z-index: 1002;
    left: 50%;
}
.header-buttons-right {
    float: right;
    width:200px;
}
.notify-div {
    width: 24px;
    height: 24px;
    background: url('../images/notify-round.png') no-repeat center;
    text-align: center;

}
#notify-span {
    font-family: "Futura LT Bold";
    font-size: 12px;
    font-weight: bold;
    color: rgb(255,255,255);
}
.gear-settings {
    background: url('../images/gear-settings.png') no-repeat center;
    width: 24px;
    height: 24px;
}
.menu-button {
    background: url('../images/menu.png') no-repeat center;
    width: 24px;
    height: 21px;
}

Jsfiddle: http://jsfiddle.net/VJGUM/

关于HTML/CSS 对齐(内联、水平)和保持右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606510/

相关文章:

html - 欢迎页面背景

html - 4 列与 bootstrap 3.3.7 不正确对齐

html - 将一个元素推到其父级的底部,没有重叠?

pyqt - 如何在 PyQt 中正确对齐右键单击上下文菜单?

javascript - 如何创建多层 Accordion 菜单?

html - 根据背景设置表格最后一个元素的边框

html - 当我放大和缩小时横幅左右移动

javascript - 由于视差滚动功能,导航栏和标题图像(背景图像)之间的差距

html - 如何增加 HTML 应用程序窗口的大小?

html - 在动态网格中排列 Div