Switching image on hover in a button - html

I'm trying to change an image that is placed in a button on hover. So far, I have managed for the image itself to change when you hover over it but not for when the button itself is hovered. Here is the code.
<style>
.btn-large{
width: 300px;
height: 350px;
}
.movie{
width: 90px;
height: 90px;
position: relative;
margin-top: 25px;
}
#hardware:hover, #hardware:active{
background: #23c6c8;
color: white;
}
</style>
<a href="#" class="btn btn-large" id="hardware">
<figure>
<img class="movie" alt="ticket" src="http://i.imgur.com/u8wsfFL.png" onmouseover="this.src='http://i.imgur.com/BuK26gd.png'" onmouseout="this.src='http://i.imgur.com/u8wsfFL.png'" />
</figure>
<div class="details">
<h2>All Tickets</h2></br>
<p>View all tickets</p>
</div>
</a>

you need to move the event handlers to the anchor instead of the img and search for the img tag
Demo
<a href="#" class="btn btn-large" id="hardware"
onmouseover="this.getElementsByTagName('img')[0].src ='http://i.imgur.com/BuK26gd.png'"
onmouseout="this.getElementsByTagName('img')[0].src = 'http://i.imgur.com/u8wsfFL.png'">
<figure>
<img class="movie" alt="ticket" src="http://i.imgur.com/u8wsfFL.png" />
</figure>
<div class="details">
<h2>All Tickets</h2></br>
<p>View all tickets</p>
</div>
</a>

use something like this
<style>
.btn-large{
width: 300px;
height: 350px;
}
.image{
width: 90px;
height: 90px;
position: relative;
margin-top: 25px;
background:url("http://i.imgur.com/u8wsfFL.png");
}
.btn-large:hover .image{
background:url("http://i.imgur.com/BuK26gd.png");
}
.btn-large:hover .details{
background: #23c6c8;
color: red;
}
</style>
<div class="btn-large">
<div class="image">
</div>
<div class="details">
<h2>All Tickets</h2></br>
<p>View all tickets</p>
</div>
</div>

.btn-large {
width: 300px;
height: 350px;
}
.details {
background: url("http://i.imgur.com/u8wsfFL.png") no-repeat;
height: 90px;
}
.details:hover,
.details:active {
background: url("http://i.imgur.com/BuK26gd.png") no-repeat;
}
figure {
height: 90px;
}
<a href="#" class="btn btn-large" id="hardware">
<div class="details">
<figure>
</figure>
<h2>All Tickets</h2>
</br>
<p>View all tickets</p>
</div>
</a>
Quite simple - just add css for details and figure to your stylesheet and set a background image and a different one on hover. You can remove the alternating imgs from your html
Here is a fiddle

Related

How to display a background color on heading?

