Navigation menu in reverse and not aligned with logo - html

I am trying to create a horizontal navigation menu in my vue3 application. I have 2 problems.
My menu is reversed and not in the correct order. 2) My menu does not align with the logo. Below is an image of what it looks like
<template>
<header>
<nav class="navbar">
<img src="src\assets\logo.svg" height="50px" width="50px" />
<ul>
<li>Home</li>
<li>About</li>
<li>Courses</li>
<li>Contact us</li>
</ul>
</nav>
<style scoped>
.navbar {
background-color: white;
border-radius: 30px;
}
.navbar li {
float: right;
list-style: none;
margin: 13px 20px;
font-size: 24px;
}
.navbar ul {
overflow: auto;
}
.navbar li a {
padding: 3px 3px;
text-decoration: none;
color: black;
}
</style>

You could use flexbox model instead of float like this:
.navbar {
background-color: white;
border-radius: 30px;
display: flex;
justify-content: space-between;
align-items: center;
}
.navbar li {
list-style: none;
margin: 13px 20px;
font-size: 24px;
}
.navbar ul {
display: flex;
}
.navbar li a {
padding: 3px 3px;
text-decoration: none;
color: black;
}
<nav class="navbar">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/95/Vue.js_Logo_2.svg/512px-Vue.js_Logo_2.svg.png" height="50px" width="50px" />
<ul>
<li>Home</li>
<li>About</li>
<li>Courses</li>
<li>Contact us</li>
</ul>
</nav>

Related

How to align part of the navigation content to the right?

My navigation bar's code is as follows:
index.html
<header id="header" class="flex">
<h2 id="site-name">RandomSite</h2>
<!-- NAVIGATION -->
<nav id="header-nav">
<h3 class="hidden">RandomSite's hidden navigation</h3>
<ul class="nav-list">
<li>Home</li>
<li>News</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
styles.css
/* NAVIGATION */
header {
border: 2px dashed black;
display: flex;
padding: 10px;
}
header h2 {
font-size: 18px;
font-weight: 700;
margin: 16px 0px;
}
.nav-list {
list-style-type: none;
display: flex;
float: right;
}
li {
list-style: none;
display: inline;
padding: 0px 5px 0px 0px;
}
This is what my navbar looks like. I want the unordered list contents to be aligned to the right. How do I do that?
Navigation bar screenshot
You need to add justify-content: space-between to the class .header.Also, to remove the default underline of the <a> tag you must use text-decoration:none, and for hidden the element with class .hidden use display:none.
/* NAVIGATION */
header {
border: 2px dashed black;
display: flex;
justify-content:space-between;
padding: 10px;
}
header h2 {
font-size: 18px;
font-weight: 700;
margin: 16px 0px;
}
.nav-list {
list-style-type: none;
display: flex;
float: right;
}
.hidden{
display:none;
/* visibility:hidden; */
}
li {
list-style: none;
display: inline;
padding: 0px 5px 0px 0px;
}
#site-name a {
text-decoration:none;
color: black;
}
.nav-list a {
text-decoration:none;
color: black;
}
*{font-family:sans-serif}
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<header id="header" class="flex">
<h2 id="site-name">RandomSite</h2>
<!-- NAVIGATION -->
<nav id="header-nav">
<h3 class="hidden">RandomSite's hidden navigation</h3>
<ul class="nav-list">
<li>Home</li>
<li>News</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>
</body>
</html>
I removed all the unnecessary code that you had before. I added a bit of padding to your a tags so that it will look nicer. To make your nav items move to the right, just add space-between and it will fix your problem.
* {
font-family: sans-serif;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
border: 2px dashed black;
padding: 10px;
}
header h2 {
font-size: 18px;
margin: 16px 0px;
}
header a {
text-decoration: none;
}
li > a {
color: #484b4f;
padding: 0.5rem;
}
header > h2 > a {
color: black;
}
.nav-list {
list-style-type: none;
}
li {
display: inline;
}
<header>
<h2 className="header-site-name">
RandomSite
</h2>
<nav>
<ul class="nav-list">
<li>Home</li>
<li>News</li>
<li>Blog</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</header>

