I am trying to move things around in the header navbar under #media trying to make my site responsive. I'm tinkering with a bunch of stuff but I've hit a wall.
I'm trying to space out my header navbar links which currently are not spaced apart, and I'm also trying to move my subscription bar to the far right inside the navbar.
Since I have been tinkering with stuff I probably have excess code in places it should not be, if so please let me know so I can understand how moving items functions and what I should avoid in the future.
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
height: 100px;
display: flex;
padding: 10px 0 30px 10px;
}
.header-logo img {
height: 100px;
padding: 10px 0px 10px 10px;
float: left;
}
header nav ul {
display: block;
margin: 50px 0 0 auto;
padding: 0 0 0 10px;
width: fit-content;
}
header nav ul li {
display: inline-block;
padding: 0 5px;
}
header nav ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.home-link {
float: right;
padding: 0 0 0 0px;
}
.sub {
display: none;
background-color: rgb(70, 149, 223);
margin-left: 5%;
height: auto;
list-style: none;
}
/* HAMBURGER MENU */
.nav div {
height: 4px;
background-color: rgb(20, 15, 15);
margin: 5px 0;
border-radius: 25px;
transition: 0.3s;
}
.nav {
width: 30;
display: block;
float: right;
margin: 1em 0 0 1em;
padding-right: 0px;
}
.one {
width: 30px;
}
.two {
width: 20px;
}
.three {
width: 25px;
}
.nav:hover div {
width: 30px;
}
#hamburger {
display: none;
list-style: none;
}
.hamburger-toggle {
float: right;
padding: 25px 0px 0px 125px;
}
ul li a:hover {
color: rgb(255, 255, 255);
}
/* Desktop Media */
#media only screen and (min-width: 1000px) {
header .header-logo {
float: left;
padding: 10px 10px 10px 10px;
height: auto;
width: 220px;
display: table;
}
header nav ul {
margin: 0 auto;
padding-right: 50px;
}
header nav ul li {
padding: 0 0 0 50px;
}
header nav ul li a {
line-height: 150px;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
padding: 0 0 0 50px;
}
header .sub {
display: block;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
line-height: 50px;
border: 2px solid #111;
float: right;
padding: 2px 20px;
}
.sub {
margin-left: auto;
height: auto;
position: relative;
z-index: 1000;
width: fit-content;
height: 40px;
background-color: rgb(70, 149, 223);
}
.index-banner {
width: 100%;
height: calc(100vh - 100px);
max-width: 1080px;
margin-right: auto;
margin-left: auto;
background-image: url('img/road_trip.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.index-banner h1 {
display: block;
padding: 120px 0 0px 120px;
font-family: 'Karma', serif;
font-size: 60px;
font-weight: 900;
color: #fff;
text-shadow: 4px 4px 16px #111;
}
.verticial-center {
margin: 0 auto;
display: table-cell;
vertical-align: middle;
padding: 120px 0 0 0;
}
.nav {
display: none;
}
#hamburger {
display: flex;
line-height: 150px;
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
}
.hamburger-toggle {
display: none;
}
}
/*INDEX*/
.index-banner {
width: 100%;
height: calc(100vh - 100px);
background-image: url('img/road_trip.jpg');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.index-banner h1 {
padding-top: 30px;
font-family: 'Karma', serif;
font-size: 60px;
font-weight: 900;
line-height: 70px;
color: #fff;
text-align: center;
text-shadow: 4px 4px 16px #111;
}
.verticial-center {
margin: 0 auto;
display: table-cell;
vertical-align: middle;
}
/* HERO SECTION */
.hero-section {
font-family: 'Sorts Mill Goudy', serif;
font-size: 24px;
color: #111;
width: 100%;
max-width: 1080px;
/* or whatever width you want */
margin-right: auto;
margin-left: auto;
}
.hero-section {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
text-align: center;
padding: 25px;
}
.hero-paragraph {
margin: 0 auto;
max-width: 100%;
font-family: 'Sorts Mill Goudy', serif;
font-size: 24px;
color: #111;
text-align: center;
padding: 25px;
}
/* RESPONSIVNESS */
#media only screen and (min-width: 1000px) {
.wrapper {
width: 100%;
margin: 0 auto;
}
.index-banner {
height: 500px;
}
.hero-paragraph {
width: 100%;
margin: 0 auto;
}
.hero-section {
width: 100%;
margin: 0 auto;
}
}
/* BLOG PAGE */
.body-wrapper {
width: 100%;
max-width: 1080px;
/* or whatever width you want */
margin-right: auto;
margin-left: auto;
padding-top: 50px;
}
.blog-title {
font-family: 'Sorts Mill Goudy', serif;
font-size: 60px;
color: #111;
text-align: center;
display: block;
}
.blog-title div {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
padding: 60px;
width: 50%;
text-align: left;
}
.blog-title div h1 {
font-family: 'Karma', serif;
font-size: 40px;
color: #111;
text-align: center;
}
/* FOOTER */
footer {
width: calc(100% - 80px);
padding: 40px 40px;
margin-top: 20px;
background-color: #111;
overflow: hidden;
}
footer ul {
width: fit-content;
float: left;
padding-left: 20px;
}
footer ul li {
display: block;
list-style: none;
}
footer ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 18px;
color: #fff;
line-height: 40px;
}
.footer-sm {
width: 50px;
float: right;
}
.footer {
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #fff;
text-align: center;
margin: 170px 0 0 0;
}
.footer-sm img {
width: 100%;
margin-bottom: 10px;
display: block;
}
/* FOOTER RESPONESIVNESS */
#media only screen and (min-width: 1000px) {
footer ul li a {
font-family: 'Sorts Mill Goudy', serif;
font-size: 18px;
color: #fff;
line-height: 40px;
}
}
<body>
<header>
<div class="header-logo">
<img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo">
</div>
<nav div class="home-link">
<ul>
<li>Home</li>
</ul>
</nav>
<nav>
<div class="hamburger-toggle">
<ul>
<a href="#" class="nav">
<div class="one"></div>
<div class="two"></div>
<div class="three"></div>
</div>
<div id="hamburger">
<li>Podcast</li>
<li>Newsletter</li>
<li>Blog</li>
<li>Contact</li>
</div>
<div class="sub">
<li>Subscribe</li>
</div>
</a>
</ul>
</nav>
</header>
<main>
<section class="index-banner">
<div class="verticial-center">
<h1>The Milestone Hackers Podcast</h1>
</div>
</section>
<div class="wrapper">
<section class="hero-section">
<h2>What Can you Expect From our Podcast</h2>
<p class="hero-paragraph">A host (meee, Paolo) interviewing various types of entrepreneurs or founders both technical and non-technical. Each entrepreneur has their own unique story that resulted in learning or experiencing something that can benefit our audience who may
want to go down the entrepreneurial path!</p>
</section>
</div>
</main>
<div class="wrapper">
<footer>
<ul>
<li>Home</li>
<li>Podcast</li>
<li>Newsletter</li>
<li>Blog</li>
<li>Contact</li>
</ul>
<div class="footer-sm">
<a href="https://twitter.com/Milestonehacker">
<img src="img/twitter.png" alt="twiiter icon">
<a href="https://open.spotify.com/show/2ZiIxv5Mr83seTtNsg3LD9">
<img src="img/spotify.png" alt="spotify icon">
<img src="img/rss.png" alt="rss icon">
</a>
</div>
<p class="footer">Copyright © 2019; All Rights Reserved</p>
</footer>
Don't have a 3000x3000 px image that is about 100px when displaying. You're logo should be about 20kb at most for that size, not 742 kb.
Don't use float (or absolute), unless you're certain of what you're doing. Floats messes up all the divs that displays blocks. For example, you needed to set a height on your header because the logo was floating.
Start sketching out your design, and put everything in rectangles. You don't need that many elements just to display your header.
If you think your CSS is cluttered. Remove everything and start again, preferably from #3 above.
I added CSS variables. It's always good to have a margin that you keep for all distances. margin-half could be added as well.
:root {
--margin: 10px;
--margin-double: 20px;
}
* {
text-decoration: none;
}
body {
background-color: #f3f3f3;
}
header {
background-color: #fff;
width: 100%;
display: flex;
align-items: center;
padding: var(--margin-double);
box-sizing: border-box; /* take padding into account for width */
}
header > .header-logo > a {
display: flex; /* to remove weird spacing behavior in Firefox */
}
header > .header-logo img {
height: 100px;
padding-right: var(--margin);
}
header > nav {
flex: 1 1 auto; /* Take up any free space within <header> */
display: flex;
flex-wrap: wrap;
height: 100%;
}
#media (min-width: 700px) {
header > nav {
justify-content: center;
}
}
header > nav > a {
margin-right: var(--margin);
font-family: 'Sorts Mill Goudy', serif;
font-size: 16px;
color: #111;
text-transform: uppercase;
line-height: 24px;
}
header > nav > a::before {
width: 100%;
height: 1px;
}
header > a.sub {
height: 20px;
padding: var(--margin);
align-self: end; /* I didn't know where you wanted the button */
background-color: rgb(70, 149, 223);
color: #fff;
}
<body>
<header>
<div class="header-logo">
<img src="https://milestonehackers.com/img/Milestonehackers.jpg" alt="Milestonehackers logo">
</div>
<nav>
Home
Podcast
Newsletter
Blog
Contact
</nav>
<a class="sub" href="subscribe.html">Subscribe</a>
</header>
</body>
Best practice to use bootstrap for responsive purpose as it provides n number of components and does have lot's of utility classes so you don't need to write your own CSS most of the places
Check out this link for details on utility classes
here
Here is the simple example by using bootstrap.
HTML:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
https://codepen.io/pgurav/pen/abbaOwW
Related
I have a menu bar that I am trying to float right, I also have a logo that I would like to keep to the left.
I have been able to get the menu to float to the right and keep the logo on the right however the menu is being pushed down in is not in line with the logo.
How do I get the menu in line with the logo?
If I put float left on the logo it leaves a weird gap at the top and messes up the layout.
Here is my code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
You need to put display: flex for .container-fluid that helps all your menu items on the same line as logo. To align right for menu items, you should put margin-left: auto for .navbar-collapse
Here is the full code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.container-fluid {
display: flex;
}
.navbar-collapse {
margin-left: auto;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
I have a header in the beginning of my webpage with a background image covering 100% of the width and 100vh. I want to add a different section in my page for the story section which is one of my nav
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,body {
font-family: 'Lato','sans-serif','arial';
color: #fff;
font-size: 15px;
font-weight: 300;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
.wrapper {
width: 100%;
height: 100vh;
padding: 0;
}
.flex {
display: flex;
justify-content: space-between;
background-image: linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.6)),url("img/truck.jpg");
background-size: cover;
background-position: center;
height: 100vh;
}
.flex-item {
padding-top: 15px;
}
.item1 {
padding-top: 0;
padding-left: 30px;
}
.logo {
height: 90px;
}
.main-nav ul {
display: flex;
margin: 0;
padding: 0;
list-style: none;
}
.main-nav a {
color: white;
padding: 1rem;
text-decoration: none;
}
.main-nav a:hover {
color:orange;
}
.hero {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.hero a {
text-decoration: none;
color: white;
display: block;
margin: 10px;
}
.btn {
background-color: orange;
border-radius: 50px;
}
/*---------------------------------*/
/*Story Section*/
/*---------------------------------*/
section .flex2 {
display: flex;
flex-direction: column;
color: black;
height: 100vh;
}
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="Resources/css/styles.css">
</head>
<body class="wrapper">
<header class="flex">
<div class="flex-item item1">
<img src="Resources/img/moBurgerzLogo.png" class="logo">
</div>
<nav class="flex-item main-nav">
<ul>
<li>Our Story</li>
<li>Locations</li>
<li>Menu</li>
<li>Order now</li>
</ul>
</nav>
<div class="hero">
<h2>Best Burgers <br> In DA City(D.C)</h2>
<a href="#" class="btn" btn-full>Order now!</a>
<a href="#" class="btn" btn-ghost>View Menu!</a>
</div>
</header>
<section class="flex-2">
<div class="flex-item-2">
<h2>Established in 2017 in D.M.V</h2>
<p class="story"> founded in 2017 by owner Med.<br> Since then we have been serving the best hand crafted burgers in the D.M.V.<br>All our meat is halal and all of our ingridients are organic.</p>
</div>
</section>
</body>
</html>
elements. However I can not scroll to view the content in the story section consisting of an h2 element and paragraph tag inside a flex container.
html,
body {
font-family: "Lato", "sans-serif", "arial";
color: #fff;
font-size: 15px;
font-weight: 300;
text-transform: uppercase;
text-rendering: optimizeLegibility;
}
I think because your font color is white
I've been going around the web trying to find an answer to how to center my navbar but none of the solution worked.
The code below will show what I have so far with both HTML and CSS.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
This is how it looks like right now:
I have also noticed that in CSS, when I did "float: center;" it had no difference with when I did "float: left;". But when I did "float: right;" it would shift to the right.
ul {
margin: 0 auto;
text-align: center;
}
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin: 0 auto;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>
</body>
</html>
I have removed the below css from your code
header #smcontent {
float: left;
}
and added margin: 0 auto; text-align: center; to the ul
Try absolute position with float none, left 50% and a left translate of 50% to center your nav bar perfectly.
CSS: add
header .newCenter {
float: none;
position: absolute;
left: 50%;
transform: translate(-50%, 0);
}
HTML: add
<nav class="newCenter">
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
Float only applies to left and right. I added display: grid and justify-content: center to your header. I removed float: left; in header #smcontent.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
display: grid; //or flex
justify-content: center;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
display: inline;
padding: 0 20px;
}
header nav {
margin: 10px auto 0;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin: 0 auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="./images/twitter.png">
</a>
<a href="https://facebook.com/">
<img src="./images/facebook.png">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="./images/portfolio.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</header>
To align text horizontally center use text-align:center. In your to align nav bar content center just add text-align:center to header nav
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
In below code snippet I have added some images for demonstration purpose.
header {
background: #ffffff;
color: #000000;
padding-top: 30px;
min-height: 70px;
border-bottom: #000000 3px solid;
}
header a {
color: #000000;
text-decoration: none;
text-transform: uppercase;
font-size: 16px;
}
header li {
float: center;
display: inline;
padding: 0 20px 0 20px;
}
header nav {
margin-left: auto;
text-align:center;
margin-right: auto;
margin-top: 10px;
}
header #smcontent {
float: left;
}
header #smcontent a {
margin: 0;
}
header #smcontent img {
width: 20px;
}
header .logoimg .center {
display: block;
margin-left: auto;
margin-right: auto;
width: 20%;
}
header a:hover {
color: #cccccc;
font-weight: bold;
}
<header>
<div class="container">
<div id="smcontent">
<a href="https://twitter.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-may-26-2015twitter-260nw-281505518.jpg">
</a>
<a href="https://facebook.com/">
<img src="https://image.shutterstock.com/image-photo/kiev-ukraine-april-27-2015-260nw-278925056.jpg">
</a>
</div>
<div class="logoimg">
<a href="index.html">
<img class="center" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
</a>
</div>
<nav>
<ul>
<li class="current">Home</li>
<li>Story</li>
<li>Product</li>
<li>Clinique</li>
<li>Promotions</li>
</ul>
</nav>
</div>
</header>
I've finished coding my website for a 1024x768 resolution and now want to add #media queries to my code so that the sidebar disappears when the screen is at a width of 980px and then stays like that all the way down from there. I have tried adding the #media max-width 980 myself but it does not seem to be working at all. I've also tried in various places on the page but again, no luck. It's so frustrating! Code Below (Sorry if it's really long, I'm gonna leave it all in there to avoid any questions regarding code).
HTML:
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" />
<title>Lakeside Books</title>
<link rel="stylesheet" type="text/css" href="masterstyle.css">
<meta name="viewsize" content="width-device-width,initial-scale=1.0">
<!--[if IE]>
<script type="text/javascript" src="_http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<div id="sidebar">
<nav id="nav">
<h3 id="welcometext">Welcome To<br>Lakeside Books</h3>
<div id="searchbar">
<form action="http://www.example.com/search.php">
<input type="text" name="search" placeholder=" ...Search Book Title" class="searchstyle"/>
</form>
</div>
<ul>
<li style="background-color: #333">
<a href="1Index.html" class="link">
<span style="color: #ed786a">Home</span>
</a>
</li>
<li>
<a href="2Catgeories.html" class="link">
Categories
</a>
</li>
<li>
<a href="http://example.com" class="link">
Bestsellers
</a>
</li>
<li>
<a href="http://example.com" class="link">
Find Us
</a>
</li>
<li>
<a href="http://example.com" class="link">
Contact
</a>
</li>
</ul>
</nav>
</div>
CSS:
html, body { /* ### */
margin:0;
padding:0;
height:100%;
width:100%;
}
body {
background-color: #fdfdfd;
font-family: Arial, "Open Sans", sans-serif-light, sans-serif, "Segoe UI";
}
#wrapper {
width: 100%;
height: 100%;
margin:0 0 0 20%; /* ### */
}
#sidebar {
background-color: #212528;
position: fixed;
width: 20%;
height: 100%;
top: 0;
left: 0;
overflow: hidden;
text-shadow: 0.1em 0.1em 0 rgba(0, 0, 0, 0.1);
}
#nav {
color: #DADADA;
display: block;
max-width: 100%;
}
#nav ul {
padding-left: 0;
}
#nav li {
list-style-type: none;
margin: 0;
padding: 0.75em 0 0.75em 0;
text-align: center;
max-width: 100%;
}
#nav li:hover {
background:#333;
}
#nav li a {
display: block;
padding: 0.5em 0;
}
.link {
text-align: right;
margin-right: 25%;
letter-spacing: 1px;
display: block;
}
#nav li a:link{
color: #DADADA;
text-decoration: none;
}
#nav li a:visited{
color: #DADADA;
text-decoration: none;
}
#nav li a:hover{
color: #DADADA;
text-decoration: none;
}
#nav li a:active{
color: #DADADA;
text-decoration: none;
}
#welcometext {
text-align: center;
/*font-style: italic;*/
text-transform: uppercase;
font-size: 1em;
margin-top: 2em;
}
#searchbar {
width: 70%;
margin-left: auto;
margin-right: auto;
padding: 1em 1em 0.5em 1em;
text-align: right;
}
#searchbar .searchstyle{
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#searchbar input {
max-width: 95%;
}
/*-------Media Styles-------*/
#media all and (max-width: 980px){
#sidebar{
float: none;
}
}
I have a couple groups of links at the top of a layout page for an MVC app, and I'm having trouble getting these links positioned properly.
Here's what they SHOULD look like (I'm making some huge changes to this site, but keeping the layout intact):
Keep in mind that this photo is at the center-right of my page, that is to say, the page extends further to the right, but there's no content in that area.
After altering these image-based links to text-based, they lose their styling integrity and scramble.
Here's some code from my current links to give an idea of how they're contained:
<div class="top-links">
<div id="top-nav">
<a class="top-link" href="#" title="My Profile">
<span>MY PROFILE</span>
</a>
<a class="top-link" href="#" title="Account Profile">
<span>ACCOUNT PROFILE</span>
</a>
<a class="top-link" href="#" title="Sign Out">
<span>SIGN OUT</span>
</a>
</div>
</div>
<div class="links">
<div id="nav">
<a class="home-link home-link-left" href="#" title="My Component Books">
<span>MY COMPONENT BOOKS</span>
</a>
<a class="home-link" href="#" title="New Component Book">
<span>NEW COMPONENT BOOK</span>
</a>
<a class="home-link" href="#" title="System Logs">
<span>SYSTEM LOGS</span>
</a>
</div>
</div>
I left out pieces of the tags themselves for readability.
And finally, the relevant CSS:
/*----------- TOP NAVIGATION -----------*/
.top-links {
float: right;
height: 31px;
margin: 0 0 0 0;
width: auto
}
.top-link {
font: 7pt Georgia, serif;
color: #E1915C;
text-align:center;
text-decoration: none;
line-height: 34px;
padding: 10px;
}
#top-nav {
float: right;
margin: 0 0 0 0;
overflow: hidden;
}
/*----------- NAVIGATION -----------*/
.links {
float: right;
width: auto;
height: 36px;
overflow: hidden;
bottom: 0;
right: 0;
}
.home-link {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
border-right: 1px solid #E1E1E1;
text-align: center;
line-height: 36px;
width: auto;
padding: 10px;
}
.home-link:hover {
color: #369AAA;
}
.home-link-left {
border-left: 1px solid #E1E1E1;
}
.home-link-right {
border-right: 1px solid #E1E1E1;
}
#nav {
position: absolute;
float: right;
overflow: hidden;
}
Sorry if it seems like a bit much, some of it isn't my original code and I'm not sure what I should/shouldn't include.
I'm not the best with CSS, so could any styling gurus give me some insight on how I can make the links lay out as they are in the screenshot?
Here is the jsFiddle: http://jsfiddle.net/FVjhQ/2/
CSS
#profile-nav {
margin-bottom: 25px;
}
.nav-container,
.nav-container li {
margin: 0;
padding: 0;
}
.nav-container {
clear: right;
float: right;
}
.nav-container li {
border-left: 1px solid #E1E1E1;
float: left;
list-style: none;
line-height: 36px;
}
.nav-container a {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
padding: 10px;
text-transform: uppercase;
}
.nav-container a:hover {
color: #369AAA;
}
.nav-container .last-link {
border-right: 1px solid #E1E1E1;
}
.no-border li {
border: 0;
}
HTML
<ul id="profile-nav" class="nav-container no-border">
<li>
My Profile
</li>
<li>
Account Profile
</li>
<li>
Sign Out
</li>
</ul>
<ul id="component-nav" class="nav-container">
<li>
My Component Books
</li>
<li>
New Component Books
</li>
<li>
Notifications
</li>
<li class="last-link">
System Logs
</li>
</ul>
See if this is what you were going for: http://jsfiddle.net/derekstory/cHnXx/
/*----------- TOP NAVIGATION -----------*/
.top-links {
height: 31px;
margin: 0 0 0 0;
width: auto;
}
.top-link {
font: 7pt Georgia, serif;
color: #E1915C;
text-align:center;
text-decoration: none;
line-height: 34px;
padding: 10px;
}
#top-nav {
float: right;
margin: 0 0 0 0;
overflow: hidden;
}
/*----------- NAVIGATION -----------*/
.links {
whitespace: nowrap;
min-width: 120px;
float: right;
height: 36px;
}
.home-link {
font: 7.25pt Georgia, serif;
color: #E1915C;
text-decoration: none;
font-weight: bold;
border-right: 1px solid #E1E1E1;
text-align: center;
line-height: 36px;
width: auto;
padding: 10px;
}
.home-link:hover {
color: #369AAA;
}
.home-link-left {
border-left: 1px solid #E1E1E1;
}
.home-link-right {
border-right: 1px solid #E1E1E1;
}
#nav {
position: absolute;
float: right;
overflow: hidden;
}