Image while hovering a link [HTML+CSS] - html

So I want to be able to have a link which when hovered, display an image..
So far, I only found tutorial to change an image while it's hovered..
How should I do that please ?
BTW : I'm a total beginner in HTML..
Thanks !

Use adjacent sibling selector and the display property.
img {
display: none;
}
a:hover + img {
display: block;
}
<a href='http://example.com'>Hover Here</a>
<img src='https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png' width='200'>

jQuery for life.
$('.link').mouseover(function() {
$('.dog').show();
}).mouseleave(function() {
$('.dog').hide();
})
#import url('https://fonts.googleapis.com/css?family=Raleway');
.link {
height: 40px;
width: 200px;
border: 1px solid black;
text-align: center;
border-radius: 5px;
margin-bottom: 10px;
}
a {
text-decoration: none;
color: black;
font-size: 30px;
font-family: Raleway;
}
.dog {
background: url('https://i.ytimg.com/vi/opKg3fyqWt4/hqdefault.jpg');
height: 150px;
width: 150px;
background-size: cover;
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='link'>
<a href='http://www.google.com'>Hover me</a>
</div>
<div class='dog'>
</div>

Indeed there is couple ways to achieve what you want. probably if you are a beginner in html and css, the best for you is to use zer00ne snippet. Hovever, if you want to dig deeper I also have the following solution for you:
You can test it here
https://jsbin.com/barixeqigi/17/edit?html,css,js,output
HTML
<a href="#" title="super eye" alt="super eye">
hover
</a>
CSS
a {
position:relative;
}
a:after {
content:'';
display:block;
width: 200px;
height: 200px;
opacity:0;
background: url('http://cdn.arstechnica.net/wp-content/uploads/2016/02/5718897981_10faa45ac3_b-640x624.jpg') no-repeat center;
background-size: cover;
border-radius:50%;
position:absolute:
right:0px;
top:0px;
-webkit-transition: all 3s;
transition: all 3s;
}
a:hover:after {
opacity: 100;
}

Related

Cumulating Animation with CSS

I'm trying to make a kind of animated website only using CSS Animations with the :target selector
I made up my first cascade and then the main problem is encountered :
I can't animate anymore. Maybe because I am not sure of every lines of the code I am using, that is why I am coming to you.
Basically the effect is actually working on the 2nd link only.
Here is a small piece of my code:
.saq {
width: 110px;
height: 110px;
color: yellow;
margin-left: 815px;
border: 1px black solid;
margin-top: -550px;
transition: 4s ease-in-out;
position: absolute
}
.qaq {
width: 60px;
height: 110px;
margin-left: 1205px;
margin-top: -550px;
transition: 5s ease-in-out;
position: absolute;
display: inline;
cursor: auto;
background-color: black;
z-index: 1000
}
a {
font-size: 100px;
text-align: right
}
;
.navi {
margin-left: 400px;
transform: translate(300px, 200px);
}
nav a {
background-color: yellow;
display: inline-block
}
nav a:hover {
background-color: brown;
color: yellow;
}
#s1:target {
display: block;
transition: all 4s ease;
transform: translate(300px, 350px) rotate(90deg) scale(0.6);
overflow: hidden;
overflow-y: hidden
}
#move #s1:target~.saq {
transform: translateY(-1720px)
}
#move #s1:target~.qaq {
transform: translateY(-1720px)
}
<div id=move>
<nav class=navi id=s1>
<ul>Home</ul>
<ul>Creations</ul>
<ul>About</ul>
<ul>Contact</ul>
</nav>
<div class="qaq"></div>
<div class="saq"></div>
Here is the link of the page : http://faxe-kondi.16mb.com/bru.html
Here what I have done so far, is a lot of div moving after the #s1 is targeted.
What i am looking to do : Making a lot of div move after the #s3 is targeted.
Maybe it is a selector problem, or children/sibling, or maybe I cannot use two animation on the same div.
But of course there is a solution you can bring to me.
The :target selector works alright in your code. But you only use it for the #s1:target rule. Which in your HTML is only the second link.
For example:
.links>a {
display: inline-block;
width: 50px;
height: 50px;
}
.link1 {
background: red;
}
.link2 {
background: blue;
}
.link3 {
background: green;
}
.animated-box {
display: inline-block;
width: 50px;
height: 50px;
border-radius: 50px;
transition: border-radius 1s;
}
.animated-box:target {
border-radius: 0;
}
#box1 {
background: red;
}
#box2 {
background: blue;
}
#box3 {
background: green;
}
<div class="links">
<a class="link1" href="#box1"></a>
<a class="link2" href="#box2"></a>
<a class="link3" href="#box3"></a>
</div>
<div class="animated-box" id="box1"></div>
<div class="animated-box" id="box2"></div>
<div class="animated-box" id="box3"></div>
See, the difference here is how you apply the transition-effect (border-radius: 0). If you want to target only one element you can go with a selector like #s1:target but it then will only happen in case the element with id="s1" gets the target (meaning, the link with href="#s1" gets clicked).
You either want to specify more CSS rules like you did with #s1:target or you want to use a class instead like I did below.
can you test it?
<div id=move>
<nav class=navi id=s1>
<ul>Home</ul>
<ul>Creations</ul>
<ul>About</ul>
<ul>Contact</ul>
</nav>
<div class="qaq"></div>
<div class="saq"></div>
</div>