How to separate items in an HTML list to make it like three elements are on one side and two on the other side in a horizontal navigation

I have already put a div tag along the place where I want to split the list items. However, when I do float left or right, it doesn't work. I want to create a navigation bar where the user can browse the website on the left and manage their account on the right. Can anyone help me?
This Is The HTML and CSS Code:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #0f0f0f;
border-radius: 50px;
}
li {
float: left;
background-color: #0f0f0f;
}
li a {
display: block;
color: #8ca2ff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
li a:hover {
background-color: #111;
}
<div class="header">
<ul>
<div class="first">
<li>Home</li>
<li>Updates</li>
<li>Blog</li>
</div>
<div class="last">
<li>Sign In</li>
<li>Login</li>
</div>
</ul>
</div>
How The Navigation Bar Looks Now
Can you please check the below code? Hope it will work for you.
As per Html standards, we can not use div directly inside ul(unordered list) so we added 2 ul inside .navigation div. With the help of flex properties, display:flex; and justify-content:space-between; we have separated items in .navigation as per your requirement.
Please refer to this link:
https://jsfiddle.net/yudizsolutions/764rdezq/1/
.navigation {
background-color: #0f0f0f;
border-radius: 50px;
overflow: hidden;
display:flex;
display: -webkit-flex;
justify-content:space-between;
-webkit-justify-content:space-between;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display:flex;
display: -webkit-flex;
}
li {
background-color: #0f0f0f;
}
li a {
display: block;
color: #8ca2ff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
li a:hover {
background-color: #111;
}
<div class="header">
<div class="navigation">
<ul>
<li>Home</li>
<li>Updates</li>
<li>Blog</li>
</ul>
<ul>
<li>Sign In</li>
<li>Login</li>
</ul>
</div>
</div>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #0f0f0f;
border-radius: 50px;
display: flex;
justify-content: space-between;
}
.last,
.first {
display: flex;
}
li {
background-color: #0f0f0f;
}
li a {
display: block;
color: #8ca2ff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 20px;
}
li a:hover {
background-color: #111;
}
<div class="header">
<ul>
<div class="first">
<li>Home</li>
<li>Updates</li>
<li>Blog</li>
</div>
<div class="last">
<li>Sign In</li>
<li>Login</li>
</div>
</ul>
</div>

How do i get my nav links responsive but also not extend past 50%?

I am attempting to turn a PSD into a website for practice, and I am trying to figure out the best way to turn the nav into code.
Here is what I am trying to recreate
HTML
<nav class="main-nav">
<img src="img/icon.png" alt="" class="logo">
<ul class="menu">
<li>Stories</li>
<li>Events</li>
<li>Places</li>
<li>Boards</li>
</ul>
</nav>
CSS
.main-nav {
display: flex;
align-items: center;
padding: 40px 0;
justify-content: space-around
}
.main-nav ul {
display: flex;
font-family: "LeagueSpartan";
text-transform: uppercase;
font-size: 12px;
}
.main-nav ul li {
letter-spacing: 8px;
}
Check this snippet, now you just need to update font-family to get the result that you want!
.main-nav {
display: flex;
align-items: center;
padding: 40px 0;
justify-content: space-around
}
.main-nav ul {
display: flex;
font-family: "LeagueSpartan";
text-transform: uppercase;
font-size: 12px;
list-style: none;
}
.main-nav ul li {
letter-spacing: 5px;
padding-right: 30px;
font-weight: bold;
}
.main-nav ul li a {
text-decoration: none;
}
<nav class="main-nav">
<img src="img/icon.png" alt="" class="logo">
<ul class="menu">
<li>Stories</li>
<li>Events</li>
<li>Places</li>
<li>Boards</li>
</ul>
</nav>
Hope this helps!

How can I center an image to the right of a navigation bar in html/css?

I'm completely new at coding so I apologize in advance for this question.
I'm trying to centrally align an image to the right of a fixed navigation menu.
Here's my code right now:
HTML:
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
display: block;
display: inline-block;
float: left;
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
I want the navigation menu to be fixed to the left, and the image to be to the right of the navigation menu but at the CENTER of the page. here's an image of what I have right now: current homepage. How can I put the image at the center of the page?
Thanks!
If you are trying the centre the whole lot then your nav and div.image should be inline-block to display them side by side. You should then put the lot in a wrapper which you can centre:
section {text-align:center}
nav,
div.image {
display: inline-block;
vertical-align:middle;
}
ul {
list-style-type: none;
position: relative;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
<section>
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
<section>
Updated...
Now that I better understand what you are after (nav on left, image centered in remaining space on the right) it seems that flex-box is the simplest solution:
section {
display:flex;
justify-content: space-between;
align-items: flex-start;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
<section>
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
<section>
Attempt 3...
Based on your comments (fyi, you really should try harder to explain your requirements) it sounds like what you want is to centre the image regardless of the nav's position. In the following example I have used margin:auto to centre the .image and position:absolute to fix the nav in the top left. Now the image in centred but the nav may overlap it depending on the viewport width.
nav {display:block; position:absolute;}
ul {
list-style-type: none;
margin: 0;
padding: 0;
text-align:left;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
.image {display:block; width:450px; margin:auto;}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
you can use your div class if class is not work then use id for div like id="image"
#media All and (max-width: 641px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 25%;
margin-left: 16%;
}
}
#media screen and (min-width: 641px) and (max-width: 800px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 23%;
margin-left: 21%;
}
}
#media screen and (min-width: 801px) and (max-width: 1024px) {
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 18%;
margin-left: 24%;
}
}
#media screen and (min-width: 1025px){
ul {
list-style-type: none;
float: left;
position: relative;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
div.image{
padding-top: 13%;
margin-left: 30%;
}
}
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
</nav>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
kindly check my codes i'll create for you
.image{
display: block;
text-align: center;
}
.image > img{
background-color: red;
}
You can also check this link for your exact code http://codepen.io/myco27/pen/dNxWWK
You can put the img element into nav and style nav with display:flex, justify-content: space-between See the code snippet
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
padding: 3px;
margin-bottom: 8px;
background-color: #33b5e5;
color: #ffffff;
font-family: "Courier";
}
nav {
display: flex;
justify-content: space-between;
}
<nav>
<ul>
<li>about</li>
<li>cv</li>
<li>adventures</li>
<li>books</li>
<li>blog</li>
<li>quotes</li>
<li>contact</li>
</ul>
<div class="image"><img src="vietnam.jpg" alt="" width="450" height="350" /></div>
</nav>

Centering Items within Navigation Bar

I've been trying to center the items within the navigation but no such luck. Every single solution turns my navigation bar from this: horizontal navigation bar to this: vertical navigation bar.
Any help would be greatly appreciated!
HTML with CSS code:
ul {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
text-align: center;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 10px 10px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
<html>
<head>
</head>
<body>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>News</li>
<li>Contact</li>
<li>About</li>
</ul>
</body>
</html>
Just remove the float from the li and make the inline-block
li {
/* float: left; */
display:inline-block;
}
The first rule of centering is..."Don't use floats"
ul {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
text-align: center;
}
li {
display: inline-block;
}
li a {
display: block;
color: white;
text-align: center;
padding: 10px 10px;
text-decoration: none;
}
li a:hover {
background-color: #111;
}
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li>News
</li>
<li>Contact
</li>
<li>About
</li>
</ul>
I removed your css on li tag with float and changed it to display and width:
li {
display: -webkit-inline-box;
width: 60px;
}
https://i.stack.imgur.com/LbYd4.png`
I hope this helped you #C. Lagos