How can I move my navigation bar to a different place? - html

I'm trying to make my nav bar be horizontal and centered. Right now, it's all smushed to the right of the website. How do I control where the bar is located?
Also, why can't I just have all my css under #nav (why do I need #nav ul li, etc?)
#nav{
width: 90%;
text-align: center;
font-size: 35px;
text-align: center;
}
#nav ul li{
display: inline;
height: 60px;
text-align: center;
}
#nav ul li a{
padding: 40px;
background: #25ccc7;
color: white;
text-align: center;
}
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>

You need the different css selectors because not all the styles are meant to be applied to the surrounding container #nav, but to certain elements inside it. With pure CSS, it is not possible to nest rules. If nesting is what you were asking for, take a look at LESS or SASS (DuckDuckGo is your friend).
Your list items were pushed a little to the right because that is the natural behaviour of list items unless you overwrite the responsible css attributes margin and / or padding (depending on the browser). So just reset both to 0 in your CSS for the list items.
#nav {
background-color: #e8e8e8;
width: 90%;
font-size: 35px;
text-align: center;
margin: 0 auto;
}
#nav ul {
display: inline-block;
white-space: nowrap;
margin: 0;
padding: 0;
}
#nav ul li {
display: inline;
text-align: center;
margin: 0;
padding: 0;
}
#nav ul li a {
padding: 40px;
background: #25ccc7;
color: white;
text-align: center;
}
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>

Related

How do i close the letter gap accross my navbar at the top

So there is the letter spacing/gap between each word and i want to minimize that, but when i try to do it the only thing that shrinks is the button itself.
.navbar {
position: fixed;
top: 0;
right: 7%;
z-index: 10;
display: flex;
text-align: center;
display: table;
}
.navbar ul {
flex: 1;
text-align: right;
padding: 40px;
background: transparent;
}
.navbar ul li {
display: inline-block;
list-style: none;
margin: 10px 30px;
background: transparent;
}
.navbar ul li {
display: inline-block;
list-style: none;
margin: 10px 30px;
background: transparent;
}
.navbar ul li a {
color: #6dffe7;
text-decoration: none;
letter-spacing: 1px;
font-size: 15px;
cursor: pointer;
}
body { background: black; }
<div class="page">
<nav class="navbar">
<ul>
<div class="download-btn">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Contact</li>
<li> Download Resume</li>
</div>
</ul>
</nav>
</div>
Thank you for your help
I think you are trying to recreate the navbar as depicted in the image provided. As such, you need to following rules:
Horizontal navbar with a fixed height (I assumed it to be 100px).
All links except for the button should appear on the left and separated by some gap.
The "Download Resume" button needs to appear on the right side of your navbar.
There should be some padding at the left and right side of the navbar (I assumed this to be 2rem).
To achieve, this you need to set flex layout on your navbar, so that we can use the align-items: center to center the links vertically inside the navbar. We then need to set flex layout on the ul itself, and give it flex-direction: row with some gap: 2rem.
Now to place the button on the far right side of your navbar, you need to remove it from the ul inside the navbar, and place it as a sibling below it. And set justify-content: space-between on your navbar. This should move the links to far left, and the button to far right.
Additionally, we can style the visuals by giving navbar a background-color and color. We then inherit this color onto the anchor links a. We also set list-style: none and text-decoration: none on the ul and a respectively, to achieve the look of the image linked in the question.
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.navbar {
padding: 0 2rem;
position: fixed;
top: 0;
width: 100%;
background-color: #12182b;
color: #6dffe7;
height: 100px;
display: flex;
align-items: center;
justify-content: space-between;
}
.navbar ul {
display: flex;
flex-direction: row;
align-items: center;
list-style: none;
gap: 2rem;
}
.navbar ul a {
font-size: 0.9em;
color: inherit;
text-decoration: none;
}
.navbar .btn {
font-size: 0.9em;
border: 2px solid #6dffe7;
padding: 0.6em;
text-decoration: none;
color: inherit;
font-weight: bold;
}
<div class="page">
<nav class="navbar">
<ul>
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Contact</li>
</ul>
Download Resume
</nav>
</div>
Looking at the image it seems like you want to adjust nav items spacing instead of letter spacing/gap.
You can try to adjust paddings/margins on navbar ul and the li child items.
Also, you have duplicate display prop on .navbar you can remove one.
.navbar {
background-color: #12182b;
position: fixed;
top: 0;
left: 0;
z-index: 1;
display: flex;
text-align: center;
}
.navbar ul {
flex: 1;
text-align: right;
padding: 20px;
background: transparent;}.navbar ul li {
display: inline-block;
list-style: none;
margin: 10px 20px;
background: transparent;
}
.navbar ul li {
display: inline-block;
list-style: none;
margin: 10px 20px;
background: transparent;
}
.navbar ul li a {
color: #6dffe7;
text-decoration: none;
letter-spacing: 1px;
font-size: 15px;
cursor: pointer;
}
<nav class="navbar">
<ul>
<div class="download-btn">
<li>Home</li>
<li>About</li>
<li>Work</li>
<li>Contact</li>
<li>
Download Resume </li>
</div>
</ul>
</nav>
it seems to me you use bootstrap if you do then you will to need to use !important after any styles in css

I can't change the height or text-align in navbar items