CSS :hover works but :active does not

I'm preparing a WordPress theme and can't figure why :active in my CSS doesn't work while :hover is working fine.
HTML:
(...)
<div id="mainMenu">
<div id="mm_links">
<a id="mm_1" href="index.php/about-icar/">About ICAR</a><br/>
<a id="mm_2" href="">News</a><br/>
<a id="mm_3" href="index.php/for-the-authors/">For the authors</a><br/>
<a id="mm_4" href="index.php/resources/">Resources</a><br/>
<a id="mm_5" href="index.php/contact-promotion/">Contact<br/>& promotion</a><br/>
</div>
<div id="mm_tail"></div>
</div>
(...)
CSS:
div#mainMenu{
float: left;
width: 140px;
height: 430px;
margin-top: 48px;
background-image: url("img/mainMenu.svg");
background-size:cover;
text-align: center;
}
div#mainMenu a{
font-family: 'Raleway', sans-serif;
font-size: 10.6pt;
text-decoration: none;
}
div#mainMenu a:link, div#mainMenu a:visited, div#mainMenu a:active {
color: #262E5B;
}
div#mainMenu a:hover{
color: #262E5B;
}
a#mm_1 {
position: relative;
display: table-cell;
top: 21px;
left: 18px;
width: 120px;
height: 35px;
vertical-align: middle;
}
a#mm_1:hover, a#mm_1:active { <-- THIS IS NOT WORKING
background-image: url('img/ElementAbout.png');
background-size: cover;
}
div#mm_links{
clear:both;
height: 430px;
}
div#mm_tail{
background-color: white;
border-left: 2px solid #262E5B;
border-right: 2px solid #262E5B;
border-bottom: 2px solid #262E5B;
width: 30px;
height: 100%;
clear: both;
float: right;
}
What are you trying to accomplish? If you remove the :hover and press the link I think you will find that the :active is working just fine. But it doesn't do much good since you are styling it the same as when you hover over it. So basically you are hovering over it and then the background-image shows, then you click the link and the same background-image keeps showing.
a#mm_1:active {
background-image: url('img/ElementAbout.png');
background-size: cover;
}
The :hover pseudo-class selects an element when the mouse cursor is right above it.
The :active pseudo-class applies styles when the element is clicked (or activated in another way).
In your code, your :hover and :active styles are identical.
a#mm_1:hover, a#mm_1:active {
background-image: url('img/ElementAbout.png');
background-size: cover;
}
You won't notice any difference when hovering or clicking.
However, give each a different style and you'll see the difference:
a#mm_1:hover { background-color: yellow; }
a#mm_1:active { background-color: red; }
DEMO

Background won't display

