Add icon to menu items - icon not showing properly, css issue - html

I am trying to add icons to my menu items. I have read many different tutorials on it, but the css that all tutorials recommend will not work for me, and I'm not sure what to do.
Here is my html and css:
<div class="hike-menu">
<ul>
<li class="icon">Menu Item 1</li>
<li class="icon">Menu Item 2</li>
<li class="icon">Menu Item 3</li>
<li class="icon">Menu Item 4</li>
</ul>
</div>
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-repeat: no-repeat;
background-position: top;
}
And I have also uploaded in onto a jfiddle if you would like to take a look. You can see the exact problem I am having with the icon not showing. https://jsfiddle.net/katherinekonn/g1e4cok3/5/
I should also note that it is absolutely necessary I use background-image for this, I am unable to place an img link directly into the html. Does anyone know how I can fix it? I would like the icon to be above the list items text.
Here is an image of what I am trying to create:

The main issue is related to the size of the icon you used. The actual size is much bigger than you required. So either you resize the image or apply background image size in css. Then apply some padding-top for the <LI> to avoid overlapping of text and icon.
I tried modifying your css in fiddle and it worked perfect for me. please see it below
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-size: 20px;
background-repeat: no-repeat;
background-position: top;
padding-top: 30px;
}

Please try this. It will work.
HTML
<div class="hike-menu">
<ul>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 1
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
<li class="element">
<div class="icon">
</div>
<div class="text">
Menu Item 2
</div>
</li>
</ul>
</div>
CSS
ul li {
list-style-type: none;
display: inline-block;
}
.icon {
background-image: url("https://i.postimg.cc/ZWW7qTmm/calendar-yellow-copy.png");
background-repeat: no-repeat;
background-position: top;
background-size: cover;
display: block;
width: 24px;
height: 24px;
margin: 0 auto;
}
.text {
display: block;
}

Related

Align Nav-Bar to center of logo (Image)

I created a little test website with UIKit. Now that I messed around with that I wanted to try and create the design without using a pre-made framework. I am having issues with my navbar though.
This is the Original navbar that was created on the UIKit, see how the text is aligned vertically with the middle of the logo.
This is the second image, which is the Navbar i am trying to create, as you can see the text is on the same row as the image, but it is aligned with the top of the image (logo)
I am Trying to make the second image like the first image, the text aligned with the centre of the logo. I have tried "vertical-align: middle;" in my css but it doesn't seem to work... Any ideas?
Here's my code:
html {
font-family: monospace;
font-size: 12pt;
}
body {
margin: 0;
}
header {
background-color: honeydew;
}
nav .ul {
list-style-type: none;
display: table;
margin: 0;
padding: 0;
overflow: hidden;
float: left;
vertical-align: middle;
}
li {
display: table-cell;
vertical-align: middle;
}
<header>
<div class="row">
<nav>
<ul class="column small-hidden large-12">
<li class="column small-hidden large-3"> </li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-1">Yep</li>
<li style="float: center;" class="column small-hidden large-1 logo"><img alt="Website Logo" src="img/image.png"></li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-1">Yep</li>
<li class="column small-hidden large-3"> </li>
</ul>
</nav>
</div>
</header>
Thanks in advance!
You can try this:
nav li.img{ vertical-align: middle;}

CSS bug with Image on responsive web page

I have a bug in my CSS when it comes to a responsive page with images.
Demo: https://jsfiddle.net/xr4getom/
You'll notice on this example that a dark background (#222) appears at times when you resize the window. Is there a fix for this that would just force the image to take up this area - while keeping the ratio correct?
I have omitted the CSS from here as it goes over the character limit but if you click the demo link, you can see it.
<section class="news-bloc">
<div class="news-container">
<h1>Latest News</h1>
<ul class="news-list">
<li>
<a href='#' target='_blank'><img alt='' class='img-responsive photo-thumb image-link' src='https://scontent.cdninstagram.com/t51.2885-15/s320x320/e15/c157.0.406.406/14504934_1825657564379158_1219547695887155200_n.jpg?ig_cache_key=MTQwMDU3NTA0ODg3NjAyNTIxNA%3D%3D.2.c'>
<p>View Post</p></a>
</li>
</ul>
</div>
</section>
Set the image in the background of your <a> instead of using <img> tag. Like:
HTML:
<ul class="news-list">
<li>
<a href='#' target='_blank' style="background-image: url('https://scontent.cdninstagram.com/t51.2885-15/s320x320/e15/c157.0.406.406/14504934_1825657564379158_1219547695887155200_n.jpg?ig_cache_key=MTQwMDU3NTA0ODg3NjAyNTIxNA%3D%3D.2.c');">
<p>View Post</p>
</a>
</li>
</ul>
CSS:
.news-list li a {
display: flex;
width: 100%;
height: 200px;
background-size: cover;
background-position: center;
}
Have a look at this jsFiddle Demo.
Hope this helps!
Your <li> element is having width more than that of image. Try setting your li width to auto -
ul.news-list li {
float: left;
width: auto; <-- Changed here
margin-right: 1.63934%;
float: left;
margin-bottom: 1.63934%;
background-color: #222
}
Found a solution! :-)
ul.news-list>li>a {
width: 100%;
}
you can use margin-bottom:-5px; in the css code

