在标题中为块添加颜色

时间:2013-09-12 00:37:31

标签: html css frameworks jekyll

我想把我的标题栏拆分成一个绿色的块(大约是标题长度的1/4),其余的是眉毛。现在我有一个标题,背景颜色设置只为实际内容着色,我如何着色标题的整个左侧?

html:

<!doctype HTML>
<html>
<header class="nav">
        <div class="container">
            <a class="n-logo" href="/">That Awkward Moment.</a>
            <ul class="n-menu">
                <li><a href="#flav">The Project</a></li>
                <li><a href="#feat">About Us</a></li>
                <li><a href="#inst">Contact</a></li>
                <li><a href="#vid">Github</a></li>
            </ul>
        </div>
    </header>
    <main>
</html>

和css for it(sry他们可能是错误,我知道,我只想要彩色块):

body {
    background-color: $yellowLighter;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 20px;
    color: #333;
}

header {
    display: block;
}

h1 {
    color: $orangeDarker;
}

.container {
    margin-right: auto;
    margin-left: auto;
}

.nav {
    padding: 1em 0;
    border-bottom: 1px solid #eee;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    background: #fffcf5;
    position: fixed;
    width: 100%;
    height: 50px;
    top: 0;
    z-index: 1;
    margin-left: 0;
    margin-bottom: 20px;
    list-style: none;
}

.n-menu {
    float: right;
    list-style: none;
    font-weight: bold;
}
.n-menu li {
    display: inline-block;
    margin-left: 1.2em;
}
.n-menu a {
    color: #555;
}

.n-logo {
    float: left;
    color: #333;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 18px;
}

ul {
    padding: 0;
    margin: 0 0 10px 25px;
    vertical-align: middle;
}

li {
    text-align: -webkit-match-parent;
}

1 个答案:

答案 0 :(得分:0)

我结合你的html和css,尝试以下方法:

<html>
<header class="nav">
    <style>
body {
    background-color: $yellowLighter;
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
    line-height: 20px;
    color: #333;
    margin: auto auto;
}

header {
    display:block;
}

h1 {
    color: $orangeDarker;
}

.container {
    margin-right: auto;
    margin-left: auto;
}

.nav {
    padding: 0 0;
    border-bottom: 1px solid #eee;
    box-shadow: 0 0 5px rgba(0,0,0,0.1);
    background: #fffcf5;
    position: fixed;
    width: 100%;
    height: 50px;
    top: 0;
    z-index: 1;
    margin-left: 0;
    margin-bottom: 20px;
    list-style: none;
}

.n-menu {
    float: right;
    list-style: none;
    font-weight: bold;
}
.n-menu li {
    display: inline-block;
    margin-left: 1.2em;
}
.n-menu a {
    color: #555;
}

.n-logo {
    position: absolute;
    color: #333;
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 18px;
}
.n-logo-div{
    background-color:green;
    width: 25%;
    float: left;
    position: relative;
    height: 100%;
}

ul {
    padding: 0;
    margin: 0 0 10px 25px;
    vertical-align: middle;
}

li {
    text-align: -webkit-match-parent;
}   
    </style>
        <div class="container">
            <div class="n-logo-div">
                <a class="n-logo" href="/">That Awkward Moment.</a>
            </div>
            <ul class="n-menu">
                <li><a href="#flav">The Project</a></li>
                <li><a href="#feat">About Us</a></li>
                <li><a href="#inst">Contact</a></li>
                <li><a href="#vid">Github</a></li>
            </ul>
            <div style="clear: both"></div>
        </div>
    </header>
</html>