Image and Ul Li not inline - html

I am designing a hotel website with a fixed navbar. I am having trouble getting the items to be inline with an image item. It's getting quite frustrating.
Here's my HTML
<nav id="navigation">
<ul>
<li class="left">Rooms</li>
<li class="left">Dining</li>
<li class="home"><img src="assets/navbarimg.png" height="64.5px" weight="250px"></img></li>
<li class="right">Activities</li>
<li class="right">Book a Stay</li>
</ul>
</nav>
and here's my CSS
#navigation ul {
text-align: center;
position: fixed;
width: 100%;
max-width: 100%;
font-size: 2vh;
font-family: 'Raleway', sans-serif;
z-index: 100;
background-color: rgba(255,255,255,.55);
display: inline-block;
}
#navigation li {
display: inline-block;
list-style-type: none;
}
#navigation a {
text-decoration: none;
margin: 0px 75px 0 75px;
color: black;
font-weight: 600;
text-transform: uppercase;
display: inline-block;
}
.left {
display: inline;
}
.home {
display: inline;
}
.right {
display: inline;
}
My code is super basic, so work with me here.
#navigation ul {
text-align: center;
position: fixed;
width: 100%;
max-width: 100%;
font-size: 2vh;
font-family: 'Raleway', sans-serif;
z-index: 100;
background-color: rgba(255, 255, 255, .55);
display: inline-block;
}
#navigation li {
display: inline-block;
list-style-type: none;
}
#navigation a {
text-decoration: none;
margin: 0px 75px 0 75px;
color: black;
font-weight: 600;
text-transform: uppercase;
display: inline-block;
}
.left {
display: inline;
}
.home {
display: inline;
}
.right {
display: inline;
}
<nav id="navigation">
<ul>
<li class="left">Rooms</li>
<li class="left">Dining</li>
<li class="home">
<a href="index.html"><img src="https://placehold.it/250x65" height="64.5px" weight="250px"></img>
</a>
</li>
<li class="right">Activities</li>
<li class="right">Book a Stay</li>
</ul>
</nav>

Live Example I made: https://akainth015.github.io/Inked-Out
Often, you can align things with vertical-align(CSS). However, it is a little counter-intuitive. When you use the vertical-align style, the element it is applied to becomes the standard for the rest of the elements. So, if you have this structure:
li {
display: inline-block;
}
ul {
list-style-type: none;
}
li img {
vertical-align: middle;
}
<ul>
<li>Home</li>
<li><img src="https://placehold.it/64x64"></li>
<li>About</li>
</ul>
Notice how it is applied to the image, not the the text you want in the center. Good luck!

Related

Problem with making my menu horizentel (ul)

