Trying to get a title to appear inline between the Logo and the navbar links. I'm trying to learn without bootstrap first and ideally without flexbox (want to know the basics first).
I've been trying 'display: inline' and different 'position' values in different spots but I'm getting lost.
#header-img {
margin-left: 20px;
margin-top: 10px;
height: 100px;
width: 100px;
float: left;
}
#nav-bar {
text-align: right;
padding: 20px;
background-color: #A7A7A9;
}
li {
display: inline;
list-style: none;
}
ul {
top: 5px;
left: 10px;
}
.nav-link {
width: auto;
height: 50px;
margin-left: 40px;
margin-top: 25px;
display: inline-block;
color: #453F3C;
font-size: 20px;
font-weight: 500;
letter-spacing: .9px;
text-decoration: none;
}
<header id="header">
<div class="logo">
<img id="header-img" alt="company logo" src="https://preview.ibb.co/jabJYd/rocket_1976107_1280.png">
</div>
<h1>Title</h1>
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#our-services">Our Services</a></li>
<li><a class="nav-link" href="#reviews">Reviews</a></li>
<li><a class="nav-link" href="#locations">Locations</a></li>
</ul>
</nav>
</header>
to learn more about css positioning use the following link : https://www.w3schools.com/Css/css_positioning.asp and to learn more about positioning read this article : https://www.w3schools.com/Css/css_inline-block.asp
You also need to look at using percentages for your widths.
In your code, the navbar and the title are the two parent elements which need to be positioned and assigned widths in percentages for responsiveness. like this;
#nav-bar {
text-align: right;
background-color: #A7A7A9;
width: 79%;
float: right;
margin-top: 12px;
display: inline-block;
}
For the title :
h1{
display: inline-block;
width: 18%;
min-width: 77px;
float: left;
}
For the ul element in the navbar :
ul {
top: 0px;
left: 0px;
padding-left: 0px;
}
finally for the .navlinks :
.navlink{
width: auto;
margin-right: 7%;
display: inline-block;
color: #453F3C;
font-size: 19px;
font-weight: 500;
letter-spacing: .9px;
text-decoration: none;
}
I am new to development as well but I think what you are trying to do is the following.
HTML:
<nav id="nav-bar">
<ul>
<div class="new_div"><h1>Title</h1></div>
<li><a class="nav-link" href="#our-services">Our Services</a></li>
<li><a class="nav-link" href="#reviews">Reviews</a></li>
<li><a class="nav-link" href="#locations">Locations</a></li>
</ul>
</nav>
</header>
CSS:
.new_div{
float: left;
}
I just added the title as a new div inside the navigation menu and float it left. If there is a logo in between then you can add it in the navigation list and float it left.
You could use
header * {
display: inline;
}
to put everything inside <header> </header> inline.
If you plan to use the header tag elsewhere use a class or an id.
header.top-bar * {
display: inline;
}
To keep all with the same background:
header.top-bar {
width: 100%;
background-color: #A7A7A9;
}
Hope it helps you!
.header h1{position:absolute; left:50%; transform:translateX(-50%); }
Now it's centered between the logo and navigation. By setting the top property you can vertically move the element. Make sure you parent element's position set to relative.
Related
I'm trying to resize my logo & add a title to the side of the logo without resizing the navbar.
What the current navbar looks like
HTML:
<header id="header">
<img src="logohtml.png" alt="logo" id="header-img">
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#"><b>Things to Do</b></a></li>
<li><a class="nav-link" href="#"><b>Where to Eat</b></a></li>
<li><a class="nav-link" href="#"><b>Events</b></a></li>
<li><a class="nav-link" href="#"><b>Hotels</b></a></li>
<li><a class="nav-link" href="#"><b>Parking</b></a></li>
</ul>
</nav>
CSS:
header {
position: fixed;
background-color: #FFAA63;
color: white;
font-family: 'Exo 2', sans-serif;
padding: 1em;
width: 100%
}
header::after {
clear: both;
content: '';
display: table;
}
#header-img {
width: 90px;
height: 50px;
float: left;
padding-top: 1.7em;
}
EDIT:
This is the navbar after applying your code. The logo is still the same size for some reason. I would like it to be bigger but not change the height of the navbar.
enter image description here
EDIT:
I did as suggested & my logo fits into the navbar, thank you!
I added width & played around with the height & width.
#header-img {
position: absolute;
height: 160px;
width: 250px;
}
Current navbar
Based on my assumption of what your provided code lacked. I built your navbar like the following snippet, I hope it will help you somehow.
Basically, my solution used flexbox applied to the header in order to let elements of header to display in row. then using align-items: center to vertically align and justify-content: space-between to create a space between the logo and the navabr.
Edit: refer to this link to playaround: https://codepen.io/DohaHelmy/pen/xxbzzRN
I tried to re-position the logo and added a name next to it. also consider removing margin-top added to the header as it is just set to show the effect properly.
For better display of the result run the snippet using full page
header {
margin-top: 50px;
display: flex;
align-items: center;
justify-content: space-between;
position: fixed;
background-color: #ffaa63;
color: white;
font-family: "Exo 2", sans-serif;
padding: 1em;
width: 100%;
}
#logo{
display: flex;
align-items: center;
font-size: 35px;
position: relative;
}
#logo span{
position: relative;
left: 220px;
}
#header-img {
position: absolute;
height: 120px;
}
#nav-bar ul {
position: relative;
right: 50px;
list-style-type: none;
overflow: auto;
}
#nav-bar ul li {
float: left;
margin: 0px 20px;
color: #fff;
}
#nav-bar .nav-link {
color: #000;
text-decoration: none;
}
<header id="header">
<div id="logo">
<img src="https://www.freepnglogos.com/uploads/eagles-png-logo/eagle-sports-png-logos--0.png" alt="logo" id="header-img">
<span>Logo name</span>
</div>
<nav id="nav-bar">
<ul>
<li><a class="nav-link" href="#"><b>Things to Do</b></a></li>
<li><a class="nav-link" href="#"><b>Where to Eat</b></a></li>
<li><a class="nav-link" href="#"><b>Events</b></a></li>
<li><a class="nav-link" href="#"><b>Hotels</b></a></li>
<li><a class="nav-link" href="#"><b>Parking</b></a></li>
</ul>
</nav>
</header>
I didn't quite understand your question but I think you need to move the logo to the right side a bit without affecting the size of the navbar. Or maybe you want to resize the logo but without affecting the navbar. So this solution works for both problems.
#nav-bar {
left: 58%;
position: absolute;
margin-top: 30px; }
I have a HTML5 header setup. It uses <ul> and <li> elements for the links.
This is the HTML:
<header>
<nav>
<ul>
<li id="logoli"><img src="/assets/logo.png" id="logo"></li>
<li>Home</li>
<li class="5px">Roulette</li>
<li>Free Stuff</li>
</ul>
</nav>
</header>
And the CSS:
header {
height: 100%;
width: 100%;
}
nav {
width: 100%;
height: 65px;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
padding-left: 10px;
background-color: rgba(0, 0, 0);
color: #0077C5;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}
li {
width: 100px;
line-height: 65px;
vertical-align: middle;
text-align: center;
margin: 0;
text-align: center;
display: inline;
list-style: none;
float: left;
}
#logo {
height: 50px;
}
#logoli {
padding-top: 7px;
width: 250px;
}
For some reason this happens: https://image.prntscr.com/image/w0LAMn5qRMq0OqIAfDTsHw.png
If you look at the nav bar you can easily see that the first two elements have a normal amount of spacing in-between. But the seccond and third have weirdly small spacing. I used inspect element on the <li>'s but they are all the same height. Can someone help me?
You need some HTML and CSS Fixes, Wrap the anchors in li elements and the issue was you have mentioned a width to the li, which causes this wierd spacing.
HTML
<header>
<nav>
<ul>
<li id="logoli">
<img src="/assets/logo.png" id="logo"></li>
<li>Home</li>
<li class="5px">Roulette</li>
<li>Free Stuff</li>
</ul>
</nav>
</header>
CSS
header {
height: 100%;
width: 100%;
}
nav {
width: 100%;
height: 65px;
font-size: 14px;
font-weight: 700;
text-transform: uppercase;
padding-left: 10px;
background-color: rgba(0, 0, 0);
color: #0077C5;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}
li {
line-height: 65px;
vertical-align: middle;
text-align: center;
margin:0px 10px;
text-align: center;
display: inline;
list-style: none;
float: left;
}
#logo {
height: 50px;
}
#logoli {
padding-top: 7px;
width: 250px;
}
You should put the <a href>'s inside the <li> tags like this:
<header>
<nav>
<ul>
<li id="logoli"><img src="/assets/logo.png" id="logo"></li>
<li>Home</li>
<li>Roulette</li>
<li>Free Stuff</li>
</ul>
</nav>
</header>
Also - you have a class="5px" on one of the <li>'s, but that class isn't in your CSS. You should make your <li>'s a fixed width and center the text, or use a standard padding on the left and right of the <li> text to maintain a uniform spacing rather than injecting classes to push single elements around.
This is happening because you're explicitly defining a width on your list items. Remove the width and separate the list items with padding instead. Optionally, remove any padding on the last list item, since you won't need it.
li {
/* width: 100px; */
padding-right: 1em;
line-height: 65px;
vertical-align: middle;
text-align: center;
margin: 0;
text-align: center;
display: inline;
list-style: none;
float: left;
}
li:last-child {
padding-right: 0;
}
https://jsfiddle.net/eulloa/yx7vkt79/
Also, restructure your list items so that they are the parent element of your anchors, not the other way around.
<li>Home</li> <!-- structure your list items this way -->
<li>Home</li>
I want to achieve some UI/UX like this
so there is a logo, also 2 menu, 1 for language change, 1 for change menu
my approach is two div
first div contain image and language menu ul
second div contain menu ul
but, image in first div is covered by second div
did my approach wrong?
Here is what I've done
HTML & CSS
header {
position: fixed;
}
#logo {
position: fixed;
float: left;
}
#nav-language {
align: right;
width: 100%;
height: 66px;
}
#nav-menu {
background-color: #ccb96b;
width: 100%;
height: 66px;
top: 67px;
position: fixed;
}
#nav-menu ul {
left: 500px;
z-index: 5;
}
ul {
list-style-type: none;
}
li {
display: inline;
padding: 15px;
}
#nav-language a {
font-size: 1.6em;
text-transform: uppercase;
font-weight: bold;
font-family: century gothic;
text-decoration: none;
color: white;
}
#nav-menu a {
font-size: 1.6em;
text-transform: uppercase;
font-weight: bold;
font-family: century gothic;
text-decoration: none;
color: #430615;
}
#nav-menu a:hover {
opacity: 0.36;
}
<header>
<div id='nav-language'>
<img id="logo" src="<?php echo base_url(); ?>assets/images/logo.png" />
<ul>
<li class='navigation-Blog'><a href='#'>en</a></li>
<li class='navigation-Crew'><a href='#'>fr</a></li>
<li class='navigation-Promos'><a href='#'>it</a></li>
</ul>
</div>
<div id='nav-menu'>
<ul>
<li class='navigation-Blog'><a href='#'>home</a></li>
<li class='navigation-Crew'><a href='#'>About Us</a></li>
<li class='navigation-Promos'><a href='#'>contact us</a></li>
</ul>
</div>
</header>
any help appreciated, maybe my approach could be wrong, welcome for advice
I was able to achieve what you're looking for by changing the #nav-language to position: relative; and changing the css on the #logo div's z-index and top & bottom attributes. Here's a jsfiddle
EDIT: Note that you'll have to play with the top and bottom values depending on your image size, i've used a random image as an example
EDIT2: i noticed that you have align: right; on your #nav-language div, but align doesn't exist in css, you'll want to set the header width to 100% and put float: right; on the language ul. i've updated my jsfiddle with the correct css
https://jsfiddle.net/n42dyhza/2/
For some reason or another my navigation buttons are being pushed down by the image. I can solve the issue by floating the image but that does not interest me.
CSS:
.wrapped {
position: relative;
width: 70%;
margin: 0 auto;
}
.header {
width: 70%;
margin: 0 auto;
}
.headernav {
width: 70%;
margin: 0 auto;
height: 120px;
}
.logo, .logo img {
display: inline-block;
margin-right: 30px;
}
.nav {
padding-left: 30px;
display: inline-block;
height: 120px;
line-height: 120px;
vertical-align: middle;
}
.navbutton {
padding: 5px 30px;
display: inline-block;
}
#fitness, #wcontrol, #recipes, #supplementation {
text-align: center;
height: 36px;
line-height: 36px;
font-weight: bold;
}
HTML:
<div id="wrapperheader">
<div class="headernav">
<div class="logo"><img src="http://protein.guru/images/PGlogo.png" alt="Protein.guru Logo" class="logo"></div>
<div class="nav">
<div class="navbutton"><div id="recipes">Recipes</div></div>
<div class="navbutton"><div id="fitness">Fitness</div></div>
<div class="navbutton"><div id="wcontrol">Weight Control</div></div>
<div class="navbutton"><div id="supplementation">Supplementation</div></div>
</div>
</div>
</div>
If anyone knows why this is happening or of a simple solution, please let me know. Sorry if its an obvious answer.. I'm been staring at the code on and off for a day and it's just not clicking.
You could simplify your HTML & CSS to remove div soup, by moving the logo into the nav bar:
Usually the logo would be wrapped with an anchor tag, so that clicking on it will return the user to the home page. So it becomes a nav element.
HTML:
<div class="nav">
<div class="navlogo"><img src="http://protein.guru/images/PGlogo.png" alt="Protein.guru Logo" class="logo"></div>
<div class="navbutton"><span id="recipes">Recipes</span></div>
<div class="navbutton"><span id="fitness">Fitness</span></div>
<div class="navbutton"><span id="wcontrol">Weight Control</span></div>
<div class="navbutton"><span id="supplementation">Supplementation</span></div>
</div>
The HTML above uses spans, but you can also use <... class="navbutton" id="recipes">Recipes</...>, as shown below.
Optimized HTML: Generally people create UL LI tag stacks for nav bars.
<ul class="nav">
<li class="navlogo"><img src="http://protein.guru/images/PGlogo.png" alt="Protein.guru Logo" class="logo"></li>
<li class="navbutton" id="recipes">Recipes</li>
<li class="navbutton" id="fitness">Fitness</li>
<li class="navbutton" id="wcontrol">Weight Control</li>
<li class="navbutton" id="supplementation">Supplementation</li>
</ul>
Then cleaning up the CSS, will remove problems with applying duplicate right margins & paddings to both the .logo & .logo .img tags. In your example, there is also a left margin on the nav element, which was creating extra margin space between the logo & the 1st link.
In this CSS example below, I've also thrown in a vertical-align:middle; property, so that the nav links center vertically next to a larger image logo. See this jsfiddle.
CSS:
.nav {
height: 120px;
line-height: 120px;
margin: 0 auto;
vertical-align: middle;
width: 70%;
}
.nav li {
display: inline-block;
list-style-type: none; /* removes bullets */
}
.nav .logo,
.nav .navlogo,
.nav .navbutton {
display: inline-block;
}
.nav .logo {
vertical-align: middle;
}
.nav .navbutton {
font-weight: bold;
height: 36px;
line-height: 36px;
padding: 5px 0 0 30px;
text-align: center;
}
If you wants to keep width: 70% of your .wrapped container, you have to reduce padding of your nav menu and size of your image.
See this fiddle
(It works on large size of the window)
Otherelse, you can put a fixed width of the .wrapped container but still have to consider padding of your nav menu and width of the image to make it fits.
.navbutton {
padding: 5px 25px;
display: inline-block;
}
Hey guys is it possible to make navigation bar stay in header no matter padding? Coz i want to make The Site title and menu in one line and i thought padding would do that...
#banner {
background-color: #d3135a;
height: 120px;
margin-bottom: 4%;
}
h1 {
float: left;
padding-bottom: 6%;
}
#pav {
font: Trebuchet MS;
float: left;
padding-left: 4%;
margin-top: 4%;
}
#menu_virsut li {
display: inline;
}
#menu_virsut {
float: right;
margin-top: 5%;
padding-right: 4%;
padding-bottom: 2%;
padding-top: 1%;
}
<header id="banner">
<h1>The Site</h1>
<nav id="menu_virsut">
<ul>
<li><a href>menu link</a>
</li>
<li><a href>menu link</a>
</li>
<li><a href>menu link</a>
</li>
</ul>
</nav>
</header>
A simple way for alignment is to set the same line-height for the h1 tag and the container. Your href tags don't have a link. "#" is what you would put if you don't want the link to go anywhere.
JSFiddle: http://jsfiddle.net/9vwjbq8n/
#banner {
background-color: #d3135a;
height: 120px;
margin-bottom: 4%;
}
h1 {
float: left;
line-height: 120px;
}
#pav {
font: Trebuchet MS;
float: left;
padding-left: 4%;
margin-top: 4%;
}
#menu_virsut li {
display: inline;
}
#menu_virsut {
float: right;
line-height: 120px;
}
Yes, remove the margins from each element in your header, or more like it, fix their values.
e.g. remove margin-top: 5%; from menu_virsut
Your markup is wrong, as a general rule, if you're creating a navigation menu you should create a <ul> tag and put all the nav items inside, then you can use float: right; on that <ul> element. If you want a logo, create another <ul> element and give it property float: left;. Make sure all the margins are okay and you're done.
I have created an example jsfiddle to illustrate how to write a good header/ navigation menu. https://jsfiddle.net/akhzywag/