This is my first time designing a site. I have a created a slideshow, and it's working fine. It's just that I want my heading to have a background color so that it can be seen over the image. But I don't know why background color is not working.
This is my html:
<div class="slideshow">
<div class="slideshow-item-container">
<div class="slideshow-item">
<a href="humans/embryonic-development.html">
<img src="img/baby.jpg" alt="A newborn baby"/>
<h2 class="item-text">The Qur'an on Human Embryonic Development</h2></a>
</div>
<div class="slideshow-item">
<a href="humans/the-cerebrum.html">
<img src="img/brain.jpg" alt="The Cerebrum and Its Parts"/>
<h2 class="item-text">The Cerebrum in Quran</h2> </a>
</div>
<div class="slideshow-item">
<a href="humans/the-cerebrum.html">
<img src="img/ocean.jpg" alt="The Cerebrum and Its Parts"/>
<h2 class="item-text">Where the oceans meet</h2> </a>
</div>
<div class="slideshow-item">
<a href="humans/embryonic-development.html">
<img src="img/baby.jpg" alt="A newborn baby"/>
<h2 class="item-text">The Qur'an on Human Embryonic Development</h2></a>
</div>
</div>
</div>
And the CSS:
*{
margin: 0;
padding: 0;
}
.slideshow {
overflow: hidden;
margin-top: 20px;
}
.slideshow-item-container {
position: relative;
width: 400%;
left: 0;
animation: 20s slider infinite;
}
.slideshow-item {
width: 25%;
float: left;
}
h2.item-text {
margin-top: -48px;
margin-right: 20px;
text-align: right;
background-color: #2b5072;
color: white;
}
Despite the background property, it's still not showing it. Here is a screenshot:
screenshot of site with no background color appearing on heading
Just because you scrolled the text on the picture, you need to add the code below to make it overlap.
You can examine the snippet to test it.
h2.item-text {
.
.
.
position: relative;
z-index: 1;
}
* {
margin: 0;
padding: 0;
}
.slideshow {
overflow: hidden;
margin-top: 20px;
}
.slideshow-item-container {
position: relative;
width: 400%;
left: 0;
animation: 20s slider infinite;
}
.slideshow-item {
width: 25%;
float: left;
}
h2.item-text {
margin-top: -48px;
margin-right: 20px;
text-align: right;
background-color: #2b5072;
color: white;
position: relative;
z-index: 1;
}
<div class="slideshow">
<div class="slideshow-item-container">
<div class="slideshow-item">
<a href="humans/embryonic-development.html">
<img src="https://placeimg.com/1640/380/any" alt="A newborn baby" />
<h2 class="item-text">The Qur'an on Human Embryonic Development</h2>
</a>
</div>
<div class="slideshow-item">
<a href="humans/the-cerebrum.html">
<img src="https://placeimg.com/1640/380/any" alt="The Cerebrum and Its Parts" />
<h2 class="item-text">The Cerebrum in Quran</h2>
</a>
</div>
<div class="slideshow-item">
<a href="humans/the-cerebrum.html">
<img src="https://placeimg.com/1640/380/any" alt="The Cerebrum and Its Parts" />
<h2 class="item-text">Where the oceans meet</h2>
</a>
</div>
<div class="slideshow-item">
<a href="humans/embryonic-development.html">
<img src="https://placeimg.com/1640/380/any" alt="A newborn baby" />
<h2 class="item-text">The Qur'an on Human Embryonic Development</h2>
</a>
</div>
</div>
</div>
Try changing your images to the background image of your div tag. Here is an example:
<div class="square" style="border:solid 1px red; height:150px;background-
image:url('https://www.campsitecoders.com/img/google-seo-search-engines.jpg')">
Photo 4
https://codepen.io/susanwinters/pen/wvWjvRb

Image container not aligning bottom to other grid container