So I've took a project from codepen.io and modified it. But now I'm trying to add a background image and I can't display it... Here's my code:
body {
background-image: url("starwars.jpg");
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
div.window {
color: white;
width: 500px;
padding: .42rem;
border-radius: 5px;
background: #26466D;
margin: 1rem;
text-align: center;
font-family: BlueHighway, Arial Black, sans-serif;
margin: 0 auto;
}
div.window label {
display: block;
background: #660b0b;
font-size: larger;
border-radius: 5px;
padding: .6rem;
transition: .4s all linear;
}
div.window label:hover {
cursor: pointer; background: #311;
}
input.toggle ~ div {
height: 0px; margin: .2rem;
overflow: hidden;
transition: .6s all cubic-bezier(0.730, -0.485, 0.145, 1.620)
}
input.toggle:checked ~ div { height: 230px; }
input.toggle:checked + label { background: red; }
input.toggle { display: none; }
<div style="height: 240px; padding-top: 1.2rem">
<div class="window">
<input type="checkbox" id="punch" class="toggle">
<label for="punch">Use the Force, Luke.</label>
<div>
<img src="http://images.sequart.org/images/Star-Wars-still-use-the-force-luke-e1415132076759.jpg" style="max-width:100%;height:auto" alt="Ackbar">
</div>
</div>
</div>
If someone could find out why my background image is not displaying, that would be great!
Thanks.
I just tested your code and it works fine so I think what's happening is that the path of your background picture is wrong.
If your starwars image is not in the root folder with your html page then it cannot be url("starwars.jpg");. Check if you didn't put it in another folder or so.
Is the image "starwars.jpg" in the same folder as the .html file that is using it?

Using CSS for an image within a border

I've got some CSS and HTML that I'm working on, I wanted to sub out the content that is a div block for an image and keep the border with rounded edges with it. But the image isn't showing up when I preview the code. The CSS and HTML are linked correctly. Admittedly, this is just me tinkering to learn more about both CSS and HTML.
If you could look at this and give me some insight of how to get the image to show up in the rounded box, I would appreciate it.
EDIT: I'm afraid I wasn't entirely clear enough on what the issue was. The image in the title tag and that is associated with the "a.title" css code isn't the issue, that's just a header image.
The issue is that I want an image to appear in the div class="content" portion of the HTML with the image source coming from the CSS portion that is div.content.
I'm pretty bad at explaining my questions/problems, sorry. But thank you for all of your help thus far!
HTML:
<html>
<head>
<title>Some Title</title>
<link href="/Volumes/lastname/sitename/css/style.css" rel="stylesheet" type="text/css" media="all">
</head>
<body>
<div id="container">
<p class="title"><img src="/Volumes/last/sitename/media/header3.png"></img></p>
<div class="navbar">
<a class="nav" href="http://www.facebook.com">Facebook</a>
<a class="nav" href="http://www.twitter.com">Twitter</a>
</div>
<div class="content">
</div>
</div>
</body>
</html>
Here's the CSS - I know its more of the code than you need to know but here any way:
body {
background: #ffffff
width: 1000px;
height: 800px;
margin: 0 auto;
font-family: "Arial";
}
#container {
width: 900px;
height: 800px;
margin: 0 auto;
}
div.content {
background-image: url('/Volumes/last/sitename/media/imagename.jpg') no-repeat;
border-style: solid;
border-width: 2px;
width: 900px;
height: 500px;
margin-top: -20px;
border-radius: 7px;
border-color: #a0a0a0;
}
a.title {
margin-top:120px;
font-size: 36px;
}
div.navbar {
margin-top: -62px;
float: right;
font-size: 18px;
}
a.nav {
text-decoration: none;
color: #717171;
padding-right: 20px;
}
a.nav:hover {
color: #1299d6;
}
div.text {
margin-top: 100px;
}
p.text1 {
display: block;
text-align: center;
}
p.text2 {
display: block;
text-align: center;
}
p.text3 {
display: block;
text-align: center;
}
p.text4 {
display: block;
text-align: center;
}
div.links {
margin-top: 50px;
text-align: center;
}
a.links {
text-decoration: none;
color: #ffffff;
padding-left: 10px;
padding-top: 5px;
padding-right: 10px;
padding-bottom: 5px;
border-radius: 10px;
opacity: 0.6;
}
a.twitter {
background: #42a300;
}
a.contact{
background: #1299d6;
}
a.subbutton{
background: #690260;
}
a.links:hover {
opacity: 1.0;
}
First of all your image tag is wrong. It must be
<img src="/Volumes/last/sitename/media/header3.png" />
http://jsfiddle.net/vBRBM/
Test the code.
You should take the image out of the div and just make a rule for the class.
p.title {
background-image: url('/Volumes/last/sitename/media/imagename.jpg') no-repeat right top;
border-style: solid;
border-width: 2px;
width: 900px;
height: 500px;
margin-top: -20px;
border-radius: 7px;
border-color: #a0a0a0;
}
I suspect it could have something to do with the URL. maybe try the .. notation? It depends on where the picture is in relation to all your other files.
body
{
background-image:url(' *CHANGE THIS* ');
background-repeat:no-repeat;
background-position:right top;
border-style: solid;
border-width: 2px;
width: 900px;
height: 500px;
margin-top: -20px;
border-radius: 7px;
border-color: #a0a0a0;
}
img tags don't have anything in them so they don't need a separate closing tag. End it in the same tag by adding the slash on the end /> like
<img src="/Volumes/last/sitename/media/imagename.jpg" />

