Navigation bar not being moved to the right? - html

I'm trying to recreate the Google homepage as part of theodinproject and I'm having trouble trying to get the navbar across the top to the right.
I tried display: flex and float: right but I'm not sure how to get the Images, Gmail, and Sign In button to the right. I've been told that my style isn't being applied also. Would anyone be willing to help? I'd greatly appreciate it. Below is a snippet of my html and css code and a link to how the page appears.
https://i.stack.imgur.com/pAgDn.png
<ul>
<li><a><button>Sign in</button></a></li>
<li>Images</li>
<li>Gmail</li>
</ul>
</header>
ul {
list-style-type: none;
}
li {
float: right;
}
li a {
display: block;
padding: 10px 10px;
}```

Seems like your only mistake is not having a <style> tag around your css code. Try this.
<style>
ul {
list-style-type: none;
}
li {
float: right;
}
li a {
display: block;
padding: 10px 10px;
}
</style>

Using float is not necessary for that, you can definitely use display: flex. The minimum to understand about flex is that it affects child elements only, so if you want to have a navbar which appears on the right for example, you need to use display: flex on the parent.
.header {
display: flex;
}
<div class='header'>
<div class='navbar'></div>
<div class='logo'></div>
</div>
You can also use justify-content to choose how they align among the main axis (by default the horizontal one)
For something like this I'd add justify-content: space-around or justify-content: space-between.
I'd highly recommend reading more about Flex, as it's super useful.
Good resource:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/

You need to wrap the css styling inside a as in the example below:
<style>
ul {
list-style-type: none;
}
li {
float: right;
}
li a {
display: block;
padding: 10px 10px;
}
</style>
and also you need to remove the characters at the end ( ``` )

Try using:
header {
width: fit-content;
margin-left: auto;
}
For example, I did the top part using this idea. This is how it looks.
html {
font-family: sans-serif;
color: #333;
}
header {
width: fit-content;
margin-left: auto;
}
li,
ul,
buttom {
display: inline-block;
padding: 0 1ch;
}
li {
font-size: 0.85em;
color: #555;
}
img {
display: block;
margin: 0 auto;
width: 20em;
padding-bottom: 1.5em;
}
main {
padding: 20vh 0;
width: fit-content;
margin: 0 auto;
}
input {
margin: 0 auto;
display: block;
border: 1px solid silver;
border-radius: 2.8em;
height: 2.8em;
width: 40em;
}
<header>
<ul>
<li>Gmail</li>
<li>Images</li>
</ul>
<button>Sign in</button>
</header>
<main>
<img src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
<input type="search">
</main>
I hope it works!

Related

How do I arrange the navbar so that it is spaced out evenly?

I have tried to use the margin and padding tags, but I can never get it right because screen sizes change, and that makes the arrangements change. Also tried using flex
I am trying to make a navigation bar (top) in HTML and CSS, but I want to make all the tags uniform in spacing so it looks nicer.
Right now it looks like this:
Here is my HTML code:
<div class="header">
<div class="container">
<h1 class="logo"></h1>
<div class="nav">
<ul>
<li>Home</li>
<li>History</li>
<li>Where to Eat</li>
<li>Places to visit</li>
<li>Beauties of Nature</li>
<li>How to navigate Seoul</li>
</ul>
</div>
</div>
</div>
CSS:
.container {
width: 80%;
margin: 0 auto;
}
.header {
background: #293380;
}
.header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
padding: 10px 0;
}
.nav {
float: right;
}
.nav ul {
display: flex;
flex-direction: row;
margin: 0;
padding: 0;
list-style: none;
}
.nav li {
flex: 1;
display: inline-block;
margin-left: 70px;
padding-top: 23px;
position: relative;
}
.nav a {
color: #F0EFF7;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
.nav a:hover {
color: #953D60;
}
.nav a::before {
content: '';
display: block;
height: 5px;
background-color: #F7D9F1;
position: absolute;
top: 0;
width: 0%;
in your css file, under .nav ul, write justify-content: space-between;, which spaces all the elements evenly.
I really recommend you look further into justify-content, since its the main way to space out the content the way you want. Really good tool

My navigation bar is showing issues never seen before by me

As you read on the title, I've been trying to make a navigation bar but I'm having several issues I haven't experienced before. I even made a list:
Buttons sticking into the navigation bar even though they don't belong in the div class.
Navigation Bar
Well now, I've seen this before, but I've gotten a bit rusty on HTML and don't quite remember how to fix it. If you can't tell, the links are not lined up with the text/logo. How can I fix this? I'm trying to make it slim.
background-color: #252036;
}
#navigation-container {
width: 1200px;
margin: 0 auto;
height: 70%;
}
.navigation-bar {
background-color: #1c172c;
width: 100%;
left: 0;
top: 0;
position: fixed;
text-align: right;
}
.navigation-bar ul {
padding: 0px;
margin: 0px;
text-align: right;
display: inline-block;
vertical-align: top;
}
.navigation-bar li {
list-style-type: none;
padding: 0px;
display: inline;
text-align: right;
}
.navigation-bar li a {
color: black;
font-size: 16px;
font-family: basic;
text-decoration: none;
line-height: 70px;
padding: 5px 15px;
opacity: 0.7;
}
#menu {
float: right;
}
<div class="navigation-bar">
<div id="navigation-container">
<h1>SINUS</h1>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<button>Download</button>
It is sticking because of position: fixed;. The button doesn't see the .navigation-bar. Add padding to a parent that contains these elements.
h1 needs to have display:inline-block;. ul is just below h1 now.