I'm having trouble making a navbar with a logo in the center, and two links on either side with equal spacing

I want to create a navbar with a logo in the center, and two navbar items (links) on either side, width equal spacing. I also need the logo to be lined up center with the navbar items.
Here's the code i have thus far. I'm using bootstrap.
HTML:
<div class="nav">
<div class="container">
<ul>
<li> Navbaritem1 </li>
<li> Navbaritem2 </li>
</ul>
<div class="logo">
<img src="Img/logo.png" class="img-responsive">
</div>
<ul>
<li> Navbaritem3 </li>
<li> Navbaritem4 </li>
</ul>
</div>
</div>
CSS:
.nav li {
display: inline;
margin-left:5%;
margin-right:5%;
}
.logo {
width: 100px;
display: inline-block;
height: auto;
}
.logo img {
float: none;
padding-top:10%;
}
ul {
display: inline;
text-align:center;
width:30%;
}
Did you try centering a div inside the container?
<div class="container">
<div class="center">
Centered content here
</div>
</div>
And the css:
.center {
display: table;
margin: 0 auto;
}
Also this post might've helped you with a quick search.

HTML/CSS logo placement issue

I was wondering if someone could help me out with this (probably easy) issue that I am having.
What I am trying to do is place my logo on the left side of my site but have it above the two divs which contain the social media links in the top one and the website menu (aligned to the right) in the other div. I have supplied an image of what I am trying to achieve here: http://i59.tinypic.com/155j7tt.jpg (The blue image is the shape of the logo and how I want it too look above the divs)
I am using the getskeleton framework in case that helps at all.
Currently the code for the top two divs is the following:
<div class="bars social">
<div class="container">
<div class="sixteen columns right">
<img src="_img/social/facebook.png" alt="Facebook"> <img src="_img/social/twitter.png" alt="Twitter"> <img src="_img/social/youtube.png" alt="Youtube">
</div>
</div>
</div>
<div class="container">
<div class="sixteen columns right">
<ul>
<li>Home</li>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
<li>Link 4</li>
</ul>
</div>
</div>
Now my question is where/how do I place my code so that the logo can float above those two divs (and also hang a little below them as seen in the pic).
Everything I do either places it on top of one or the other but not both.
UPDATE:
The CSS for the full screen version is as follows:
.container { position: relative; width: 960px; margin: 0 auto; padding: 0; }
.container .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; }
.container .sixteen.columns { width: 940px; }
.bars {backgound-color:#FFF;}
.right {text-align:right;}
.bars.social {background-color:#101116; color:#FFF; height:29px; padding-top:4px; border-bottom:2px solid #063;}
Here is a way to add a logo using absolute positioning to push it up and on top of the social media links. Of course, substitute with your own logo.
http://jsfiddle.net/bzoc9vbj/
#logo {
width:64px;
height:64px;
position: absolute;
top:0;
left:0;
background-image:url('https://asciinema.org/assets/bitcoin-logo-48563026498d25219c7e2ec2b978184b.png');
}

How can I make my header completely inline using float?

I have some HTML, and I am trying to figure out a way to make my logo, nav menu and social media icons one a single line.
<div class="header">
<div class="logo"><h1>Logo</h1></div>
<ul class="nav">
<li class="menuitem">Home</li>
<li class="menuitem">Blog</li>
<li class="menuitem">Test</li>
<li class="menuitem">Contact</li>
</ul>
<div class="social-media">
<img src="facebook.jpg">
<img src="twitter.jpg">
<img src="pinterest">
</div>
</div>
I want to logo to the left, nav menu in the middle, and the social media icon to the right.
I just realized that I forgot to post my CSS:
div .h1 {
float: left;
}
li {
display: inline-block;
}
ul {
float: left;
}
.nav {
float: left;
}
The easiest way to achieve this is text-align: justify:
Take a look at this Fiddle
Another good Tutorial for this effect is found on Codrops.