So I have made a simple HTML and CSS website with the background image currently set as the ocean picture.
Here is the code for this website
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Website1</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header>
<div class="main">
<ul>
<li class="active">Home</li>
<li>Cooking</li>
<li>Writing</li>
<li>Creative</li>
<li>Photography</li>
</ul>
</div>
<div class="title">
<h1>Nila Palmo Ram</h1>
</div>
<div class="button">
ARTICLES
ARTWORK
</div>
</header>
</body>
</html>
CSS:
*{
margin: 0;
padding: 0;
font-family: Century Gothic; }
header{
background-image: url(../2.jpg);
height: 100vh;
background-size: cover;
background-position: center;
}
ul{
float: right;
list-style-type: none;
margin-top: 25px;
}
ul li{
display: inline-block;
}
ul li a{
text-decoration: none;
color: #fff;
padding: 5px 20px;
border: 1px solid transparent;
transition: 0.6s ease;
}
ul li a:hover{
background-color: #fff;
color: rgb(115, 196, 233);
}
ul li.active a{
background-color: #fff;
color: rgb(115, 196, 233);
}
.main{
max-width: 1200px;
margin: auto;
}
.title{
position: absolute;
top: 10%;
left: 20%;
transform: translate(-50%,-50%);
}
.title h1{
color: #fff;
font-size: 70px;
}
.button{
position: absolute;
top: 62%;
left: 50%;
transform: translate(-50%,-50%);
}
.btn{
border: 1px solid #fff;
padding: 10px 30px;
color: #fff;
text-decoration: none;
transition: 0.6s ease;
}
.btn:hover{
background-color: #fff;
color: rgb(115, 196, 233);
}
For this website I want the background image to be a slider showing three images. I have built the slider separately. Here is the code for the slider:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Website2</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="slideshow-container">
<div class="mySlides fade">
<img src="1.png" style="width:100%">
<div class="text">Rustic wall decor out of reclaimed wood</div>
</div>
<div class="mySlides fade">
<img src="2.png" style="width:100%">
<div class="text">Make memorising easier with spaced repetition</div>
</div>
<div class="mySlides fade">
<img src="3.png" style="width:100%">
<div class="text">Stunning wall art using washi tape</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<script>
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
for(i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if(slideIndex > slides.length) {
slideIndex = 1
}
slides[slideIndex - 1].style.display = "block";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
</script>
</body>
</html>
CSS:
* {
box-sizing: content-box;
}
body {
font-family: Verdana, sans-serif;
margin: 0
}
.mySlides {
display: none
}
img {
vertical-align: middle;
}
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/* Caption text */
.text {
color: #ffffff;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 10s;
animation-name: fade;
animation-duration: 10s;
}
#-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
Could someone please tell me how I can make the slider of pictures the background of my website?
Thank you!
Make use of position:absolute and set the container height and width to 100%. (I used vh & vw to take the device/view height and width).
I hope you can take it forward. Cheers!!!
// no change here
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
slides[slideIndex - 1].style.display = "block";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
* {
box-sizing: content-box;
}
body {
font-family: Verdana, sans-serif;
margin: 0
}
.mySlides {
display: none;
/* added */
position: absolute;
left: 0;
top: 0;
height: 100vh;
width: 100vw;
}
/* added */
.mySlides img {
height: 100%;
width: 100%;
object-fit: cover;
}
.slideshow-container {
position: relative;
margin: auto;
}
/* Caption text */
.text {
color: #ffffff;
font-size: 15px;
padding: 8px 12px;
box-sizing: border-box;
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
}
/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 10s;
animation-name: fade;
animation-duration: 10s;
}
#-webkit-keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
#keyframes fade {
from {
opacity: .4
}
to {
opacity: 1
}
}
/* On smaller screens, decrease text size */
#media only screen and (max-width: 300px) {
.prev,
.next,
.text {
font-size: 11px
}
}
<!-- image urls changed -->
<div class="slideshow-container">
<div class="mySlides fade">
<img src="https://images.unsplash.com/photo-1422246654994-34520d5a0340?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80" style="width:100%">
<div class="text">Rustic wall decor out of reclaimed wood</div>
</div>
<div class="mySlides fade">
<img src="https://images.unsplash.com/photo-1523706120980-3f90ca135ad6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80" style="width:100%">
<div class="text">Make memorising easier with spaced repetition</div>
</div>
<div class="mySlides fade">
<img src="https://images.unsplash.com/photo-1578301978018-3005759f48f7?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1928&q=80" style="width:100%">
<div class="text">Stunning wall art using washi tape</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
I have a social media button at the home page of my personal website. Actually it is working pretty well but when I try to add a text on the button (eg. FOLLOW) the text layer makes it unclickable. My code has no JS function involved. How can I solve this problem?
Thanks in advance.
Edit: CSS code added.
Edit #2: Thank you for all the answers. However the <button> tag and JS codes didn't work for me in this situation. I finally managed to reduce the text layer area by removing height and width properties from the .social-text class and now the text doesn't affect the button functionality. It still overlaps the button but at a minimum area and doesn't cause an issue anymore. I'm adding a screenshot of fixed button. Happy coding!
HTML:
<div>
<ul id="menu">
<a class="menu-button icon-plus" href="#menu" title="Show navigation"></a>
<a class="menu-button icon-minus" href="#0" title="Hide navigation"></a>
<li class="menu-item">
<a href="https://www.instagram.com" target="_blank">
<span class="fa fa-instagram"></span>
</a>
</li>
<li class="menu-item">
<a href="https://www.facebook.com" target="_blank">
<span class="fa fa-facebook"></span>
</a>
</li>
<li class="menu-item">
<a href="https://twitter.com" target="_blank">
<span class="fa fa-twitter"></span>
</a>
</li>
<li class="menu-item">
<a href="https://linkedin.com/in" target="_blank">
<span class="fa fa-linkedin"></span>
</a>
</li>
</ul>
<span class="social-text">FOLLOW</span>
</div>
CSS:
#menu {
text-align: center;
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 23vw;
margin-left: 23vw;
margin-top: 6vw;
list-style: none;
font-size: 2.5vw;
}
.menu-button {
opacity: 0;
z-index: -1;
}
.menu-button {
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 50%;
margin: -5.8vw 0 0 -5.8vw;
border-radius: 50%;
background: #424242;
background-size: 100%;
overflow: hidden;
text-decoration: none;
}
#menu:not(:target)>a:first-of-type,
#menu:target>a:last-of-type {
opacity: 1;
z-index: 1;
}
#menu:not(:target)>.icon-plus:before,
#menu:target>.icon-minus:before {
opacity: 1;
}
.menu-item {
width: 5.5vw;
height: 5.5vw;
position: absolute;
left: 55%;
line-height: 1vw;
top: 70%;
margin: -3.9vw 0 0 -3.9vw;
border-radius: 50%;
background-color: #424242;
transform: translate(0vw, 0vw);
transition: transform 500ms;
z-index: -2;
transition: .5s;
}
.menu-item:hover{
opacity: 0.5;
box-shadow: 0 0.4vw 0.8vw black;
}
.menu-item a {
color: #fff;
position: relative;
top: 30%;
left: 0;
text-decoration: none;
}
#menu:target>.menu-item:nth-child(6) {
transform: rotate(60deg) translateY(-11.7vw) rotate(300deg);
transition-delay: 0s;
}
#menu:target>.menu-item:nth-child(5) {
transform: rotate(20deg) translateY(-12.1vw) rotate(-20deg);
transition-delay: 0.1s;
}
#menu:target>.menu-item:nth-child(3) {
transform: rotate(-20deg) translateY(-12.1vw) rotate(20deg);
transition-delay: 0.2s;
}
#menu:target>.menu-item:nth-child(4) {
transform: rotate(-60deg) translateY(-11.7vw) rotate(60deg);
transition-delay: 0.3s;
}
.social-text {
text-align: center;
width: 11vw;
height: 11vw;
position: absolute;
left: 50%;
top: 23vw;
margin-left: 23vw;
margin-top: 6vw;
z-index: 2;
}
Use a button tag in your span i.e,
<span><button class="social-text">Follow</button></span>
or either directly use <button> no need to add <span> . Here goes the JS:-
const btn=document.querySelector('.social-text');
btn.addEventListener("click",function(){
console.log("Followed");
})
You can try using a <button>
const btn = document.getElementById("btn-follow");
btn.addEventListener("click", () => {
console.log("followed");
});
<button id="btn-follow">FOLLOW</button>
Or you could add a role="button" to your span tag
const span = document.getElementById("span-follow");
span.addEventListener("click", () => {
console.log("followed");
});
<span id="span-follow" role="button">FOLLOW</span>
If you want to create a circle button, you can create a circle with a <div> and use it like a <button>
const btn = document.getElementById("btn-follow");
btn.addEventListener("click", () => {
console.log("followed");
});
.social-circle {
text-align: center;
width: 11vw;
height: 11vw;
line-height: 11vw;
border-radius: 50%;
background: #F77;
}
.social-text {
color: #fff;
}
.cursor-pointer {
cursor: pointer;
}
<div class="social-circle cursor-pointer" id="btn-follow" role="button">
<span class="social-text" role="button">FOLLOW</span>
</div>
You haven't used the button tag. So, only the 'Follow' text is showing. Try this.
<button class="social-text">Follow</button>
I'm trying to make a card that flipping on hover. To hide the back part of a card I use backface-visibility: hidden. But it only hides background of the back part while all the elements are still visible on the front side in rotated variant.
I use Google Chrome.
Here's my html code
<div class="card">
<div class="card__side card__side--front">
<div class="card__picture card__picture--1"></div>
<div class="card__heading">
<span class="card__heading-span card__heading-span--1">
The sea explorer
</span>
</div>
<div class="card__details">
<ul class="card__list">
<li class="card__item">3 day tour</li>
<li class="card__item">Up to 30 people</li>
<li class="card__item">2 tour guides</li>
<li class="card__item">Sleep in cozy hotels</li>
<li class="card__item">Difficulty: easy</li>
</ul>
</div>
</div>
<div class="card__side card__side--back card__side--back-1">
<div class="card__cta">
<div class="card__price-box">
<p class="card__price--only">Only</p>
<p class="card__price--value">$297</p>
</div>
Book now
</div>
</div>
</div>
And here's my SASS code
.card {
position: relative;
height: 52rem;
perspective: 150rem;
&__side {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 52rem;
border-radius: 3px;
overflow: hidden;
box-shadow: 0 1.5rem 4rem rgba($color-black, .15);
transform-style: preserve-3d;
backface-visibility: hidden;
transition: all .8s ease;
&--front {
background-color: $color-white;
}
&--back {
transform: rotateY(180deg);
&-1 {
background-image:
linear-gradient(to right bottom,$color-secondary-light,$color-secondary-dark);
}
&-2 {}
&-3 {}
}
}
&:hover &__side--front {
transform: rotateY(-180deg);
}
&:hover &__side--back {
transform: rotateY(0);
}
// Front side styles
&__picture {
&--1 {}
&--2 {}
&--3 {}
}
&__heading {
}
&__heading-span {
&--1 {}
&--2 {}
&--3 {}
}
&__details {
}
&__list {
width: 80%;
margin: 0 auto;
list-style-type: none;
}
&__item {
&:not(:last-child) {
border-bottom: 1px solid $color-gray-light-2;
}
}
//Back side styles
&__cta {
#include absoluteCenter();
width: 90%;
text-align: center;
}
&__price-box {
margin-bottom: 6rem;
color: $color-black;
text-align: center;
}
&__price--only {
font-size: 1.4rem;
text-transform: uppercase;
}
&__price--value {
font-size: 6rem;
font-weight: 300;
}
}
And this is how the problem actually looks like in Chrome.
Adding transform-style: preserve-3d to .card instead of .card__side fixed the bug for me.
I am working on a pretty simple flexbox gallery editor. I got it working in chrome pretty fast, but with Firefox I am experiencing trouble.
This is how it looks in chrome
And this is how it looks in Firefox
What I could find out by inspecting is, that the space on the right in Firefox equals the width of the add button. I checked some styling but just couldn't find the issue with my css.
Here is my scss and a link to a Pastebin with the CSS: https://pastebin.com/FbAPzM8P
.gallery-images {
text-align: center;
position: relative;
&.horizontal-scroll {
overflow-x: auto;
overflow-y: hidden;
padding-top: 7.5%;
padding-left: 2em;
height: 100%;
display: flex;
.gallery-image {
height: 80%;
display: flex;
flex-wrap: wrap;
flex: 0 0 0;
.gallery-image-content {
display: flex;
flex: 0 0 100%;
height: 100%;
.gallery-image-action {
width: 8em;
}
.gallery-image-content {
height: 100%;
}
.gallery-image-image, .gallery-image-action {
display: flex;
height: 100%;
> img {
height: 100%;
}
}
}
.gallery-image-action-bar {
flex: 0 0 100%;
padding-right: 10px;
padding-left: 10px;
margin-top: -18px;
.button-bar {
margin-left: 7.5em;
text-align: left;
padding-right: 2px;
.button-action-left {
float: left;
}
.button-action-right {
float: right;
margin-right: -2px;
}
}
}
}
}
/** different way of displaying the editor **/
.gallery-image {
.gallery-image-content {
.gallery-image-image, .gallery-image-action {
position: relative;
border: 10px solid transparent;
.gallery-image-edit, .gallery-image-add, .gallery-image-edit-button {
cursor: pointer;
transition: transform 0.3s, background 0.3s, opacity 0.3s;
transform: scale3d(1, 1, 1);
&:hover {
background: darken($gray-100, 6%);
transform: scale3d(0.95, 0.95, 1);
}
}
.gallery-image-edit-button {
background: $gray-100;
position: absolute;
top: 0;
left: 0;
opacity: 0;
z-index: 10;
&:hover {
opacity: 0.8;
border-radius: 4px;
+ .gallery-image-edit {
background: darken($gray-100, 6%);
transform: scale3d(0.95, 0.95, 1);
border-radius: 4px;
}
}
&::before, &::after {
position: absolute;
top: 50%;
left: 0;
margin-top: -0.35em;
width: 100%;
color: $primary;
font-size: 1.5em;
font-family: FontAwesome;
pointer-events: none;
}
&::before {
content: '\f040';
}
&::after {
margin-top: -0.5em;
color: $primary;
content: '\f040';
font-size: 3em;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
transform: scale3d(2, 2, 1);
}
}
.gallery-image-edit {
opacity: 1;
z-index: 8;
}
> div {
width: 100%;
height: 100%;
&.gallery-image-add {
border-radius: 4px;
background: darken($gray-100, 2%);
&::before, &::after {
position: absolute;
top: 50%;
left: 0;
margin-top: -0.35em;
width: 100%;
color: $primary;
font-size: 1.5em;
font-family: FontAwesome;
pointer-events: none;
}
&::before {
content: '\f067';
}
&::after {
margin-top: -0.5em;
color: $primary;
content: '\f00c';
font-size: 3em;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
transform: scale3d(2, 2, 1);
}
}
}
}
}
.gallery-image-action-bar {
.button-bar {
.button-action-left {
#extend .button;
#extend .button.primary;
}
.button-action-right {
#extend .button;
#extend .button.primary;
}
}
}
}
}
Here is the SCSS highlighted: https://github.com/Jinya-CMS/Jinya-Gallery-CMS/blob/0af7c5dc7644d35f09de9edb3fbc98a863ececb7/src/DesignerBundle/Resources/public/scss/_gallery-designer.scss
And this the rendered HTML, here is a Pastebin to the HTML rendered by Firefox: https://pastebin.com/pjRvdEYJ
<div class="gallery-images horizontal-scroll" data-source="http://localhost:8000/designer/gallery/artworks/images" data-move="http://localhost:8000/designer/gallery/artworks/%23tempid%23">
<!-- ko foreach: images -->
<div class="gallery-image">
<div class="gallery-image-content">
<div class="gallery-image-action">
<div class="gallery-image-add" role="button" data-bind="click: $root.addImage"></div>
</div>
<div class="gallery-image-image">
<div class="gallery-image-edit-button" role="button" data-bind="click: $root.editImage"></div><img data-bind="attr: { src: source }" class="gallery-image-edit" src="https://placebear.com/1920/1080" /></div>
</div>
<div class="gallery-image-action-bar">
<div class="button-bar">
<!-- ko if: $index() !== 0 --><!-- /ko -->
<!-- ko if: $index() !== ($parent.images().length - 1) -->
<!-- /ko -->
</div>
</div>
</div>
<div class="gallery-image">
<div class="gallery-image-content">
<div class="gallery-image-action">
<div class="gallery-image-add" role="button" data-bind="click: $root.addImage"></div>
</div>
<div class="gallery-image-image">
<div class="gallery-image-edit-button" role="button" data-bind="click: $root.editImage"></div><img data-bind="attr: { src: source }" class="gallery-image-edit" src="http://localhost:8000//public/content_image/d80dfe5ad6693c43a31019ee9398554fd7cc4470fcec159a427e886ab9634982" /></div>
</div>
<div class="gallery-image-action-bar">
<div class="button-bar">
<!-- ko if: $index() !== 0 -->
<!-- /ko -->
<!-- ko if: $index() !== ($parent.images().length - 1) -->
<!-- /ko -->
</div>
</div>
</div>
<div class="gallery-image">
<div class="gallery-image-content">
<div class="gallery-image-action">
<div class="gallery-image-add" role="button" data-bind="click: $root.addImage"></div>
</div>
<div class="gallery-image-image">
<div class="gallery-image-edit-button" role="button" data-bind="click: $root.editImage"></div><img data-bind="attr: { src: source }" class="gallery-image-edit" src="http://localhost:8000//public/content_image/4c58d75659edeb84f342376679c9f5382db0181920f9206fcc7e86648a8246c9" /></div>
</div>
<div class="gallery-image-action-bar">
<div class="button-bar">
<!-- ko if: $index() !== 0 -->
<!-- /ko -->
<!-- ko if: $index() !== ($parent.images().length - 1) --><!-- /ko -->
</div>
</div>
</div><!-- /ko -->
<div class="gallery-image">
<div class="gallery-image-content">
<div class="gallery-image-action">
<div class="gallery-image-add" role="button" data-bind="click: addImage"></div>
</div>
</div>
</div>
</div>
Does anyone have an idea for me where I can check for the issue or even has a solution?
I'm trying to show a description when hovering over an image. I've already done it in a less than desirable way, using image sprites and hovers here: I want it to look exactly like how I have it, but using real text instead of an image.
I've tried a few different things but I can't seem to figure out how to do it. I'm trying to do it using HTML and CSS only, but I'm not sure if that's possible.
Feel free to poke around in my code, I'll paste what I think is relavent here.
HTML
div#projectlist {
width: 770px;
margin: 0 auto;
margin-top: 20px;
margin-bottom: 40px;
}
div#buzzbutton {
display: block;
float: left;
margin: 2px;
background: url(content/assets/thumbnails/design/buzz_sprite.jpg) 0 0px no-repeat;
width: 150px;
height: 150px;
}
div#buzzbutton:hover {
background: url(content/assets/thumbnails/design/buzz_sprite.jpg);
width: 150px;
height: 150px;
background-position: 0 -150px;
}
div#slinksterbutton {
display: block;
float: left;
background: url(content/assets/thumbnails/design/slinkster_sprite.jpg) 0 0px no-repeat;
width: 150px;
height: 150px;
margin: 2px;
}
div#slinksterbutton:hover {
background: url(content/assets/thumbnails/design/slinkster_sprite.jpg);
width: 150px;
height: 150px;
background-position: 0 -150px;
}
<div id="projectlist">
<div id="buzzbutton">
<img src="content/assets/thumbnails/transparent_150x150.png" alt="" />
</div>
<div id="slinksterbutton">
<img src="content/assets/thumbnails/transparent_150x150.png" alt="" />
</div>
</div>
It's simple. Wrap the image and the "appear on hover" description in a div with the same dimensions of the image. Then, with some CSS, order the description to appear while hovering that div.
/* quick reset */
* {
margin: 0;
padding: 0;
border: 0;
}
/* relevant styles */
.img__wrap {
position: relative;
height: 200px;
width: 257px;
}
.img__description {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(29, 106, 154, 0.72);
color: #fff;
visibility: hidden;
opacity: 0;
/* transition effect. not necessary */
transition: opacity .2s, visibility .2s;
}
.img__wrap:hover .img__description {
visibility: visible;
opacity: 1;
}
<div class="img__wrap">
<img class="img__img" src="http://placehold.it/257x200.jpg" />
<p class="img__description">This image looks super neat.</p>
</div>
A nice fiddle: https://jsfiddle.net/govdqd8y/
EDIT:
There's another option if you don't want to explicitly set the height of the <img> on the wrapping <div>, and that is simply setting the <div>'s display to inline-block. (Keep in mind, though, that it won't look good if the image fails to load.)
If you choose this option, you'll notice that there'll be a slight spacing between the <img> and the bottom of the wrapping <div>. That's because of the <img>'s default vertical-align value of baseline. If you set it to bottom it will disappear.
Here's a fiddle using this option: https://jsfiddle.net/joplomacedo/5cL31o0g/
In your HTML, try and put the text that you want to come up in the title part of the code:
<a href="buzz.html" title="buzz hover text">
You can also do the same for the alt text of your image.
You can also use the title attribute in your image tag
<img src="content/assets/thumbnails/transparent_150x150.png" alt="" title="hover text" />
This is what I use to make the text appear on hover:
* {
box-sizing: border-box
}
div {
position: relative;
top: 0px;
left: 0px;
width: 400px;
height: 400px;
border-radius: 50%;
overflow: hidden;
text-align: center
}
img {
width: 400px;
height: 400px;
position: absolute;
border-radius: 50%
}
img:hover {
opacity: 0;
transition:opacity 2s;
}
heading {
line-height: 40px;
font-weight: bold;
font-family: "Trebuchet MS";
text-align: center;
position: absolute;
display: block
}
div p {
z-index: -1;
width: 420px;
line-height: 20px;
display: inline-block;
padding: 200px 0px;
vertical-align: middle;
font-family: "Trebuchet MS";
height: 450px
}
<div>
<img src="https://68.media.tumblr.com/20b34e8d12d4230f9b362d7feb148c57/tumblr_oiwytz4dh41tf8vylo1_1280.png">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing <br>elit. Reiciendis temporibus iure dolores aspernatur excepturi <br> corporis nihil in suscipit, repudiandae. Totam.
</p>
</div>
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<!DOCTYPE html>
<html>
<head></head>
<body>
<div class="container">
<img src="http://lorempixel.com/500/500/" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</body>
</html>
Reference Link W3schools with multiple styles
HTML
<img id="close" className="fa fa-close" src="" alt="" title="Close Me" />
CSS
#close[title]:hover:after {
color: red;
content: attr(title);
position: absolute;
left: 50px;
}
I saw a lot of people use an image tag. I prefer to use a background image because I can manipulate it. For example, I can:
Add smoother transitions
save time not having to crop images by using the "background-size: cover;" property.
The HTML/CSS:
.overlay-box {
background-color: #f5f5f5;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
}
.overlay-box:hover .desc,
.overlay-box:focus .desc {
opacity: 1;
}
/* opacity 0.01 for accessibility */
/* adjust the styles like height,padding to match your design*/
.overlay-box .desc {
opacity: 0.01;
min-height: 355px;
font-size: 1rem;
height: 100%;
padding: 30px 25px 20px;
transition: all 0.3s ease;
background: rgba(0, 0, 0, 0.7);
color: #fff;
}
<div class="overlay-box" style="background-image: url('https://via.placeholder.com/768x768');">
<div class="desc">
<p>Place your text here</p>
<ul>
<li>lorem ipsum dolor</li>
<li>lorem lipsum</li>
<li>lorem</li>
</ul>
</div>
</div>
<!DOCTYPE html><html lang='en' class=''>
<head><script src='//production-assets.codepen.io/assets/editor/live/console_runner-079c09a0e3b9ff743e39ee2d5637b9216b3545af0de366d4b9aad9dc87e26bfd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/events_runner-73716630c22bbc8cff4bd0f07b135f00a0bdc5d14629260c3ec49e5606f98fdd.js'></script><script src='//production-assets.codepen.io/assets/editor/live/css_live_reload_init-2c0dc5167d60a5af3ee189d570b1835129687ea2a61bee3513dee3a50c115a77.js'></script><meta charset='UTF-8'><meta name="robots" content="noindex"><link rel="shortcut icon" type="image/x-icon" href="//production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" /><link rel="mask-icon" type="" href="//production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" /><link rel="canonical" href="https://codepen.io/nelsonleite/pen/RaGwba?depth=everything&order=popularity&page=4&q=product&show_forks=false" />
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css'>
<style class="cp-pen-styles">.product-description {
transform: translate3d(0, 0, 0);
transform-style: preserve-3d;
perspective: 1000;
backface-visibility: hidden;
}
body {
color: #212121;
}
.container {
padding-top: 25px;
padding-bottom: 25px;
}
img {
max-width: 100%;
}
hr {
border-color: #e5e5e5;
margin: 15px 0;
}
.secondary-text {
color: #b6b6b6;
}
.list-inline {
margin: 0;
}
.list-inline li {
padding: 0;
}
.card-wrapper {
position: relative;
width: 100%;
height: 390px;
border: 1px solid #e5e5e5;
border-bottom-width: 2px;
overflow: hidden;
margin-bottom: 30px;
}
.card-wrapper:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
transition: opacity 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.card-wrapper:hover:after {
opacity: 1;
}
.card-wrapper:hover .image-holder:before {
opacity: .75;
}
.card-wrapper:hover .image-holder:after {
opacity: 1;
transform: translate(-50%, -50%);
}
.card-wrapper:hover .image-holder--original {
transform: translateY(-15px);
}
.card-wrapper:hover .product-description {
height: 205px;
}
#media (min-width: 768px) {
.card-wrapper:hover .product-description {
height: 185px;
}
}
.image-holder {
display: block;
position: relative;
width: 100%;
height: 310px;
background-color: #ffffff;
z-index: 1;
}
#media (min-width: 768px) {
.image-holder {
height: 325px;
}
}
.image-holder:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #4CAF50;
opacity: 0;
z-index: 5;
transition: opacity 0.6s;
}
.image-holder:after {
content: '+';
font-family: 'Raleway', sans-serif;
font-size: 70px;
color: #4CAF50;
text-align: center;
position: absolute;
top: 92.5px;
left: 50%;
width: 75px;
height: 75px;
line-height: 75px;
background-color: #ffffff;
opacity: 0;
border-radius: 50%;
z-index: 10;
transform: translate(-50%, 100%);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
transition: all 0.4s ease-out;
}
#media (min-width: 768px) {
.image-holder:after {
top: 107.5px;
}
}
.image-holder .image-holder__link {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 15;
}
.image-holder .image-holder--original {
transition: transform 0.8s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.image-liquid {
width: 100%;
height: 325px;
background-size: cover;
background-position: center center;
}
.product-description {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 80px;
padding: 10px 15px;
overflow: hidden;
background-color: #fafafa;
border-top: 1px solid #e5e5e5;
transition: height 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
z-index: 2;
}
#media (min-width: 768px) {
.product-description {
height: 65px;
}
}
.product-description p {
margin: 0 0 5px;
}
.product-description .product-description__title {
font-family: 'Raleway', sans-serif;
position: relative;
white-space: nowrap;
overflow: hidden;
margin: 0;
font-size: 18px;
line-height: 1.25;
}
.product-description .product-description__title:after {
content: '';
width: 60px;
height: 100%;
position: absolute;
top: 0;
right: 0;
background: linear-gradient(to right, rgba(255, 255, 255, 0), #fafafa);
}
.product-description .product-description__title a {
text-decoration: none;
color: inherit;
}
.product-description .product-description__category {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.product-description .product-description__price {
color: #4CAF50;
text-align: left;
font-weight: bold;
letter-spacing: 0.06em;
}
#media (min-width: 768px) {
.product-description .product-description__price {
text-align: right;
}
}
.product-description .sizes-wrapper {
margin-bottom: 15px;
}
.product-description .color-list {
font-size: 0;
}
.product-description .color-list__item {
width: 25px;
height: 10px;
position: relative;
z-index: 1;
transition: all .2s;
}
.product-description .color-list__item:hover {
width: 40px;
}
.product-description .color-list__item--red {
background-color: #F44336;
}
.product-description .color-list__item--blue {
background-color: #448AFF;
}
.product-description .color-list__item--green {
background-color: #CDDC39;
}
.product-description .color-list__item--orange {
background-color: #FF9800;
}
.product-description .color-list__item--purple {
background-color: #673AB7;
}
</style></head><body>
<!--
Inspired in this dribbble
https://dribbble.com/shots/986548-Product-Catalog
-->
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4">
<article class="card-wrapper">
<div class="image-holder">
<div class="image-liquid image-holder--original" style="background-image: url('https://upload.wikimedia.org/wikipedia/commons/2/24/Blue_Tshirt.jpg')">
</div>
</div>
<div class="product-description">
<!-- title -->
<h1 class="product-description__title">
<a href="#">
Adidas Originals
</a>
</h1>
<!-- category and price -->
<div class="row">
<div class="col-xs-12 col-sm-8 product-description__category secondary-text">
Men's running shirt
</div>
<div class="col-xs-12 col-sm-4 product-description__price">
€ 499
</div>
</div>
<!-- divider -->
<hr />
<!-- sizes -->
<div class="sizes-wrapper">
<b>Sizes</b>
<br />
<span class="secondary-text text-uppercase">
<ul class="list-inline">
<li>xs,</li>
<li>s,</li>
<li>sm,</li>
<li>m,</li>
<li>l,</li>
<li>xl,</li>
<li>xxl</li>
</ul>
</span>
</div>
<!-- colors -->
<div class="color-wrapper">
<b>Colors</b>
<br />
<ul class="list-inline color-list">
<li class="color-list__item color-list__item--red"></li>
<li class="color-list__item color-list__item--blue"></li>
<li class="color-list__item color-list__item--green"></li>
<li class="color-list__item color-list__item--orange"></li>
<li class="color-list__item color-list__item--purple"></li>
</ul>
</div>
</div>
</article>
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<article class="card-wrapper">
<div class="image-holder">
<div class="image-liquid image-holder--original" style="background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Jeans_BW_2_(3213391837).jpg/543px-Jeans_BW_2_(3213391837).jpg')">
</div>
</div>
<div class="product-description">
<!-- title -->
<h1 class="product-description__title">
<a href="#">
Adidas Originals
</a>
</h1>
<!-- category and price -->
<div class="row">
<div class="col-sm-8 product-description__category secondary-text">
Men's running shirt
</div>
<div class="col-sm-4 product-description__price text-right">
€ 499
</div>
</div>
<!-- divider -->
<hr />
<!-- sizes -->
<div class="sizes-wrapper">
<b>Sizes</b>
<br />
<span class="secondary-text text-uppercase">
<ul class="list-inline">
<li>xs,</li>
<li>s,</li>
<li>sm,</li>
<li>m,</li>
<li>l,</li>
<li>xl,</li>
<li>xxl</li>
</ul>
</span>
</div>
<!-- colors -->
<div class="color-wrapper">
<b>Colors</b>
<br />
<ul class="list-inline color-list">
<li class="color-list__item color-list__item--red"></li>
<li class="color-list__item color-list__item--blue"></li>
<li class="color-list__item color-list__item--green"></li>
<li class="color-list__item color-list__item--orange"></li>
<li class="color-list__item color-list__item--purple"></li>
</ul>
</div>
</div>
</article>
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<article class="card-wrapper">
<div class="image-holder">
<div class="image-liquid image-holder--original" style="background-image: url('https://upload.wikimedia.org/wikipedia/commons/b/b8/Columbia_Sportswear_Jacket.jpg')">
</div>
</div>
<div class="product-description">
<!-- title -->
<h1 class="product-description__title">
<a href="#">
Adidas Originals
</a>
</h1>
<!-- category and price -->
<div class="row">
<div class="col-sm-8 product-description__category secondary-text">
Men's running shirt
</div>
<div class="col-sm-4 product-description__price text-right">
€ 499
</div>
</div>
<!-- divider -->
<hr />
<!-- sizes -->
<div class="sizes-wrapper">
<b>Sizes</b>
<br />
<span class="secondary-text text-uppercase">
<ul class="list-inline">
<li>xs,</li>
<li>s,</li>
<li>sm,</li>
<li>m,</li>
<li>l,</li>
<li>xl,</li>
<li>xxl</li>
</ul>
</span>
</div>
<!-- colors -->
<div class="color-wrapper">
<b>Colors</b>
<br />
<ul class="list-inline color-list">
<li class="color-list__item color-list__item--red"></li>
<li class="color-list__item color-list__item--blue"></li>
<li class="color-list__item color-list__item--green"></li>
<li class="color-list__item color-list__item--orange"></li>
<li class="color-list__item color-list__item--purple"></li>
</ul>
</div>
</div>
</article>
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<article class="card-wrapper">
<div class="image-holder">
<div class="image-liquid image-holder--original" style="background-image: url('http://www.publicdomainpictures.net/pictures/20000/nahled/red-shoes-isolated.jpg')">
</div>
</div>
<div class="product-description">
<!-- title -->
<h1 class="product-description__title">
<a href="#">
Adidas Originals
</a>
</h1>
<!-- category and price -->
<div class="row">
<div class="col-sm-8 product-description__category secondary-text">
Men's running shirt
</div>
<div class="col-sm-4 product-description__price text-right">
€ 499
</div>
</div>
<!-- divider -->
<hr />
<!-- sizes -->
<div class="sizes-wrapper">
<b>Sizes</b>
<br />
<span class="secondary-text text-uppercase">
<ul class="list-inline">
<li>xs,</li>
<li>s,</li>
<li>sm,</li>
<li>m,</li>
<li>l,</li>
<li>xl,</li>
<li>xxl</li>
</ul>
</span>
</div>
<!-- colors -->
<div class="color-wrapper">
<b>Colors</b>
<br />
<ul class="list-inline color-list">
<li class="color-list__item color-list__item--red"></li>
<li class="color-list__item color-list__item--blue"></li>
<li class="color-list__item color-list__item--green"></li>
<li class="color-list__item color-list__item--orange"></li>
<li class="color-list__item color-list__item--purple"></li>
</ul>
</div>
</div>
</article>
</div>
</div>
</div>
</body></html>
The sample is made
<html>
<head>
<style>
.hide {
display: none;
}
.myDIV:hover + .hide {
display: block;
color: red;
}
</style>
</head>
<body>
<h2>Display an Element on Hover</h2>
<div class="myDIV">Hover over me.</div>
<div class="hide">I am shown when someone hovers over the div above.</div>
</body>
</html>
For accessibility reasons, you should use the correct semantic tags. Use a figure as a container and include the text to the image as figcaption.
Apply position: absolute to the container and then position: absolute to the figcaption.
Simply hide the figcaption with display: block and make it visible again by using :hover on the wrapping figure element.
figure {
position: relative;
}
figcaption {
position: absolute;
inset: 2px;
display: none;
}
figure:hover figcaption {
display: flex;
}
/* for visualization only */
figure {
display: inline-block;
}
figcaption {
padding: 1em;
justify-content: center;
align-items: center;
background-color: rgba(255, 255, 255, 0.7);
}
img {
border: 2px dashed red;
}
<figure>
<img src="https://via.placeholder.com/200.jpg" alt="placeholder image used for demonstration">
<figcaption>placeholder image used for demonstration</figcaption>
</figure>