The ul class is not inline with the website logo

My navigation UL items are not being displayed inline with my website's logo: Is it possible of the logo size? I've tried adding the width property to the #logo but it wont react...
Picture of problem: http://prntscr.com/p5aygy
Logo properties: 496px x 109
HTML
<!--Navigation!!!-->
<nav>
<div id="logo"><img src="images/White.png"></div>
<label for="drop" class="toggle">Menu</label>
<input type="checkbox" id="drop"/>
<ul class="menu">
<li>Home</li>
<li>Pricing</li>
<li>Faq</li>
<li>Contact</li>
</ul>
</nav>
CSS FILE
nav {
margin: 0;
padding: 0;
background-color: black;
}
#logo {
display: block;
float: left;
padding: 10px 0 0 30px;
}
nav:after {
content: "";
display: table;
clear: both;
}
nav ul {
float: right;
list-style: none;
padding: 0;
margin: 0;
}
nav ul li {
display: inline-block;
float: left;
}
#media (max-width:768px) {
#logo {
display: block;
width:100%;
text-align: center;
float: none;
padding: 20px 0 10px;
}
nav ul li {
width: 100%;
}
.toggle + a, .menu {
display: none;
}
}```
Your CSS is adding padding to the top of your logo for the #logo selector. That is probably where the spacing is coming from. If you'd like to get rid of the extra spacing on your logo, change the lines for the #logo selector like this:
#logo {
display: block;
float: left;
padding: 0 0 0 30px;
}
And again for the media query line below:
#media (max-width:768px) {
#logo {
display: block;
width: 100%;
text-align: center;
float: none;
padding: 0 0 0 10px;
}
}
Also, there may be a chance that your logo image has transparent space around the part that you can see? Sometimes if images aren't trimmed correctly, they can cause unintentional spacing errors.
If you can provide a link to the logo image file itself, we can try to rule this potential issue out.
Try adding margin-top: 10px to the UL part

centered horizontal navigation bar css

I know there are a lot of answers with this subject but it still doesn't work somehow with my code.
Every time I try to center the text with text-align center it doesn't work unless I remove float: left, display: inline or display: inline-block. But then I have a vertical centered navigation bar...
Can anyone help me with this?
This is my HTML code:
<div class="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Moviekids festivals</li>
</ul>
</div>
and here is the CSS code:
*{
margin: 0px;
padding: 0px;
}
body {
text-align: center;
font-family: arial;
background-color: white;
}
#wrapper{
width: 960px;
margin: 0 auto;
height: 100%;
text-align: left;
background-color: #1d1d1b;
}
.nav {
background-image:url("img/nav.jpg");
width: 100%;
height: 50px;
display: inline-block;
}
.nav ul {
list-style-type: none;
}
.nav li {
display: inline;
text-align: center;
}
.nav a {
text-decoration: none;
display: inline-block;
color: #1d1d1b;
padding: 10px;
}
You need to set the text-align on the parent element like so:
.nav ul {
list-style-type: none;
text-align: center;
}
.nav li {
display: inline-block;
}
See Demo
I just edited your css to acheive what you need
.nav ul {
list-style-type: none;
text-align:center;
}
.nav li {
display:inline-block;
text-align: center;
padding: 10px;
}
.nav a {
text-decoration: none;
display: block;
color: #1d1d1b;
}
DEMO
Always avoid using body text-align try using instead for wrapper.
Make sure you have mentioned <!DOCTYPE html> on the top of your HTML code.
Otherwise your code seems perfect.

Cannot figure out how to center multiple links in a navigation bar using CSS

I'm trying to center Link 1, Link 2, and Link 3 in the following page:
http://i.imgur.com/qNimZCs.png?1
Here is the relevant bit of html:
<a class="logo" href="#"><p>Logo</p></a>
<ul class="nav">
<li><a class="link" href="#"><p>Link 1</p></a></li>
<li><a class="link" href="#"><p>Link 2</p></a></li>
<li><a class="link" href="#"><p>Link 3</p></a></li>
</ul>
and here's the css:
.link
{
font-size: 1em;
margin-left: 0;
margin-right: 0;
font-weight: none;
text-decoration: none;
color: #123456;
display: inline-block;
padding: 0 0;
}
.nav
{
margin-left: 0;
display: inline-block;
margin-bottom: 5px;
margin-top: 5px;
}
.nav li
{
display: inline-block;
margin: auto;
}
I've tried every combination of things that I can think of.
To be specific, I'm trying to center the links such that they are all evenly spaced out along the nav bar. Does anyone see what I'm doing wrong?
Edit:
jsfiddle link: http://jsfiddle.net/B362m/
Try this:
.nav
{
display: inline-block;
margin-left: 5%;
margin-bottom: 5px;
margin-top: 5px;
text-align: center;
}
Working Fiddle
That's kinda a lot of css you've got there. (Consider using shorthand for your seperate margin values?) Two things..
1) if your elements are inline-block, then you can set text-align on the parent to move stuff to the left/center/right accordingling.
2) Your links are already just text, so is there a specific reason why you've set them to inline-block rather than just inline? Not that it makes a big deal.. setting inline-block will allow you to set padding and boost the clickable area.
Anyway... this should align your links:
.nav {
text-align: center;
display:block;
}
.link {
display: inline-block;
margin: 0 5px;
padding: 5px;
}
You can also use display:table and display:table-cell to get the look you're going for.
Try this:
.nav
{
margin:auto;
width: 80%;
display:table;
padding:0;
text-align:center;
}
.nav li
{
display: table-cell;
}
JSFiddle Demo