i have a problem with making the list horizontally, I tries putting in display: inline; and float: right; doesn't seem to work. Hope you can help, and sorry for the badly explained problem, I just started the education. Have a great day
ul {
display: inline;
list-style-type: none;
margin: 0px;
padding: 0px;
margin-left: -17px;
width: 200px;
line-height: 350%;
}
li a {
display: inline;
color: #FFFFFF;
padding: 15px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
<body style="background-color:black;">
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
Try this code to set your menu horizontal and remove color white or give background color so you can visible text properly give float property to li only.
ul {
display: inline;
list-style-type: none;
margin: 0px;
padding: 0px;
width: 200px;
}
li {
float: right;
}
li a {
display: inline;
color: #000;
padding: 15px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
You can use flexbox like display: flex in ul.
ul {
display: flex;
width: 100%
}
It will align ul items in horizontal.
HTML:
<body style="background-color:black;">
<div class="menu">
<ul>
<li>Home</li>
<li>Om os</li>
<li>Portfojle</li>
<li>Kontakt os</li>
</ul>
</div>
CSS:
ul {
display: flex;
width: 100%
}
li a {
display: inline;
color: #FFFFFF;
padding: 0 25px;
text-decoration: none;
font-size: 35px;
font-weight: 400;
}
li a.active {
color: white;
}
li a:hover:not(.active) {
color: #F39D2A;
}
I belive this will work. If you want adjust more, you can read about flex concept here (https://css-tricks.com/snippets/css/a-guide-to-flexbox/).

Everytime I hover on my NavList the bottom list adds width to the top

I have the width of the first ul equal to the width of the words with margin-right = 50px and I have the bottom ul width = 200px. The problem is if the top ul width is 180px and I hover on it, the top ul matches the bottom 200px which increase the right side and pushing the list.
nav {
width: 100%;
height: 50px;
background-color: #d60d8c;
}
.navbar-tab {
margin: auto;
width: 1300px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.navbar-tab-1 {
padding-right: 50px;
}
ul li {
list-style: none;
height: 50px;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-size: 19px;
font-weight: 400;
line-height: 50px;
float: left;
}
ul li a {
text-decoration: none;
color: black;
display: block;
}
ul li ul li {
display: none;
}
ul li:hover ul li {
display: block;
}
.hover-list li {
font-size: 15px;
background-color: #e2e2e2;
width: 200px;
text-indent: 20px;
}
<nav id="navbar">
<ul class="navbar-tab">
<li class="navbar-tab-1">Home</li>
<li class="navbar-tab-1">Diamond Search
<ul class="hover-list">
<a>
<li>GIA Diamond Search</li>
</a>
<a>
<li>Diamonds</li>
</a>
</ul>
</li>
<li class="navbar-tab-1">Wedding Bands</li>
<li class="navbar-tab-1">Engagement Rings</li>
<li class="navbar-tab-1">Selection Guide</li>
<li class="navbar-tab-1">Jewellery Services</li>
</ul>
</nav>
You can give absolute position to the ul element that contains submenu to prevent it from affecting the width of parent:
.hover-list {
position: absolute;
}
nav {
width: 100%;
height: 50px;
background-color: #d60d8c;
}
.navbar-tab {
margin: auto;
width: 1300px;
}
ul {
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.navbar-tab-1 {
padding-right: 50px;
}
ul li {
list-style: none;
height: 50px;
display: inline-block;
font-family: 'Raleway', sans-serif;
font-size: 19px;
font-weight: 400;
line-height: 50px;
float: left;
}
ul li a {
text-decoration: none;
color: black;
display: block;
}
ul li ul li {
display: none;
}
ul li:hover ul li {
display: block;
}
.hover-list li {
font-size: 15px;
background-color: #e2e2e2;
width: 200px;
text-indent: 20px;
}
.hover-list {
position: absolute;
}
<nav id="navbar">
<ul class="navbar-tab">
<li class="navbar-tab-1">Home</li>
<li class="navbar-tab-1">Diamond Search
<ul class="hover-list">
<a>
<li>GIA Diamond Search</li>
</a>
<a>
<li>Diamonds</li>
</a>
</ul>
</li>
<li class="navbar-tab-1">Wedding Bands</li>
<li class="navbar-tab-1">Engagement Rings</li>
<li class="navbar-tab-1">Selection Guide</li>
<li class="navbar-tab-1">Jewellery Services</li>
</ul>
</nav>
Also, I would suggest using Class selectors over tag selectors such as ul li, ul li a or ul li ul li. Tag selectors not-only have a slightly poor performance as compared to class selectors, but they will also apply to a larger number of elements - sometimes when you don't intend them to be - like in case you had another ul element in the page that listed some unrelated items.

Vertically align "after" element that contains icon

I have a navigation menu, and the first item replaces the content with an icon. I'm doing this by setting the font-size to 0px of the main element, and then adding an after element. This seems to be a common practice and it works so far so good.
However I can't seem to align the after element with the rest of the navigation menu.
I started playing around with line-height and vertical-align which got me closer to my goal, but as you can see, it's still not properly working as expected.
The fiddle can be found here: https://jsfiddle.net/67dyxLr1/
<nav class="nav-primary">
<ul class="menu">
<li class="menu-item home">Home</li>
<li class="menu-item">Blog</li>
<li class="menu-item">Contact</li>
<li class="menu-item">About Us</li>
</ul>
</nav>
Here is my CSS:
.nav-primary {
background: #CCC;
}
.nav-primary li {
list-style-type: none;
display: inline-block;
text-align: left;
font-size: 26px;
line-height: 0px;
}
.nav-primary a {
display: inline-block;
padding: 32px 20px;
border: 1px dashed black; /* border only used for display purpose of alignment*/
margin-right: -4px;
}
.nav-primary a:hover {
background: #FFF;
}
.menu {
width: 100%;
}
.menu-item {
}
.home a {
font-size:0px;
}
.home a:after {
font-family: "dashicons";
content: " \f102";
font-size: 40px;
display: inline-block;
vertical-align: middle;
line-height: 0px;
}
Just add vertical-align: middle to your li
CSS
.nav-primary li {
list-style-type: none;
display: inline-block;
text-align: left;
font-size: 26px;
line-height: 0px;
vertical-align: middle;
}
DEMO HERE
You need to add vertical align to your li:
.nav-primary {
background: #CCC;
}
.nav-primary li {
list-style-type: none;
display: inline-block;
text-align: left;
font-size: 26px;
line-height: 0px;
vertical-align: middle; /* add this */
}
.nav-primary a {
display: inline-block;
padding: 32px 20px;
border: 1px dashed black;
/* border only used for display purpose of alignment*/
margin-right: -4px;
}
.nav-primary a:hover {
background: #FFF;
}
.menu {
width: 100%;
}
.menu-item {} .home a {
font-size: 0px;
}
.home a:after {
font-family: "dashicons";
content: " \f102";
font-size: 40px;
display: inline-block;
vertical-align: middle;
line-height: 0px;
}
<nav class="nav-primary">
<ul class="menu">
<li class="menu-item home">Home</li>
<li class="menu-item">Blog</li>
<li class="menu-item">Contact</li>
<li class="menu-item">About Us</li>
</ul>
</nav>

readjust Horizontal menu to resolution

I'm new to this, so I'm clueless.
Whenever I go to my site with a different resolution the menu changes a lot and does not align correctly. Just tell me if i need more of the html or css.
My webpage is Aulan.co
My code:
ul {
font-size: 25px;
color: black;
text-align: center;
list-style-type: none;
margin-bottom: 2em;
line-height: 150%;
margin-left: 3em;
margin-right: 5em;
}
#menu {
list-style-type: none;
margin: auto;
width: 90%;
height: auto;
padding: auto;
overflow: hidden;
background-color: #353B4E;
text-align: center;
font-size: 18px;
}
li {
text-align: center;
}
li a {
display: block;
color: white;
text-align: center;
padding: 5px 70px;
text-decoration: none;
height: auto;
}
li a:hover {
background-color: #111;
display: inline;
}
#menus {
float: left;
<h1> AuLan </h1>
<ul id="menu">
<li id="menus"><a class="active">Forside</a></li>
<li id="menus">Informasjon</li>
<li id="menus">Regler</li>
<li id="menus">Crew</li>
<li id="menus">Kontakt oss</li>
<li id="menus">Seatmap</li>
<li id="menus">Timeplan</li>
</ul>
it's not really clear what you want to achieve, but I tried to change your code in a way that I think you might want. I took out a lot of unneccessary code from the CSS and added some. In the HTML, i change the menusID to a class, since IDs should only be used once per page.
You can adjust especially the min-width and padding setting in the menu li a rule to your needs (but also the other width and padding settings)
#menu {
font-size: 25px;
list-style-type: none;
width: 90%;
background-color: #353B4E;
font-size: 18px;
padding: 10px 20px;
}
#menu li {
display: inline-block;
line-height: 150%;
}
#menu li a {
display: block;
min-width: 100px;
color: white;
padding: 5px 15px;
text-decoration: none;
}
#menu li a:hover {
background-color: #111;
}
<h1> AuLan </h1>
<ul id="menu">
<li class="menus"><a class="active">Forside</a></li>
<li class="menus">Informasjon</li>
<li class="menus">Regler</li>
<li class="menus">Crew</li>
<li class="menus">Kontakt oss</li>
<li class="menus">Seatmap</li>
<li class="menus">Timeplan</li>
</ul>

