Align logo in left with link on the right navbar - html

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>

Related

Navbar hover effect no longer works when I insert a image

I have a navbar inside a header tag. the header tag is flex. the navbar too. in the navbar i have three a tags with the display value inline-block; and a padding in the height and width. So far so good. When i hover the links the hover effect is shown over the whole height.
The problem: If I add an image to the first link, I can't make the image higher than 10 px because the padding affects the entire navbar height. What I do not want.
Question: How can I add the image to the link without it affecting the height of the navbar?
My code
body {
margin: 0;
padding: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: center;
}
.navbar a:not(:first-child) {
display: inline-block;
}
.navbar a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
  margin-top: 180px;
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
<div class="flex">
<div>
<img src="https://via.placeholder.com/30">
</div>
<div>10000</div>
</div>
</a>
News
Contact
</nav>
</header>
<main class="main">
text
</main>
</div>
expected
body {
margin: 0;
pading: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: center;
}
.navbar a:not(:first-child) {
display: inline-block;
}
.navbar a {
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
  margin-top: 180px; /* Add a top margin to avoid content overlay */
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
10000
</a>
News
Contact
</nav>
</header>
<main class="main">
xca
</main>
</div>
Use flex behavior to align and stretch instead of additional markups
In the code snippet below, I removed the extra markup in the first a element that contains the img. Instead, I made all a tags display: inline-flex and removed vertical padding in the first one. Then, using the parent nav element's align-items property, I ensured each a tag has the same full height for consistent hover effect.
body {
margin: 0;
padding: 0;
}
header {
display:flex;
justify-content: space-between;
align-items: center;
background: green;
position: fixed;
top: 0;
overflow: hidden;
width:100%;
}
.logo {
background: yellow;
display: flex;
align-items: center;
}
.navbar {
background-color: #333;
display: flex;
align-items: stretch;
}
.navbar a {
display: inline-flex;
}
.navbar a {
color: #f2f2f2;
justify-content: center;
align-items: center;
padding: 14px 16px;
text-decoration: none;
font-size: 12px;
}
.navbar a:first-of-type {
padding-top:0;
padding-bottom:0;
}
.navbar a:hover {
background: #ddd;
color: black;
}
.flex {
gap:10px;
display: flex;
align-items: center;
font-size: 12px;
}
.main {
  margin-top: 180px;
color: color;
height:50vh;
background: black;
}
<div>
<header>
<div class="logo">
<img src="https://via.placeholder.com/40">Logo
</div>
<nav class="navbar">
<a href="#home">
<img src="https://via.placeholder.com/30">
10000
</a>
News
Contact
</nav>
</header>
<main class="main">
text
</main>
</div>

CSS - Border stretched to whole height of navbar

I am trying to make a border on the right of most of my LIs (that are also anchor tags) fill the entirety of the div vertically, with a width of 1em like this (my figma mockup):
However, all I am getting currently is this:
Here is my (S)CSS:
.navbar-main {
margin-top: 2em;
display: flex;
background-color: hsl(206, 97%, 13%);
color: hsl(0, 0%, 100%);
border-radius: 34px;
width: 90vw;
height: 3em;
margin-left: auto;
margin-right: auto;
justify-content: space-between;
text-align: center;
.links {
display: flex;
justify-content: flex-start;
margin-left: 2em;
align-items: center;
}
ul {
display: inherit;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
gap: 1em;
height: 100%;
}
/* Add a vertical border to the right of all of the lis that stretches to the whole of the div vertically */
li {
border-right: 1px solid hsl(0, 0%, 100%);
}
.langselect {
margin-right: 2em;
display: inherit;
justify-content: flex-end;
align-items: center;
}
.icon {
margin-right: 0.5em;
height: 1em;
width: 1em;
font-size: inherit;
text-align: center;
display: inline-block;
vertical-align: middle;
}
}
And here is my HTML (REACT):
<div className="navbar-main">
<div className="links">
<ul> {/*TODO: Remember to put icons before the a tags! (USE BOOTSTRAP ICONS!) */}
<li>
<a href="#">
<FaHome className="home icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaBookOpen className="book icon"/>
Portfolio/CV
</a>
</li>
<li>
<a href="#">
<FaPuzzlePiece className="puzzle icon"/>
!?#!#*$%
</a>
</li>
</ul>
</div>
<div className="langselect">
<FaGlobe className="world icon"/>
<p>Language Select</p>
</div>
</div>
All help is appreciated, thanks a lot.
Turns out after a bit of back and forth debugging and writing code, I found out that I could do this:
li {
display: inherit;
height: 100%;
border-right: 1px solid hsl(206, 94%, 20%);
padding-right: 1em;
a {
margin-top: auto;
margin-bottom: auto;
}
}
li:last-child {
border-right: none;
padding-right: 0;
}
This works flawlessly too, as seen here:
Thanks anyway for your guys' help!

Unable to style links with CSS [duplicate]

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

Position items in a navbar

I am a total beginner in coding & try to create a webpage for a student project, using React.
I have a problem while creating the navbar for the page. How do I position the items (Home, Project, Team, Kontakt) to the right side of the bar?
This is what it currently looks like:[1]: https://i.stack.imgur.com/gUJPi.png
Here is the code I am currently using:
const navbar = props => (
<nav className="navbar">
<div className="container" >
<div className="navbar__bubble">
<IoIosChatbubbles size="2.3em"></IoIosChatbubbles>
</div>
<div className="navbar__title">
<h2>Our project</h2>
</div>
<div className="navbar__navigation-items">
<ul>
<li><NavLink to="/" activeClassName="is-active" exact={true}>Home</NavLink></li>
<li><NavLink to="/projekt" activeClassName="is-active">Project</NavLink></li>
<li><NavLink to="/team" activeClassName="is-active" exact={true}>Team</NavLink></li>
<li><NavLink to="/kontakt" activeClassName="is-active">Kontakt</NavLink></li>
</ul>
</div>
</div>
</nav>
);
& scss code for the container and the navbar:
.container {
max-width: 115rem;
margin: 0 10rem;
padding: 0 $m-size;
display: flex;
}
and
.navbar {
background: #E3E9EE;
position: fixed;
width: 100%;
top: 0;
padding: .7rem 0;
height: 80px;
display: flex;
border-bottom: 1px solid lighten(#2C465F, 30%);
}
.navbar__bubble {
color: #2C465F;
cursor: pointer;
margin-top: 20px;
}
.navbar__title {
color: #2C465F;
cursor: pointer;
margin: 30px;
margin-left: 10px;
margin-top: 5px;
font-size: $m-size;
}
.navbar__navigation-items {
margin-top: 30px;
font-size: $m-size;
}
.navbar__navigation-items ul {
list-style: none;
margin: 0;
padding: 0;
display: grid;
grid-template-columns: repeat(4, auto);
grid-gap: 20px;
list-style: none;
float: right;
}
.navbar__navigation-items a:hover,
.navbar__navigation-items a:active {
color: #2C465F;
}
.navbar__subtitle {
margin-top: 28px;
}
Thanks in advance for your help! :) (
Wrap you left elements and use flexbox
.container {
display: flex;
align-items: center;
justify-content: space-between;
}
const navbar = props => (
<nav className="navbar">
<div className="container" >
<div className="navbar__left">
<div className="navbar__bubble">
<IoIosChatbubbles size="2.3em"></IoIosChatbubbles>
</div>
<div className="navbar__title">
<h2>Our project</h2>
</div>
</div>
<div className="navbar__navigation-items">
<ul>
<li><NavLink to="/" activeClassName="is-active" exact={true}>Home</NavLink></li>
<li><NavLink to="/projekt" activeClassName="is-active">Project</NavLink></li>
<li><NavLink to="/team" activeClassName="is-active" exact={true}>Team</NavLink></li>
<li><NavLink to="/kontakt" activeClassName="is-active">Kontakt</NavLink></li>
</ul>
</div>
</div>
</nav>
);
I would add flex: 1 to the .navbar__title. It will push everything after it to the right as much as it can.
Use flexbox for the items. I did change the code a bit, and made it HTML-CSS friendly, so adapt it for React (className, RouterLinks etc).
Summary: The Nav has display: flex applied and it has 2 child elements (Logo+Title and Menu), and I added justify-content: space-between.
In the <ul> class, I added another display: flex so the items are behaved as a row. By default, the flex-direction is row. If you want anything as column, you must add flex-direction: column.
Here is a working snippet:
* {
list-style: none;
}
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
.navbar__navigation-items ul {
display: flex;
}
.navbar__navigation-items ul li {
margin-right: 10px;
}
<nav class="navbar">
<div class="container">
<div class="navbar__bubble">
<IoIosChatbubbles size="2.3em"></IoIosChatbubbles>
</div>
<div class="navbar__title">
<h2>Our project</h2>
</div>
</div>
<div class="navbar__navigation-items">
<ul>
<li>Home</li>
<li>Project</li>
<li>Team</li>
<li>Kontakt</li>
</ul>
</div>
</nav>
All you need to do, is to add margin-left: auto for your navbar__navigation-items style.
That will position your navbar__navigation-items to the right and push everything else within the same container to the left.
Another option would be to use flexbox. For your container apply display: flexbox to it. and add justify-content: space-between; and it will also work. But this will control all other elements within container to behave based on that call.
Check below, I've done it and all works.
.navbar {
background: #E3E9EE;
position: fixed;
width: 100%;
top: 0;
padding: .7rem 0;
height: 80px;
display: flex;
border-bottom: 1px solid lighten(#2C465F, 30%);
}
.container {
max-width: 115rem;
padding: 0 $m-size;
display: flex;
width: 100%;
}
.navbar__bubble {
color: #2C465F;
cursor: pointer;
margin-top: 20px;
}
.navbar__title {
color: #2C465F;
cursor: pointer;
margin: 30px;
margin-left: 10px;
margin-top: 5px;
font-size: $m-size;
}
.navbar__navigation-items {
margin-top: 30px;
font-size: $m-size;
margin-left: auto;
}
.navbar__navigation-items ul {
list-style: none;
margin: 0;
padding: 0;
display: grid;
grid-template-columns: repeat(4, auto);
grid-gap: 20px;
list-style: none;
}
.navbar__navigation-items a:hover,
.navbar__navigation-items a:active {
color: #2C465F;
}
.navbar__subtitle {
margin-top: 28px;
}
<nav class="navbar">
<div class="container" >
<div class="navbar__title">
<h2>Our project</h2>
</div>
<div class="navbar__navigation-items">
<ul>
<li><a>One</a></li>
<li><a>Two</a></li>
<li><a>Three</a></li>
<li><a>Four</a></li>
</ul>
</div>
</div>
</nav>
there is multiple ways to do it but adding
float: right
to
.navbar__navigation-items {
margin-top: 30px;
font-size: $m-size;
float: right;
}
should do the trick,
might need to add width: 100% to the container aswell
.container {
max-width: 115rem;
margin: 0 10rem;
padding: 0 $m-size;
display: flex;
width: 100%;
}
Edit:
i agree that float is not the best tool but i suggested it because he already use it in his code and it required only css changes but https://stackoverflow.com/a/63427704/8382007 answer with width to 100%
.container {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
surely is better

full-bleed flexbox header with nested nav -- absolute positioning bad practice?

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