I am making making a full-bleed cover where I want 100% of the viewport on load to have an image, and then I want the header text to be centered.
I used flexbox to do this, the problem is, I also want the navbar in the full-bleed.
I get whitespace when I nest the nav in the header, but if I keep it in, I can't use flex-box to position my header
My last solution was to use absolute positioning and move it over a bit.. which is probably bad practice. I can't come up with a solution on my own other than these -- and I think absolute positioning is bad practice.
I made a codepen with a snippet. and below is my regular code.
I hope this is enough information - the idea is I want my nav inside the full bleed without it disrupting. The current codepen has absolute positioning but I would rather not use that. -- Did I miss something simple or is this a common problem?
I am not opposed to not using flexbox (I just started to use this) But I think there is a solution with flexbox that I am just not aware. Also I know my nav in generally is a little hacky
Here is my codepen and snippet
http://codepen.io/willcodes/pen/oLKZEL
HTML:
<nav>
<div class="nav-left">
<div class="logo">
<img src="assets/logo.png" alt="">
</div>
<ul>
<li>Home</li>
<li>FAQ</li>
<li>Portfolio</li>
<li>Blog</li>
<li>Contact
</ul>
</div>
<ul class="nav-right">
<li><i class="fa fa-globe" aria-hidden="true"></i>ENG</li>
<li><i class="fa fa-search" aria-hidden="true"></i></li>
</ul>
</nav>
<header>
<div class="heading">
<div class="wrapper">
<h2>Trendy, Versatile, Minimal Solution to Style up Your Business</h2>
<h1>Designer. Photographer. Developer.</h1>
<button class="info">More Info</button>
</div>
</div>
</header>
<script src="https://use.fontawesome.com/902375b958.js"></script>
<script src="js/main.js"></script>
</body>
body, html {
margin: 0;
padding: 0;
width: 100%;
font-size: 10px;
}
h1, h2, h3, h4, ul {
margin: 0;
padding: 0;
}
.wrapper {
width: 70%;
margin: 0 auto;
max-width: 1280px;
}
.nav-left {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
nav {
position:absolute;
left:5%;
width: 90%;
margin: 0 auto;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
}
nav ul {
padding-top: 1%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
nav ul.nav-right {
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
}
nav ul.nav-right i.fa-globe {
display: inline;
margin-right: 5px;
}
nav ul.nav-right li {
margin-top: 5px;
margin-right: 10px;
}
nav ul li {
margin-top: 5px;
margin-right: 2%;
list-style: none;
font-size: 1.5rem;
font-family: "Raleway", sans-serif;
text-transform: uppercase;
color: white;
}
nav ul li a {
color: white;
text-decoration: none;
}
.logo {
margin-right: 5%;
padding-top: 1%;
}
.logo img {
max-width: 100%;
display: block;
}
header {
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)), url("../Images/hero.jpg") no-repeat center, black;
background-attachment: fixed;
background-size: cover;
height: 100vh;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.heading {
color: white;
text-align: center;
padding: 25px 50px;
margin: auto;
}
.heading h2 {
font-weight: 300;
font-family: "Damion", cursive;
font-size: 2rem;
}
.heading h1 {
font-family: "Raleway", sans-serif;
text-transform: uppercase;
font-weight: 600;
font-size: 4rem;
letter-spacing: 3px;
}
Related
My header should be fixed on the page so i couldn't use float:right;. I'm %150 newbie around here. Logo should be on right side of the navbar and also responsive. I tried margin, float and other flex properties. I'm just going to be mad. Where is the mistake.
#import url('https://fonts.googleapis.com/css2?family=Oswald&display=swap');
body {
margin: 0;
font-family: 'Trebuchet MS', sans-serif;
background-color: #efefef;
}
.wrapper {
position: relative;
}
.header-logo {
width: 20vw;
height: 20vw;
}
header {
width: 100%;
height: 4rem;
background: #609F92;
position: fixed;
display: flex;
font-family: Oswald, sans-serif;
font-size: 1.5rem;
}
#header-img {
width: 100%;
height: 100%;
border-radius: 50%;
box-shadow: 1px 1px 2px 1px;
}
#nav-bar {
display: flex;
flex-direction: row;
}
#nav-bar ul {
display: flex;
flex-direction: row;
align-items: center;
list-style: none;
}
#nav-bar li {
margin: 10px;
}
<div class="wrapper">
<header id="header">
<nav id="nav-bar">
<ul>
<li>Features</li>
<li>About Us</li>
<li>Contact</li>
</ul>
<div class="header-logo">
<img id="header-img" src="https://thumbnails-photos.amazon.com/v1/thumbnail/lFJOXJpuTKGgtJYa9-wScA?viewBox=943%2C943&ownerId=A4PYAHHROL8LR&groupShareToken=OSTx_M1GRRS1y_rPWtVfGA.8mpQdgJWAet53NrSPN2TyS">
</div>
</nav>
</header>
</div>
The issue is mainly caused because you nesting so many flexboxes within each other. As such the elements will not span the entire available width automatically.
Give the nav tag a width of 100% to fill out the entire containers width: #nav-bar { width: 100% }
to align the logo to the right within a flexbox use margin-left: auto: .header-logo { margin-left: auto; }
Also you could improve your code by removing the ID from the nav element and target the nav element directly. As semantically you should only have one nav element it would be unecessary to asign an id to it. Same rule also counts for the header element.
Then you could remove display: flex; from the header which has only one child element in the first place and as such is useless. IMHO it would be smarter though to close the nav with the ul as the logog is semantically not part of the navbar.
Last but not least you could remove flex-direction: row as it is the default value anyways.
#nav-bar {
width: 100%;
}
.header-logo {
margin-left: auto;
}
/* original CSS */
#import url('https://fonts.googleapis.com/css2?family=Oswald&display=swap');
body {
margin: 0;
font-family: 'Trebuchet MS', sans-serif;
background-color: #efefef;
}
.wrapper {
position: relative;
}
.header-logo {
width: 20vw;
height: 20vw;
}
header {
width: 100%;
height: 4rem;
background: #609F92;
position: fixed;
display: flex;
font-family: Oswald, sans-serif;
font-size: 1.5rem;
}
#header-img {
width: 100%;
height: 100%;
border-radius: 50%;
box-shadow: 1px 1px 2px 1px;
}
#nav-bar {
display: flex;
flex-direction: row;
}
#nav-bar ul {
display: flex;
flex-direction: row;
align-items: center;
list-style: none;
}
#nav-bar li {
margin: 10px;
}
<div class="wrapper">
<header id="header">
<nav id="nav-bar">
<ul>
<li>Features</li>
<li>About Us</li>
<li>Contact</li>
</ul>
<div class="header-logo">
<img id="header-img" src="https://thumbnails-photos.amazon.com/v1/thumbnail/lFJOXJpuTKGgtJYa9-wScA?viewBox=943%2C943&ownerId=A4PYAHHROL8LR&groupShareToken=OSTx_M1GRRS1y_rPWtVfGA.8mpQdgJWAet53NrSPN2TyS">
</div>
</nav>
</header>
</div>
I also created a Codepen for you where I corrected the code to be semantically correct and to shroten it to the necessary lines: Codepen
I wanna to put a logo in the left of the navigation.
The links are set to justify-content: flex-end;
I tried to make a div element and make it important with !important property.
.navbar {
background-color: #242931;
top: 0%;
text-align: center;
justify-content: flex-end;
display: flex;
}
.left-nav {
justify-content: flex-start !important;
display: flex !important;
}
.navbar a {
color: #b7c2d0;
font-family: cubano;
font-size: 1.15rem;
text-decoration: none;
margin-right: 15px;
margin-left: 15px;
padding: 24px;
}
.navbar a:hover {
-webkit-background-clip: text;
background-image: linear-gradient(to right, #ff6e00, #ff9400, #ffb900, #f8dc00, #e9ff00);
background-clip: text;
color: transparent;
}
<div class="navbar">
<div class="left-nav">
example
</div>
Guides
Clips
Leaderborard
Support the server
Help
Rules
</div>
You don't need any div
simply assign margin-right: auto
to the first a (logo)
.navbar {
display: flex;
gap: 2em;
}
.navbar a:first-child {
margin-right: auto;
}
<div class="navbar">
LOGO
two
three
</div>
If you want to separate those two groups, wrap the actual navigation into a <nav> tag (and for better SEO), and use instead a margin-left: auto on it. The principle is the same:
.navbar {
display: flex;
}
.navbar nav {
display: flex;
gap: 2em;
margin-left: auto;
}
<div class="navbar">
LOGO
<nav>
two
three
</nav>
</div>
Nest the right-nav in a div also. Then you can use justify-content: space-between; which will space out the two divs. Then you can add align-items: center; to make them align.
.navbar {
background-color: #242931;
top: 0%;
text-align: center;
justify-content: space-between;
display: flex;
align-items: center;
}
.left-nav {
justify-content: flex-start !important;
display: flex !important;
}
.navbar a {
color: #b7c2d0;
font-family: cubano;
font-size: 1.15rem;
text-decoration: none;
margin-right: 15px;
margin-left: 15px;
padding: 24px;
}
.navbar a:hover {
-webkit-background-clip: text;
background-image: linear-gradient(to right, #ff6e00, #ff9400, #ffb900, #f8dc00, #e9ff00);
background-clip: text;
color: transparent;
}
<div class="navbar">
<div class="left-nav">
example
</div>
<div class="right-nav">
Guides
Clips
Leaderborard
Support the server
Help
Rules
</div>
</div>
This question already has answers here:
CSS child selector higher precedence than class selector?
(3 answers)
Closed 1 year ago.
Ok, sorry in advance for the question for being silly and very specific, but I just cannot figure this out.
I am simply trying to style two <li> elements that are positioned as such: <nav><ul><li>text</li></ul></nav>. Also, I want to style the footer to be white.
I don’t know what is wrong in my code, what is preventing it from happening.
#import url('https://fonts.googleapis.com/css2?family=Roboto:wght#400;700&display=swap');
html,
body {
height: 100vh;
font-family: 'Roboto', sans-serif;
color: #ffffff;
background-color: #0e2a47;
}
.Titlebanner {
display: block;
width: 50%;
margin-left: auto;
margin-right: auto;
text-align: center;
border-color: #48ffd5;
border-radius: 1em;
}
.Titlebanner h1>a {
color: #ffffff;
font-weight: 700;
font-size: 2em;
text-decoration: none;
border-bottom: 2px solid #48ffd5;
}
ul {
display: flex;
flex-direction: row;
justify-content: center;
list-style: none;
padding: 0;
}
nav li {
list-style: none;
display: flex;
margin: 2em;
padding: 1em;
border-radius: 1em;
border: 2px solid #48ffd5;
}
/* --------------Here is what I’ve tried to modify but doesn’t work-------*/
a:hover,
a:visited,
a:link,
a:active {
color: white;
text-decoration: none;
}
/*---------------------------------------*/
.body {
display: flex;
flex-direction: row;
}
.ranking {
width: 8%;
height: 4em;
background-color: grey;
align-items: center;
position: -webkit-sticky;
position: sticky;
top: 0.5em;
}
.ranking>ul {
padding: 0;
display: flex;
flex-direction: column;
}
.ranking>ul>li {
margin: auto
}
.Analysis {
display: flex;
flex-direction: row;
margin: auto;
width: 80%;
justify-content: center;
text-align: justify;
}
/*---------------------- and here for the footer -------*/
footer>a {
display: block;
width: 30%;
margin-left: auto;
margin-right: auto;
text-align: center;
color: white;
}
/*-----------------------------------------------*/
<body>
<header>
<div class="Titlebanner">
<h1>Impact of Privacy Policies on Users’ Lives</h1>
</div>
<!------------- here is the part I’m trying to style----->
<nav>
<ul>
<li>Results</li>
<li>Analysis</li>
</ul>
</nav>
<!----------------------------------------------------->
</header>
<div class="body">
<div class="ranking" id="ranking">
<ul>
<li>First Place</li>
<li>Second Place</li>
</ul>
</div>
<div class="Analysis">
text
</div>
</div>
</body>
<!----------------- and the footer I’m trying to style as well------->
<footer>
<span class="">
About us
</span>
</footer>
<!------------------------------------------------------------->
You are trying to access the a tag that is a direct child in your footer use footer a or footer > span > a instead
I am not sure why your header styling is not working, I guess it has to do with specificity try simplifying your selector header > h1 > a to header a and change a:hover to header a:hover
also try not to use capital symbols when naming classes
i have the following code
header {
width: 100%;
height: 65px;
background: #fff;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
display: flex;
justify-content: space-between;
align-items: center;
color: #252c3a;
}
#menu {
width: 100%;
display: flex;
margin-left: 28%;
}
#menu div {
width: 100px;
height: 65px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
<header>
<div id="logo">
<img src="img/header/logo.png" alt="Logo">
</div>
<div id="menu">
<div>Home</div>
<div>Club-Life</div>
<div>Training</div>
<div>Instructors</div>
<div>Contact</div>
</div>
Chrome inspect
The width of the other blocks is 100%, but the header width gets bigger than the block below. I use justify-content: space-between.
Remove width & margin
Add flex-wrap on the header
header {
width: 100%;
height: 65px;
background: #fff;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
display: flex;
justify-content: space-between;
align-items: center;
color: #252c3a;
flex-wrap:wrap;
}
#menu {
display: flex;
flex-wrap:wrap;
}
There are few things we need to do:
In header:
1. Remove width
In #main:
1. Remove width
2. Remove margin
In #menu div:
1. Remove everything and just add margin left
Demo: https://codepen.io/Bibeva/pen/povddJr
Final code:
header {
height: 65px;
background: #fff;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
display: flex;
justify-content: space-between;
align-items: center;
color: #252c3a;
}
#menu {
display: flex;
}
#menu div {
margin: 0 0 0 30px;
}
#menu {
display: flex;
}
that's all , Can you try this ?
I want to make a logo which looks like this:
but I can't get it to work, this is what I have at the moment:
I want the logo on the left to be the same as the first picture I uploaded, does anyone know how to do this?
I tried with vertical-align: middle which doesn't work, and I tried display: flex and then align: center but that doesn't work either.
Here is my attempt:
header {
padding-top: 24px;
padding-bottom: 24px;
background: #1b1b2e;
width: 100%;
border-bottom: 1px solid black;
align-items: center;
display: grid;
grid-template-columns: 1fr 3fr;
}
header a {
text-decoration: none;
display: flex;
justify-content: space-between;
color: white;
}
header img {}
#nav {
display: flex;
justify-content: space-around;
}
#logo {
display: flex;
justify-content: space-around;
}
<header>
<div id="Logo"> <img src="img/logo_shape.png" alt="Logo">
<h1>Dublin apps</h1>
<h3>Ipad applications</h3>
</div>
<div id="nav">
Home Ipad Apps
Demonstrations
Leogards Media
connect us
</div>
</header>
As already mentioned Rickard Elimää your CSS targets #logo but your id says "Logo".
We must also put
flex-direction: column;
and some other adjustment to make it work.
I also created the graphic element in the css logo as it is very simple, if you want an image instead of the pseudo element you can put it inside h1 like this:
<h1><img src="path_to.png" alt="i">Dublin apps</h1>
and remove the css rules for the pseudo element.
#Logo h1:before
You will need to change the logo font to match the one in the image
header {
padding-top: 24px;
padding-bottom: 24px;
background: #1b1b2e;
width: 100%;
border-bottom: 1px solid black;
align-items: center;
display: grid;
grid-template-columns: 1fr 3fr;
}
header a {
text-decoration: none;
display: flex;
justify-content: space-between;
color: white;
}
#nav {
display: flex;
justify-content: space-around;
}
#Logo {
display: flex;
justify-content: space-around;
color: white;
flex-direction: column;
}
#Logo h1, #Logo h3 {
margin: 0;
}
#Logo h1 {
font-size: 24px;
display: flex;
align-items: center;
font-weight: 300;
}
#Logo h3 {
font-size: 14px;
padding-left: 24px;
font-weight: 300;
}
#Logo h1:before {
content: "i";
display: inline-block;
font-size: 14px;
color: black;
background-color: white;
width: 20px;
height: 20px;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50% 0 50% 50%;
margin-right: 4px;
}
<img src="https://i.stack.imgur.com/NPCDE.png" alt="">
<header>
<div id="Logo">
<h1>Dublin apps</h1>
<h3>Ipad applications</h3>
</div>
<div id="nav">
Home Ipad Apps
Demonstrations
Leogards Media
connect us
</div>
</header>
Try this answer.
header {
padding: 10px 20px;
background: #1b1b2e;
width: 100%;
border-bottom: 1px solid black;
align-items: center;
display: grid;
grid-template-columns: 1fr auto;
}
header img {
width: 25px;
margin-right: 5px;
}
#nav {
display: flex;
justify-content: space-around;
}
#nav a {
text-decoration: none;
color: white;
padding: 3px 5px;
margin: 0 2px;
}
#nav a.active {
background-color: #fff;
color: #111;
border-radius: 2px;
}
#logo {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
}
.logo-text {
display: inline-flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
}
.logo-text h1, .logo-text h3 {
margin: 0;
color: #fff;
}
.logo-text h1 {
font-size:16px;
}
.logo-text h3 {
font-size:14px;
}
<header>
<div id="logo">
<img src="https://d1nhio0ox7pgb.cloudfront.net/_img/o_collection_png/green_dark_grey/512x512/plain/leaf.png" alt="Logo">
<div class="logo-text">
<h1>Dublin apps</h1>
<h3>Ipad applications</h3>
</div>
</div>
<div id="nav">
Home Ipad Apps
Demonstrations
Leogards Media
connect us
</div>
</header>
enter image description hereUse this css
#logo img{
margin:0 auto;
display:table;
}