简体   繁体   中英

Color a block in header

I want to split up my header bar with a green block (approx. 1/4 of length of header) and have the rest a light brow. Now I have a title and the background-color setting only colors the actual content, how can I color the whole left side of the bar the encompass the title?

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>

and the css for it (sry their might be mistakes, I know, I just want the colored block):

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;
}

I combine your html and css, try the following:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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