Hello,
As you can see from the photo above, I am trying to achieve a grid system. First grid is 3 images, second grid is a column, and third grid is a large image floated to the right of the 2nd grid. You can see this photo on my portfolio website: http://www.irwinlitvak.com
I have three images in the first grid that have a width of 31.33% and the first and second img have a margin-right of 3.005% to full up the container width.
In the next grid (grid-2), I have a two of my images floated left in a column and (grid-2-of-3) is floated right with a width of 65.556%.
I would like the top and bottom of the larger image to take up the full height of the grid, so the bottom of the big image aligns with the self-destructing box.
Here is the HTML & CSS:
.projects-grid {
margin: 100px auto 0;
width: 90%;
}
.projects-grid .title {
margin-bottom: 20px;
text-align: center;
}
.projects-grid h1 {
display: inline-block;
font-family: "Montserrat";
}
.grid-1 {
margin-bottom: 4%;
}
.grid-1-of-3 {
position: relative;
width: 31.33%;
float: left;
overflow: hidden;
}
.grid-2-of-3 {
position: relative;
width: 65.556%;
float: right;
}
.grid-1-of-3:first-child,
.grid-1-of-3:nth-child(2) {
margin-right: 3.005%;
}
.grid-3 {
position: relative;
display: inline-block;
width: 33%;
margin-bottom: 60px;
vertical-align: bottom;
}
.grid-5 {
position: relative;
display: inline-block;
width: 20%;
margin-bottom: 60px;
vertical-align: bottom;
}
.box-1 {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.grid-1-of-3:first-child {
margin-left: 0;
}
.grid-1-of-3:last-child {
margin-right: 0;
}
.big-box {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.grid-2 {
width: 31.33%;
float: left;
}
.grid-2 .box-cont {
width: 100%;
}
.grid-2 .box-cont:first-child {
margin-bottom: 4%;
}
.grid-2 .box-cont {
position: relative;
}
<section class="projects-grid clearfix">
<div class="row title">
<h2>Projects</h2>
</div>
<div class="grid-1 clearfix">
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img class="bdgt-app" src="assets/budget-app-x-ps.jpg" alt="budget-app pic">
</a>
<a href="https://budget-app-x.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Budget-App-X</h3>
<p>Manage your incomes and expenses in a fun and easy app.</p>
</div>
</div>
</a>
</div>
<h3>
Budget-App-X
</h3>
</div>
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img src="/assets/dice-game-x-ps.jpg" alt="dice-game">
</a>
<a href="https://dice-game-x.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Dice-Game</h3>
<p>Roll the dice. Test your luck and see who racks the most points.</p>
</div>
</div>
</a>
</div>
<h3>
Dice-Game
</h3>
</div>
<div class="grid-1-of-3">
<div class="box-1">
<a href="">
<img src="/assets/pomodoro-timer-x-ps.jpg" alt="pomodoro-app-timer">
</a>
<a href="http://pomodoro-app-timer.herokuapp.com" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Pomodoro-Timer</h3>
<p>A quick and easy solution to being productive. Set the time and get things done.</p>
</div>
</div>
</a>
</div>
<h3>
Pomodoro-Timer
</h3>
</div>
</div>
<div class="grid-2 clearfix">
<div class="box-cont">
<div class="box-1">
<a href="">
<img src="/assets/cucumberme-x-ps.jpg" alt="cucumber me">
</a>
<a href="http://www.cucumberme.com" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>CucumberMe</h3>
<p>CucumberMe is your way of anonymously sending cucumbers to a friend, ex or anyone you want.<br><br> Go and send one today! </p>
</div>
</div>
</a>
</div>
<h3>
CucumberMe
</h3>
</div>
<div class="box-cont">
<div class="box-1">
<a href="#">
<img src="/assets/self-destruct-x-ps.jpg" alt="to do list">
</a>
<a href="http://todos-irwin.herokuapp.com/" target="_blank">
<div class="box-overlay">
<div class="text-overlay">
<h3>Self Destructing To-Do-List</h3>
<p>A to-do-list that will delete itself within 10 seconds. How many chores can you list within that time? </p>
</div>
</div>
</a>
</div>
<h3>
<a href="http://todos-irwin.herokuapp.com/" target="_blank">
Self Destructing To-Do-List
</a>
</h3>
</div>
</div>
<div class="grid-2-of-3 clearfix">
<div class="box-cont">
<div class="big-box">
<a href="#">
<img src="/assets/omnifood-x-ps.jpg" alt="omnifood">
</a>
<a href="http://con.staging.thegateny.net/con/Omnifood/v1/" target="_blank">
<div class="box-overlay big-overlay">
<div class="text-overlay">
<h3>Omnifood</h3>
<p>My version of the food app Blue Apron. Take a look! </p>
</div>
</div>
</a>
</div>
<h3>
<a href="http://con.staging.thegateny.net/con/Omnifood/v1/" target="_blank">
Omnifood
</a>
</h3>
</div>
</div>
</section>
What you can do is as I show in the snippet below. You have a container for all your divs you want at the same height, which you give a set height. You then give the items on the left a container (with height: 100%) and make a div for the right item (height: 100%).
By doing this, you have a container for the items on the left, so you can make them, say, 50% each, and you have a right item that's the same height as the container on the left.
In order to make an image fit a div, either use background-size: cover or something similar. height:100%; width: auto also works for responsive images.
Hope it helps.
.outer {
background: blue;
width: 600px;
height: 200px;
}
.leftwrap {
width: 30%;
float: left;
height: 100%;
}
.left1 {
background: purple;
width: 100%;
height: 50%;
}
.left2 {
background: orange;
width: 100%;
height: 50%;
}
.right {
background: teal;
height: 100%;
width: 70%;
float: left;
}
/** New code **/
.image {
height: 80%;
width: auto;
border: 1px solid black;
}
.imagetext {
color: white;
text-align: center;
border: 1px solid black;
}
.left {
box-sizing: border-box;
padding-bottom: 30px;
}
<div class='outer'>
<div class='leftwrap'>
<div class='left left1'>
<div class="image">My image here</div>
<div class="imagetext">Some text</div>
</div>
<div class='left left2'>
<div class="image">My image here</div>
<div class="imagetext">Some text</div>
</div>
</div>
<div class='right'>3</div>
</div>

Why is my image not following the divs class?

I'm very new to html, here is my code:
.social-media {
height: 100px;
width: 100px;
border-radius: 25px;
}
<div class="social-media">
<a href="https://twitter.com/mytwitter" target="_blank">
<img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/256/Twitter-icon.png" alt="my twitter">
</a>
</div>
the twitter image is not changing from the css
Try this:
.social-media img {
height: 100px;
width: 100px;
border-radius: 25px;
}
Add Separate style for image to make it occupy full width of the parent
.social-media {
height: 100px;
width: 100px;
border-radius: 25px;
}
.social-media img{
width: 100%;
}
<div class="social-media">
<img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/256/Twitter-icon.png" alt="my twitter">
</div>
Your css is not targeting the image directly :
give your image an Id or Class so you target that specifically
.social-media-image {
height: 100px;
width: 100px;
border-radius: 25px;
}
<div class="social-media">
<a href="https://twitter.com/mytwitter" target="_blank">
<img class="social-media-image" src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/256/Twitter-icon.png" alt="my twitter">
</a>
</div>
you could target the image directly from the social media class
.social-media img {
height: 100px;
width: 100px;
border-radius: 25px;
}
<div class="social-media">
<a href="https://twitter.com/mytwitter" target="_blank">
<img src="http://icons.iconarchive.com/icons/limav/flat-gradient-social/256/Twitter-icon.png" alt="my twitter">
</a>
</div>
check out link on how css selector work

Display Images In A Row With Text Directly Underneath

I am trying to put a few images in a row and display text that is directly underneath them and centered this is for my college work. I have tried some code but could not get it to work.
<div class="test">
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 100px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 500px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
<p>
<a href="https://www.facebook.com">
<img height="200px" style="display: block; margin-left: 500px; float: left;border: 2px solid white; border-radius: 100%; margin-top: 30px;" src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</p>
</div>
Personally I would do so:
.test a {
margin-left: 10px;
float: left;
text-align: center;
overflow: auto;
}
.test a img {
width: 100px;
border:2px solid white;
border-radius: 50%;
}
<div class="test">
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
Key points:
Use HTML for markup. Use CSS for style. Separate them.
The p tag is not necessary.
To float the three block on one line you have to set 'float:left' to the <a> element not in the img.
If we use a float based layout we have to Clearing floats (because the floats' container doesn't want to stretch up to accomodate the floats). This is why I added 'overflow: auto' to the container named '.test'
Last but not least, there are tons of method for lay-out things with CSS. I recommend watching Flexbox.
First of all, close your <p> tags.
Then personally I would an inline-block to the p and remove the margin-left on the img.
.test {
text-align: center;
}
img {
display: block;
float: left;
border: 2px solid white;
border-radius: 100%;
margin-top: 30px;
}
p {
display: inline-block;
}
You needed to two things:
HTML wrapping DIVs to be able to control your blocks.
Using CSS
Please, try this fiddle which may meet your requirement:
<style>
div.test {
width:auto;
margin: auto;
}
div.block {
float: left;
}
div.block a{
display:inline-block;
margin-left: 50px;
}
div.block img {
border: 2px solid white;
border-radius: 100%;
width:150px;
}
h3 {
text-align: center;
}
</style>
<div class="test">
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
<div class='block'>
<a href="https://www.facebook.com">
<img src="https://scontent-lhr3-1.xx.fbcdn.net/v/t1.0-9/12512240_1005566046198664_2775546349199755757_n.jpg?oh=a37edadd99a4631e165accf6bd193a9f&oe=58C8AD58">
<h3>Test</h3>
</a>
</div>
</div>

Displaying Image caption with only HTML and CSS

I am trying to display caption on images.
This is my HTML
<div class="image-hover">
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
</div>
This is my CSS :
.image-hover {
overflow: hidden;
}
.image-hover .image-block {
width: 234px;
height: 100px;
display: inline-block;
border: 1px solid #666666;
}
.image-hover .image-block img {
width: 230px;
height: 100px;
border: 2px solid #fff;
}
.details, .image-backdrop {
float: left;
}
.details h4:after {
display: inline-block;
content:" ";
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 8px solid #666666;
margin: 0 10px;
}
This is my JsFiddel
My problem is how can I get image's caption to above of image?
Any comments are greatly welcome.
Thank you.
you should use position:relative; to the container and position:absolute; to the child container whom you want to on image it is styled as you want
http://jsfiddle.net/ADMvd/2/
Add this to your CSS
.details h4 {
color: white; /* just to make it look pretty */
}
.details {
position: absolute;
}
.image-overlay {
position: relative;
}
DEMO
EDIT
Note that you are using div tag inside your a tag so don't forget to add display: block to your a.image-overlay tag because inline elements can't contain any other type of elements. It does work but will cause many weird problems.
For starters height:100% won't work for div inside a