CSS: Button Visibility Problem

I am working on a project with a video player. I want to add play/pause and skip buttons together but one of the buttons is always invisible, however working. The codes I am using:
in .css file:
.buttons { position:absolute; top: 326px; left:150px; }
.buttons DIV { width: 26px; height: 20px; cursor: pointer; }
.buttons .pause { background-image: url("button_pause.png"); }
.buttons .play { background-image: url("button_play.png"); }
.buttons .skip { background-image: url("button_skip.png"); }
in html file:
<div class="buttons">
<div id="skip" onclick="skipCurrentSong();"></div>
<div id="playpause" onclick="setPlayPause();"></div>
</div>
the functions in js file work properly but the skip button is invisible. I have tried to create a different class in css file for the skip button and updated the html file accordingly but this gave the same output also. Can anyone say what mistake I am making and how to correct it?
Thanks in advance.
Some extra codes:
.css file:
#CHARSET "UTF-8";
BODY { height: 530px; overflow: hidden; }
#tv { width: 532px; height: 443px; background: url("tv.png") no-repeat; margin: 0 auto; margin-top: 20px; z-index: 3; position: relative; }
#title { color: #dddddd; text-align: right; float: right; margin-top: 320px; margin-right: 120px; }
.buttons { position:absolute; top: 326px; left:150px; }
.buttons DIV { width: 26px; height: 20px; cursor: pointer; background-color: white;}
.buttons .pause { background-image: url("button_pause.png"); }
.buttons .play { background-image: url("button_play.png"); }
.buttons .skip { background-image: url("button_skip.png"); }
FORM { display: block; margin: 0 auto; background: url("player.png"); height: 295px; width: 482px; clear: both; position: relative; top: -421px; margin-bottom: -295px; z-index: 4; }
FORM LABEL { color: #00aad4; margin-bottom: 10px; padding-top: 40px; }
FORM INPUT { border: none; border-bottom: 3px solid #00aad4; font-size: 24px; width: 200px; }
FORM * { display: block; margin: 0 auto; text-align: center; }
FORM .loader { margin-top: 10px; }
.loader { background: url("load.gif"); width: 16px; height: 16px; margin: 0 auto; visibility: hidden; }
.load .loader { visibility: visible; }
in html file:
<div id="tv">
<div id="title"></div>
<div class="buttons">
<div id="playpause" onclick="setPlayPause();"></div>
<div id="skip" onclick="skipCurrentSong();"></div>
</div>
</div>
Updated: This will give you three buttons. Do you want pause/play combined?
CSS:
.buttons { position:absolute; top: 326px; left:150px; }
.buttons div { width: 26px; height: 20px; cursor: pointer; background-color: white;}
.buttons #pause { background-image: url("button_pause.png"); }
.buttons #play { background-image: url("button_play.png"); }
.buttons #skip { background-image: url("button_skip.png"); }
HTML:
<div id="tv">
<div id="title"></div>
<div class="buttons">
<div id="play" onclick="setPlayPause();"></div>
<div id="pause" onclick="setPlayPause();"></div>
<div id="skip" onclick="skipCurrentSong();"></div>
</div>
</div>
I changed the .css code as:
.skipbutton { position:absolute; top:326px; left:120px; }
.skipbutton DIV { width: 26px; height: 20px; cursor: pointer; background-color: gray;}
.skipbutton .skip { background-image: url("button_skip.png"); }
.buttons { position:absolute; top: 326px; left:90px; }
.buttons DIV { width: 26px; height: 20px; cursor: pointer; }
.buttons .pause { background-image: url("button_pause.png"); }
.buttons .play { background-image: url("button_play.png"); }
and changed .html as:
<div id="tv">
<div id="title"></div>
<div class="skipbutton">
<div class="skip" onclick="skipCurrentSong();"></div>
</div>
<div class="buttons">
<div id="playpause" onclick="setPlayPause();"></div>
</div>
</div>
surpsiringly for skip button div class worked while for playpause button, div id works and div class just kills the button. It is a little awkward as the two buttons have the same structe in css file.
I tried to seperate the classes for two buttons earlier but this time it finally worked.
Thanks to lasseespeholt.