One Image into Different Social links - html

I found this method of making one image featuring different social icons on it into different social links by using x and y icons to define the section of the image you want featured in a link.
The issue I'm having is that once I set up the code, the background image isn't showing up. If anyone could offer their insight into why this code isn't working as it shoul, it would be greatly appreciated!
CSS:
aside .social {
margin-top: 40px;
}
.social ul {
list-style-type: none;
margin: 0;
}
.social li {
display: block;
width: 24px;
height: 24px;
margin: 0 4px 6px 0;
display:-moz-inline-stack;
display:inline-block;
zoom:1;
*display:inline;
line-height: 20px;
}
.social li:nth-child(8n+0) {
margin-right: 0;
}
.social li a, .social li a:active, .social li a:visited {
opacity: 0.5;
-moz-transition: opacity .15s ease-in-out;
-o-transition: opacity .15s ease-in-out;
-webkit-transition: opacity .15s ease-in-out;
}
.social li a:hover {
opacity: 1;
}
.social li.facebook a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) 0 0; }
.social li.twitter a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -24px 0; }
.social li.youtube a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -48px 0; }
.social li.instagram a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -72px 0; }
.social li.google a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -96px 0; }
.social li.flickr a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -120px 0; }
.social li.linkedin a { background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png) -144px 0; }
HTML:
<h1>Find Us On</h1>
<div class="social">
<ul>
<li class="facebook"></li>
<li class="twitter"></li>
<li class="youtube"></li>
<li class="google"></li>
<li class="instagram"></li>
<li class="flickr"></li>
<li class="linkedin"></li>
</ul>
<div>
I have also created a JSFiddle for your convenience here: http://jsfiddle.net/HRHnY/
The code is rendering the list, it's just the background image isn't displaying...

Your anchors are collapsing to 0x0 because you have no content in them. They don't auto-expand to the size of the parent just because you have a background image. Explicitly give them a width/height like the li and you get http://jsfiddle.net/HRHnY/2/
Relevant CSS for the anchors:
display: block;
width: 24px;
height: 24px;
Alternatively you could set width and height to 100% of the parent instead of explicitly setting it.