I'm really new to this whole CSS and HTML and i'm trying to make a simple navbar with what I have learned.
The problem is, I have the navbar items centered and I was happy with it. Then I decided to add this hover option so the background color of each item would change when hovering on it.
The issue is I cannot change the height or alignment of the boxes.
weird box
#header {
background: #9842f5;
position: fixed;
width: 100%;
padding: 20px 0;
text-align: center;
}
nav ul {
font-family: Arial;
display: inline;
text-align: center;
margin: 0 20px;
}
nav ul:hover {
background: blue;
height: 20px important;
}
nav li {
display: inline;
opacity: 0.78;
text-align: center;
}
<nav id="header">
<ul>
<li>Home</li>
</ul>
<ul>
<li>Contact Info</li>
</ul>
<ul>
<li>NUKE</li>
</ul>
</nav>
The hover effect should be added to the list-items (<li>). To get more space, you can add padding instead of changing the height.
Also, only add one <ul> instead of 3.
#header {
background: #9842f5;
position: fixed;
width: 100%;
padding: 20px 0;
text-align: center;
}
nav ul {
font-family: Arial;
display: inline;
text-align: center;
margin: 0 20px;
}
nav li:hover{
background: blue;
}
nav li {
display: inline;
opacity: 0.78;
text-align: center;
padding: 20px;
}
<nav id="header">
<ul>
<li>Home</li>
<li>Contact Info</li>
<li>NUKE</li>
</ul>
</nav>

Why aren't my <a> elements centered within my <li> navigation elements?

I am creating a website using a mobile-first approach. I am currently styling the navigation bar, which is comprised of a ul with five li elements and an a element within each li. For the mobile layout, I want the navigation to be perfectly centered. The nav element and the li elements appear to be perfectly centered; however, the a elements are not centered within each li... They are skewed toward the right. How can I correct this?
Here is my HTML:
<nav>
<ul>
<li>Home</li>
<li>Programs</li>
<li>About Us</li>
<li>Why</li>
<li>Contact Us</li>
</ul>
</nav>
And here is my CSS:
nav {
width: 15%;
margin: 0 auto;
padding-top: 0.5em;
}
nav ul {
list-style-type: none;
}
nav li {
max-width: 100%;
margin: 1em;
text-align: center;
border-radius: 10px;
}
nav a {
display: inline-block;
width: 100%;
margin: 0 auto;
padding: 0.5em;
color: inherit;
text-decoration: none;
}
And here is an image of what the nav currently looks like in the browser (Chrome):
Set the li's margin and padding to 0;
Add the following inline or in an external style sheet to nav a
margin: 0px;
text-align: center;
Try this :
nav ul {
display: block;
overflow: hidden;
padding: 0px;
list-style-type: none;
}
nav a {
display: block;
width: 100%;
margin: 0 auto;
color: inherit;
text-decoration: none;
overflow: hidden;
}
And use max-width on the tag not simple width

Navigation lists, inline and with spacing

i have a navigation bar and i want to be on one line it does this however there is only one space between each item, i want them to be spaced equally out, and flexible, so that when i change the window size they adjust.
this is my html
<div class="navigation">
<div class="navhead">
<h2>Navigation</h2>
</div>
<div class="navlist">
<ul>
<li>Home</li>
<li>Chat</li>
<li>Blog</li>
</ul>
</div>
</div>
and this is my css
.navlist li{
text-decoration: none;
color: #000000;
list-style-type: none;
display: inline;
text-indent: 10%;
}
please keep in mind i am in year 7 and don't use too complex words
Just apply width of your li and if needed add padding value. But change inline to table-cell. And to apply the space between them apply border-spacing value as followings:
.navlist{
border-spacing: 10px;
}
.navlist li{
text-decoration: none;
color: #000000;
list-style-type: none;
display: table-cell;
text-indent: 10%;
width: 20%;
padding: 1em;
}
Check this demo
You could display the ul as a table, like this:
HTML:
<ul>
<li>link</li>
<li>link</li>
<li>link</li>
</ul>
CSS:
ul {
width: 90%;
background: #222;
margin: 0;
padding: 10px;
display: table;
table-layout: fixed;
}
ul li {
display: table-cell;
}
ul li a {
display: block;
background: #555;
text-align: center;
color: white;
padding: 10px 0;
}
Also check this demo.

strange top padding with Chrome/IE and display:inline on ul list

I have a very plain navigation menu using an unordered list laid out horizontally using display:inline;. The previews in my HTML editor show the page coming together just fine. However, when it's viewed in Chrome and IE, there's a strange padding on top of the nav menu and only on the top. Using the process of elimination, I know this is a problem with my CSS for the <li> tag but I'm not sure what the problem is.
So far I've tried display:inline-block, lowering the font size, setting the <ul> tag in the nav menu to display:inline, and a myriad other things. None seems to be helping. Any advice for where the CSS went wrong? Here is the HTML in question...
<body>
<div id="wrapper">
<div id="header"></div>
<div id="navigation">
<ul>
<li>welcome</li>
<li>who we are</li>
<li>what we do</li>
<li>contact</li>
</ul>
</div>
<div id="content"> </div>
</div>
</body>
And here is the CSS...
body {
background-color: #000000;
margin: 0;
padding: 0;
font-family: Arial, Helvetica, Sans-Serif;
text-align: center;
}
#header {
background-color: #ffffff;
height: 100px;
}
#wrapper {
width: 960px;
text-align: left;
}
#navigation {
height: 45px;
background-color: #C0C0C0;
font-size: 1.3em;
text-align: right;
}
#navigation a {
color: #00132a;
text-decoration: none;
}
#navigation a:hover {
color: #483D8B;
}
#navigation ul {
padding-top: 10px;
}
#navigation ul li {
display: inline;
list-style-type: none;
padding: 0 30px 0 30px;
}
#navigation-symbol {
font-size: 1em;
}
#content {
background-color: #ffffff;
text-align: left;
font-size: 14px;
}
And for interactive fun there's a jsFiddle as well which shows the exact same phenomenon I'm seeing. Thanks ahead for the advice!
Simply set margin to zero
#navigation ul {
margin: 0;
padding-top: 10px;
}