Centering text on a navigation bar

I need to center these links while leaving Santos Fire Department where it is
BTW the only reason that Santos Fire Department has two different tags is to avoid the hover animation.
ul.nav{
display: block;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
height: 3.3em;
}
ul.nav li {
float:left;
}
ul.nav li a{
display: block;
color: white;
padding: 14px 16px;
text-decoration: none;
text-align: center;
}
ul.nav li .navlogo{
overflow: hidden;
background-color: #333;
height: 3.3em;
}
ul.nav li a.navlogo{
display: inline-block;
padding-top: 10px;
margin-left: 10px;
font-size: 150%;
z-index: -1;
}
<nav class="navbar">
<ul class="nav">
<li id="logo"><a class="navlogo">Santos Fire Department</a></li>
<li id="nav">TeamSpeak (Temp Server)</li>
<li id="nav">US Server</li>
<li id="nav">EU Server</li>
<li id="nav">SantosRP</li>
</ul>
</nav>
Santos Fire Department in original position, navbar centered :)
.navbar {
background-color: #333;
}
.nav {
display: table;
margin: 0 auto;
}
ul.nav li {
display: inline-block;
}
ul.nav li a {
display: block;
color: white;
padding: 14px 16px;
text-decoration: none;
text-align: center;
}
.navlogo a {
color: white;
font-size: 150%;
margin: 8px;
position:absolute;
}
<nav class="navbar">
<span class="navlogo"><a>Santos Fire Department</a></span>
<ul class="nav">
<li id="nav1">TeamSpeak (Temp Server)
</li>
<li id="nav2">US Server
</li>
<li id="nav3">EU Server
</li>
<li id="nav4">SantosRP
</li>
</ul>
</nav>
Update
position:absolute; on .navlogo a class, might not be the best way but gives you the results desired.
First of all you should eliminate multiple ids like id="nav" this is important for styling.
Now the parent needs to be text-align: center; and for your #logo you can float: left; like now. Otherwise, never avoid flexbox, but remember the browser support http://pleeease.io/play/