Working jsFiddle Demo
The a elements, are inline and the width and height of them,
is calculated by the data within them.
So you must set them explicitly, add this rule to your CSS:
.social a {
display: inline-block;
width: 24px;
height: 24px;
}
TIP
It's better to write background-image only once in general selector:
.social a {
background: url(http://static.tumblr.com/csqo1yp/4uimntnjk/social.png);
}
And just change background-position for each element:
.social li.facebook a {
background-position: 0 0;
}
.social li.twitter a {
background-position: -24px 0;
}

Related

Anti Aliasing making strange gap in skewed navigation

I've problem with creating a skewed navigation, actually everything is good except the strange gap between navigation item links. I did bit of research and I saw that is because of Anti Aliasing technique.
I tried to hack it with ::before selector and/or with applying border-right attribute to the block, but no success.
There is code:
* {
margin: 0;
padding: 0;
}
header {
width: 100%;
background: #1d1e22;
overflow: hidden;
}
ul {
margin-left: 5%;
position: relative;
}
ul li {
float: left;
list-style: none;
}
ul li a {
display: block;
padding: 20px;
text-decoration: none;
color: #fff;
background: #444857;
transform: skew(-20deg);
transition: all 300ms ease-in-out;
}
ul li a:hover {
background: #fff;
color: #000;
}
ul li a span {
transform: skew(20deg);
display: block;
}
<header>
<ul>
<li><span>Home</span></li>
<li><span>About us</span></li>
<li><span>Services</span></li>
<li><span>Contact</span></li>
</ul>
</header>
I want it to be without the black gap, just in one tone. If you know how to fix it, I will appreciate if you share it.
The issue here is how browsers handle subpixel rendering. As you are transforming the shape, the browser applies some antialiasing on the edges of the shapes for a smoother rendering.
Because of this there is no guarantee that the edge of two elements will align perfectly. See an interesting article about it.
The quickest fix is to apply some negative margin so that the shapes overlap.
* {
margin: 0;
padding: 0;
}
header {
width: 100%;
background: #1d1e22;
overflow: hidden;
}
ul {
margin-left: 5%;
position: relative;
}
ul li {
float: left;
list-style: none;
margin-left: -2px;
}
ul li a {
display: block;
padding: 20px;
text-decoration: none;
color: #fff;
background: #444857;
transform: skew(-20deg);
transition: all 300ms ease-in-out;
}
ul li a:hover {
background: #fff;
color: #000;
}
ul li a span {
transform: skew(20deg);
display: block;
}
<header>
<ul>
<li><span>Home</span></li>
<li><span>About us</span></li>
<li><span>Services</span></li>
<li><span>Contact</span></li>
</ul>
</header>
I added a box-shadow: 1px 0 1px #444857 to the <a> tags; https://codepen.io/nosnetrom/pen/QPaMBQ

Making navbar link filled while on current page

I am currently trying to create a navbar that fills when hovered over a link. However, I would also like to have the link filled (or highlighted) while on the relative page. Any help would be much appreciated!
Note: This code has been retrieved from an open source.I am new learner of web technologies and working for a web project.
/*NAVIGATION */
body {
font-family: 'Roboto', sans-serif;
padding: 0;
margin: 0;
}
small {
font-size: 12px;
color: rgba(0, 0, 0, 0.4);
}
h1 {
text-align: center;
padding: 50px 0;
font-weight: 800;
margin: 0;
letter-spacing: -1px;
color: inherit;
font-size: 40px;
}
h2 {
text-align: center;
font-size: 30px;
margin: 0;
font-weight: 300;
color: inherit;
padding: 50px;
}
.center {
text-align: center;
}
section {
height: 100vh;
}
nav {
width: 60%;
margin: 0 auto;
background: #fff;
padding: 10px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a {
display: block;
padding: 15px;
text-decoration: none;
color: #aaa;
font-weight: 800;
text-transform: uppercase;
margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after {
width: 100%;
}
nav.fill ul li a {
transition: all 2s;
}
nav.fill ul li a:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
/* Keyframes */
#-webkit-keyframes fill {
0% {
width: 0%;
height: 1px;
}
50% {
width: 100%;
height: 1px;
}
100% {
width: 100%;
height: 100%;
background: #333;
}
}
<section style="background: #2ecc71; color: rgba(0, 0, 0, 0.5);">
<h2>Nav bar test</h2>
<nav class="fill">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Downloads
</li>
<li>More
</li>
<li>Contact
</li>
</ul>
</nav>
</section>
The best practice is just to add an "active" class to the current page button.
<li>Home</li>
And add "a.active" to every "a:hover" that you already have so it has the same css.
nav.fill ul li a:hover,
nav.fill ul li a.active { /* Here */
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after,
nav.fill ul li a.active:after { /* Here */
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
nav.stroke ul li a:hover:after,
nav.stroke ul li a.active:after { /* Here */
width: 100%;
}
Here is an jsfiddle live example: https://jsfiddle.net/884o5sjs/
(To get help faster, remember to create your own jsfiddle next time)
You could add the class="active" to the current page dynamically with php (suggested) or even with jQuery (not suggested), but since it looks like you are using ".html" you will have to add it manually on each page.
Hope this helps.
Looks like you've already achieved your first task of having it highlight when hovered. I would do this in php because that's the language I'm most comfortable, but then you'd also have to run a web server on your computer so hopefully you get some more helpful tips from some of the Jscript pros on here. If you do have to resort to php, one way I commonly do this is by having a variable on the page that lets the header know what page you're on, and then a few if statements that coorespond and apply a .current-page style.
I'm probably doing it the long way, but I just haven't learned Javascript yet.
the if statement would look like this within the li of the ul of the nav... <li <?php if ($title == "Home) { echo "class='current-page'"; } ?>>Home and so on for each element in the ul with the corresponding title, and title declarations in the body of the page.

CSS Drop-Down Navigation Links Cramped

I'm trying to create a responsive, drop-down CSS menu, and I have a media query that targets mobile devices (760 pixels). I'm trying to make all the links occupy the entire width, and that goes well, but the problem is when I display the drop down menu when the width is less than 760 pixels, all of the links of the drop down menu are cramped into the navigation links. I would like to know how to solve this problem, because I have been thinking for a long time and haven't figured out a solution. I want the drop-down menu for services to be directly below services, and the final contact link to go below the drop-down menu. This is the problem:
Below is the HTML and the CSS, as well as a link to the JSFiddle.
HTML:
<div class="wrapper">
<ul class="links">
<li id="active">home
</li><li>about
</li><li>services
<ul class="links">
<li>web development
</li><li>design templates
</li><li>networking
</li><li>custom builds
</li>
</ul>
</li><li>contact</li>
</ul>
</div>
CSS:
html,
body {
margin: 0;
padding: 0;
font-family: Source Sans Pro, Helvetica, sans-serif;
}
.wrapper {
width: 100%;
height: auto;
}
ul.links {
margin: 0px;
padding: 0px;
list-style: none;
background-color: #EBEBEB;
}
ul.links a {
color: #737373;
text-decoration: none;
}
ul.links ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
}
ul.links li {
background: none;
color: #737373;
display: inline-block;
position: relative;
font-size: 19px;
padding-top: 22px;
padding-bottom: 22px;
padding-left: 35px;
padding-right: 35px;
transition: background 0.2s linear 0s, color 0.2s linear 0s;
-webkit-transition: background 0.2s linear 0s, color 0.2s linear 0s;
}
ul.links ul li {
position: relative;
font-size: 18px;
display: block;
float: left;
width: 100%;
}
ul.links li:hover {
background-color: #6ECFFF;
}
ul.links li:hover ul {
display: block;
}
ul.links li:hover .link {
color: #F0F0F0;
}
ul.links ul li:hover .link2 {
color: #F0F0F0;
}
#active {
background-color: #6ECFFF;
}
#active a {
color: #F0F0F0;
}
#media screen and (max-width: 760px) {
ul.links li
{
width: 100%;
}
ul.links ul {
position: absolute;
left: 0;
}
ul.links ul li {
background: #EBEBEB;
}
}
JSFiddle: https://jsfiddle.net/7tkn7zzs/
You should make ul.links ul { to position: relative; in media query to display it proper.
ul.links ul {
position: relative;
left: 0;
}
Working Fiddle
ul.links ul {
position: relative;
left: -35px; /* equal to padding left */
}

CSS transition only working on mouseout

I am trying to make CSS-only dropdowns. I have some CSS that, when a nav item is hovered, its background color changes.
.horiz-nav {
background: linear-gradient(#EEE, #900) no-repeat fixed;
border: none;
outline: none;
}
.horiz-nav ul {
list-style: none;
}
.horiz-nav ul li {
display: inline-block;
padding: 1.2em;
clear: none;
float: left;
margin: 0 0;
background: #000;
width: 10em;
transition: all .5s ease-in;
}
.horiz-nav ul ul {
display: none;
position: absolute;
top: 73px;
height: 0;
transition: all .5s ease-in;
}
.horiz-nav ul ul li {
background: linear-gradient(#000, #F50) no-repeat fixed;
padding: 7px;
margin: 0 3px;
color: #FFF;
}
.horiz-nav ul li:hover {
background: linear-gradient(to bottom, #808080, #80108F);
}
.horiz-nav ul li:hover > ul {
display: block;
height: auto;
}
.horiz-nav ul li:hover > ul li {
display: list-item;
position: relative;
float: none;
left: -62px;
}
<nav class="horiz-nav">
<ul>
<li class="title">Example.com
</li>
<li>About
</li>
<li>Contact
</li>
<li>Programming <span class="caret"></span>
<ul>
<li>HTML</li>
<li>PHP</li>
</ul>
</li>
</ul>
</nav>
With this CSS, the background changes to the new color, but it doesn't fade, with the transition. It does, however fade back to the old color on mouseout. Why is the transition only working on mouseout? And how can I make the background fade by both mouseover and mouseout? FIDDLE
You can't, Gradients don't support transitions
What you can do ?
Add another element under the li with same width and height and position, this element has the gradient background, and play with his opacity when hovering the li.
li .background-holder{
position : absolute;
width : 100%;
height : 100%;
top : 0;
left : 0;
background : linear-gradient(to bottom, #808080, #80108F);
opacity : 0;
transition : all 0.5;
}
li:hover .background-holder{
opacity : 1;
}
JSFiddle : http://jsfiddle.net/qrky8yyp/1/

Hover on CSS menu only affects part of element?

I've made a css dropdown menu and I want each dropdown option to have a blue background when it is hovered on. However when I try this the background for the option will only be blue when the top half of it is hovered on. Here it is on jsfiddle. If you hover your mouse on the "products" option and then put the mouse under "plates" but above the gray horizontal line the background won't be blue. Can anybody help me? Thank you.
http://jsfiddle.net/hDWuJ/1/
HTML (Note this is a segment of my web page and so it does not have valid syntax)
<h1 id="title">Sample Text</h1>
<div id="HorzLineDiv"><hr></div>
<div id="MenuCenter">
<nav id="Menu" class="MenuBar">
<ul id="drop-nav">
<li>Home</li>
<li>Products <span id="arrowDown">&#9660</span>
<ul>
<li>Children's Stuff</li>
<li>Plates</li>
<li>Top Sellers</li>
</ul>
</li>
<li>Services <span id="arrowDown">&#9660</span>
<ul>
<li>Wash 'n' Fold</li>
<li>Blanket Making</li>
<li>Wedding Dress</li>
<li>Custom</li>
</ul>
</li>
</ul>
</nav>
</div>
CSS
body
{
background-color: #dfdfdf;
}
#title
{
text-align: center;
color: #07a8ca;
font-size:60pt;
margin: 0px;
padding: 0px;
text-shadow: 2px 2px 0px #888888;
}
h1
{
margin: 0px;
padding: 0px;
}
hr
{
height: 3px;
color: #07a8ca;
background: #07a8ca;
font-size: 0;
border: 0;
}
#HorzLineDiv
{
width: 95%;
margin: 2% 0% 3% 0%;
margin-left: auto ;
margin-right: auto ;
}
#Menu
{
width:100%;
}
#drop-nav
{
margin: 0 auto;
width: -webkit-fit-content;
width: -moz-fit-content;
width: fit-content;
}
ul
{
list-style: none;
padding: 0px;
margin: 0px;
}
ul li
{
display: block;
position: relative;
float: left;
display: inline;
padding: 12px 50px 8px 50px;
margin: 0px 5px 0px 5px;
border-left: 3px solid #07a8ca;
}
ul li:first-child
{
border-left: 0px;
}
li ul
{
display: none;
}
ul li a
{
display: block;
text-transform: uppercase;
text-decoration: none;
text-align:center;
color: #000;
font: 25px/1.1em "Kelly Slab","serif";
transition: color 0.4s ease 0s;
-moz-transition: color 0.4s ease 0s; /* Firefox 4 */
-webkit-transition: color 0.4s ease 0s; /* Safari and Chrome */
-o-transition: color 0.4s ease 0s; /* Opera */
}
ul li a:hover
{
color: #FF4D4D;
}
li:hover ul
{
display: block;
position: absolute;
}
li:hover li
{
float: none;
}
li:hover a
{
margin:0;
}
li:hover li a:hover
{
background: #21e8fa;
}
#drop-nav li ul li
{
border-top: 0px;
border-left: 0px;
}
#drop-nav ul li a
{
border-top: 3px solid #888;
padding: 13px 0px 13px 0px;
margin: -10px -8px;
text-align:center;
text-transform: none;
position:relative;
top: 13px;
color: #000;
}
#drop-nav ul
{
width:100%;
position:absolute;
right:-5px;
}
a
{
margin:0px;
padding:0px;
}
#arrowDown
{
font-size: 10pt;
vertical-align:text-bottom
}
The main issue is in your margins and padding, but this can be worked around by changing your ul li to display: block; instead of display: inline;.
Of course, this isn't a direct fix to the issue, and there still is an area at the bottom that doesn't work on hover, but it is much smaller than before. The proper way to go about fixing this is fixing your margins and padding.
Demo
UPDATE
Reading deeper into your code, I found the actual problem. It is not in margins or padding as I originally thought, but is a top property of 13px defined in #drop-nav ul li a. That top of 13px was creating a blank, inactive space in your list.
Get rid of that piece and it is working fine: DEMO