I am a beginner at HTML, and I was trying to make a web page to gain experience. I wanted to create this menu but I want it to have options on both sides of it. Just like the HOME, ABOUT ME, etc. options is on the right side, I want similar options on the left side too but am not able to figure it out. Any help would be greatly appreciated.
The HTML code:
<div id="menu">
<nav class="navl" style="justify-content: right">
<ul>
<li class="navulli">
<a href="C:\Users\vivek\Desktop\html-css-course\LegendsOfTime\LOT_Home.html">
Home
</a>
</li>
</ul>
</nav>
</div>
The CSS code:
#menu {
width: 100%;
height: 30px;
background-size: cover;
justify-content: right;
margin: 0px;
padding: 0px;
}
.navl {
width: 100%;
height: 150%;
line-height: 10px;
margin-right: 60px;
display: flex;
background-color: black;
opacity: 0.6;
margin: 0px;
}
.navulli {
display: inline-block;
transition: 0.7s all;
font-family: Century Gothic, CenturyGothic, AppleGothic, sans-serif;
place-items: left;
margin: 0px;
}
.navulli:hover {
opacity: 0.4;
height: 20px;
border-radius: 20px;
}
nav ul li a {
text-decoration: none;
color: white;
padding: 30px;
justify-content: right;
font-size: calc(1rem + 0.2vw);
margin-top: 0px;
}
i {
text-decoration: none;
color: white;
justify-content: right;
padding: 15px;
font-size: calc(1rem + 0.5vw);
margin-top: 0px;
}
One possible solution would be to use a flexbox with justify-content: space-between;
nav {
background: silver;
padding: 1em;
display: flex;
justify-content: space-between;
}
nav ul {
display: inline-block;
margin: 0;
padding: 0;
}
nav ul li {
list-style: none;
display: inline;
margin: 0 1em;
}
<nav>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
<ul>
<li>four</li>
<li>five</li>
<li>six</li>
</ul>
</nav>
Related
I am trying to create a simple web page and I want the links' background covers the whole space in navbar but it covers only the text around it.
My code is here:
.navbar {
width: 105%;
height: 5vw;
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
Any suggestions?
You can remove the height from the navbar class so, it'll take the available height. Also, you can add height to .navbar li (Optional, if you want to use some custom height).
.navbar {
width: 105%;
/*height: 5vw;*/
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
/*height: 100%;(Optional)*/
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
i don't understand exact your problem but if your problem with the default margin and padding its a solution
* {
padding: 0;
margin: 0;
}
.navbar {
width: 105%;
height: 5vw;
display: flex;
flex-direction: row;
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0px;
overflow: hidden;
}
.navbar li {
float: left;
/*height: 100%;(Optional)*/
}
.navbar li a {
text-decoration: none;
color: black;
padding: 1px;
text-align: center;
}
.tab {
width: 100%;
display: flex;
background-color: grey;
justify-content: center;
align-items: center;
margin: 1px;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
I have removed some unnecessary style from your code & build this using CSS display: flex; instead of float. Now .tab is covering full height with background.
Here is the working example:
.navbar {
background-color: #008083;
z-index: 10;
}
.navbar ul {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
align-items: center;
}
.navbar li {
margin: 0;
padding: 0;
}
.navbar li a {
text-decoration: none;
color: black;
text-align: center;
padding: 10px;
display: block;
}
.tab {
background-color: grey;
}
<nav class="navbar">
<ul>
<li>Biography</li>
<li> Novels </li>
<li> Films </li>
</ul>
</nav>
I am trying to move the Status/Actions Text over to the left but no matter how much I mess with the CSS nothing works!
What it is supposed to look like
What I have so far
HTML code for that section
CSS for that section
.top {
background: #1b1b1e;
width: 1650px;
margin: auto;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 10em;
}
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
.top {
background: #1b1b1e;
width: 100%;
margin: auto;
float: left;
padding: 10px 0;
}
.top ul {
margin: 0px;
padding: 0px;
}
.top li {
list-style-type: none;
float: left;
width: 230px;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
}
.statusText {
float: right !important;
}
.actionText {
float: right !important;
max-width: 149px;
}
<div class="top">
<ul>
<li class="linkText">Link</li>
<li class="actionText">Action</li>
<li class="statusText">Status</li>
</ul>
</div>
Please apply this :
.top {
background: #1b1b1e;
display: flex;
align-items: center;
justify-content: space-between;
}
.link-wrap {
width: 300px;
padding-left: 20px;
}
.top ul {
display: flex;
width: 400px;
justify-content: space-between;
list-style-type: none;
}
.top ul li {
padding-right: 25px;
}
.top ul li a,
.link-wrap a {
display: inline—block;
color: #9c9c9c;
text-decoration: none;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
}
.link-wrap a {
width: 300px;
}
<div class="top">
<div class="link-wrap">
Link
</div>
<ul>
<li>Status</li>
<li>Action</li>
</ul>
</div>
If any changes please let me know.
you can use flexbox order property:
https://www.w3schools.com/css/css3_flexbox.asp
If you are good to go with flex, a few lines of code will fix your issue.
display: flex;
.top {
background: #1b1b1e;
/* width: 1650px; */
width: 100%;
margin: auto;
}
ul {
display: flex;
}
li {
list-style: none;
}
.statusText {
margin-left: auto;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
/* margin-right: 10em; */
}
<div class="top">
<ul>
<li>Link</li>
<li class="statusText">Status</li>
<li>Action</li>
</ul>
</div>
If you are interested to go with display inline-block only, you can use the float property.
display: inline-block;
.top {
background: #1b1b1e;
/* width: 1650px; */
width: 100%;
margin: auto;
}
li {
display: inline-block;;
list-style: none;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
/* margin-right: 10em; */
}
.float-right {
float: right;
}
<div class="top">
<ul>
<li>Link</li>
<!-- Reversed Order -->
<li class="float-right">Action</li>
<li class="float-right">Status</li>
</ul>
</div>
.top {
background: #1b1b1e;
width: 1650px;
margin: auto;
}
ul{
display:flex;
flex-direction: row-reverse;
}
li a {
display: inline—block;
padding: 1em;
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 10em;
}
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
.top {
background: #1b1b1e;
width: 100%;
margin: auto;
}
li {
display: inline-block;
}
li a {
display: inline—block;
/* padding: 1em; */
color: #9c9c9c;
text-decoration: none;
text-align: left;
font-size: 25px;
letter-spacing: 1.1px;
font-weight: bold;
margin-right: 1em;
}
ul li:not(:first-child) {
float: right;
}
</style>
<body>
<div class="top">
<ul>
<li>Link</li>
<li>Status</li>
<li>Action</li>
</ul>
</div>
</body>
</html>
Another way to achieve what you want, But I would suggest just like others to use flex box :)
I tried to play all around the codes, but I didn't find a solution. Can anyone help me to center all content inside the border box?. I tried to search everywhere and I can't find the solution. Advance Thanks.
https://i.stack.imgur.com/f17JF.png
.menubar {
width: 50vw;
height: 5rem;
background-color: #283747;
margin: auto;
border-bottom-left-radius: 10rem;
border-bottom-right-radius: 10rem;
position: relative;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
}
li.navbar {
list-style-type: none;
display: inline-block;
padding: .8rem 6rem 1rem 3rem;
text-transform: uppercase;
background: #fff;
width: 1.5rem;
height: 1.5rem;
border-radius: 1rem;
}
li.navbar a {
color: #000;
text-decoration: none;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
If you want to center the nav inside the .menubar container, give it these styles: display: flex; justify-content: center; align-items: center;. Then remove the default browser left padding on .mainMenu by giving it padding: 0.
.menubar {
width: 50vw;
height: 5rem;
background-color: #283747;
margin: auto;
border-bottom-left-radius: 10rem;
border-bottom-right-radius: 10rem;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
padding: 0;
}
li.navbar {
list-style-type: none;
display: inline-block;
text-transform: uppercase;
background: #fff;
border-radius: 1rem;
}
li.navbar a {
color: #000;
text-decoration: none;
display: inline-block;
padding: 1rem 3rem 1rem 3rem;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
Do You want this?
.menubar {
height: auto;
background-color: #283747;
margin: auto;
position: relative;
}
.mainMenu {
list-style-type: none;
text-align: center;
position: relative;
vertical-align: middle;
}
li {
list-style-type: none;
display: inline-block;
padding: 1rem 4rem 1rem 3rem;
background: #fff;
width: 1.5rem;
height: 1.5rem;
border-radius: 1rem;
margin: 30px auto;
}
li.navbar a {
color: #000;
text-decoration: none;
text-transform: uppercase;
}
<div class="menubar">
<nav>
<ul class="mainMenu">
<li class="navbar">Hub</li>
<li class="navbar">Blog</li>
<li class="navbar">News</li>
</ul>
</nav>
</div>
jsfiddle
So I try to change li's vertical position but when I do the nav bar height is affected as well. What is the way to actually do that without affecting nav bar's height?
Here's the code:
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
What is your goal here? To have the content centered or...?
It may be better to use flexbox here rather than set the padding-left: 850px; on your ul (also on your ul you could've used display: block; margin: 0 auto; to center it.) If you'd like, you can give your ul a defined height and use align-items to specify how it should be aligned vertically.
body {
margin: 0;
}
nav {
background-color: #333;
display: flex;
justify-content: center;
}
nav ul {
display: flex;
justify-content: center;
list-style: none;
margin: 0;
padding: 0;
height: 50px;
align-items: center;
}
li {
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<body>
<nav>
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
</nav>
</body>
You can add position: relative; and a value for bottom or top- in my snippet bottom: 4px;:
This reserves the space originally taken by the element (without position: relative;), but moves the element according to the top/bottom/left/right settings, without affecting other elements.
body {
margin: 0px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
padding-left: 5px;
padding-top: 10px;
background-color: #333;
overflow: hidden;
}
li {
float: left;
height: 30px;
width: 100px;
background-color: grey;
color: white;
margin-right: 4px;
text-align: center;
line-height: 30px;
font-weight: bold;
font-size: 15px;
position: relative;
bottom: 4px;
}
li a {
text-decoration: none;
color: white;
display: block;
}
ul li:hover {
opacity: 0.8;
}
<ul>
<li>Home</li>
<li>My Profile</li>
<li>Settings</li>
</ul>
Why isn't the vertical-align: middle; not working on my h1? The ul isn't aligning with the h1 and it should.
#logo {
color: white;
display: inline;
vertical-align: middle;
}
ul {
padding: 20px;
background: rgba(0,0,0,.5);
}
#title {
position: absolute;
text-align: center;
color: white;
font-size: 50px;
top: 100px;
}
#navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-image: url('../img/bg.jpg');
background-repeat: no-repeat;
background-size: 100% 100%;
height: 600px;
}
li {
float: right;
display: inline;
}
li a {
display: inline;
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
<h1 id="title">Freelance Web Developer</h1>
</div>
Because vertical-align only applies to inline and table-cell elements, not block-level elements.
In order to have your links line up with your header, you need to assign a line-height equal to the height of the header element (35.33px):
li {
line-height: 35.33px;
}
#logo {
color: white;
display: inline;
vertical-align: middle;
}
ul {
padding: 20px;
background: rgba(0, 0, 0, .5);
}
#title {
position: absolute;
text-align: center;
color: white;
font-size: 50px;
top: 100px;
}
#navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-image: url('../img/bg.jpg');
background-repeat: no-repeat;
background-size: 100% 100%;
height: 600px;
}
li {
float: right;
display: inline;
line-height: 35.33px;
}
li a {
display: inline;
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
<h1 id="title">Freelance Web Developer</h1>
</div>
It's also worth noting that having a <h1> element as a child of <ul> is invalid syntax. Only <li> elements shouold be a child of <ul>. What you should do is bring the title out of the <ul>, and float the entire <ul> element to the right.
Hope this helps! :)
Ready for a bit of a mind flip?
Here comes FLEXBOX! This could be done "better" but I didn't want to change your html structure: https://jsfiddle.net/ohbffjjm/
#navbar {
background-color: pink;
}
#logo {
margin-right: 150px;
align-self: flex-start;
}
ul {
display: flex;
align-items: center;
list-style-type: none;
}
li a {
padding: 10px 10px 10px 20px;
text-decoration: none;
color: white;
}
<div id="navbar">
<ul>
<h1 id="logo">Jordan Baron</h1>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
</div>
And a flexbox solution with a few html improvements and improvisations.
body {
margin: 0;
}
header {
color: white;
background: rgba( 0, 0, 0, 0.5 );
}
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
header,
ul {
display: flex;
align-items: center;
justify-content: space-between;
}
h1,
h2 {
margin: 0.5rem 0;
}
h1 {
padding: 0 20px;
}
h2 {
text-align: center;
}
ul {
padding: 0 10px;
}
li {
padding: 10px;
}
li a {
color: white;
text-decoration: none;
transition: color 350ms ease-in-out;
}
li a:hover {
color: gold;
}
<header>
<h1 id="logo">Jordan Baron</h1>
<ul>
<li>About Me</li>
<li>Contact</li>
<li>Projects</li>
</ul>
</header>
<main>
<h2>Freelance Web Developer</h2>
</main>