I can't change SCSS to CSS - css
I have a problem with this slideshow:
https://codepen.io/bcarvalho/pen/gWPvJB
The HTML is:
<main class="main-content">
<section class="slideshow">
<div class="slideshow-inner">
<div class="slides">
<div class="slide is-active ">
<div class="slide-content">
<div class="caption">
<div class="title">Slide title 1</div>
<div class="text">
<p>Slide description 1</p>
</div>
<a href="#" class="btn">
<span class="btn-inner">Learn More</span>
</a>
</div>
</div>
<div class="image-container">
<img src="https://www.alixbdanthenay.fr/wp-content/uploads/2015/07/Indispensable-1.jpg" alt="" class="image" />
</div>
</div>
<div class="slide">
<div class="slide-content">
<div class="caption">
<div class="title">Slide title 2</div>
<div class="text">
<p>Slide description 2</p>
</div>
<a href="#" class="btn">
<span class="btn-inner">Learn More</span>
</a>
</div>
</div>
<div class="image-container">
<img src="https://www.alixbdanthenay.fr/wp-content/uploads/2015/07/Indispensable-4-1.jpg" alt="" class="image" />
</div>
</div>
<div class="slide">
<div class="slide-content">
<div class="caption">
<div class="title">Slide title 3</div>
<div class="text">
<p>Slide description 3</p>
</div>
<a href="#" class="btn">
<span class="btn-inner">Learn More</span>
</a>
</div>
</div>
<div class="image-container">
<img src="https://www.alixbdanthenay.fr/wp-content/uploads/2016/11/11.jpg" alt="" class="image" />
</div>
</div>
<div class="slide">
<div class="slide-content">
<div class="caption">
<div class="title">Slide title 4</div>
<div class="text">
<p>Slide description 4</p>
</div>
<a href="#" class="btn">
<span class="btn-inner">Learn More</span>
</a>
</div>
</div>
<div class="image-container">
<img src="https://www.alixbdanthenay.fr/wp-content/uploads/2016/11/20mars17-sans-typo.jpg" alt="" class="image" />
</div>
</div>
</div>
<div class="pagination">
<div class="item is-active">
<span class="icon">1</span>
</div>
<div class="item">
<span class="icon">2</span>
</div>
<div class="item">
<span class="icon">3</span>
</div>
<div class="item">
<span class="icon">4</span>
</div>
</div>
<div class="arrows">
<div class="arrow prev">
<span class="svg svg-arrow-left">
<svg version="1.1" id="svg4-Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="14px" height="26px" viewBox="0 0 14 26" enable-background="new 0 0 14 26" xml:space="preserve"> <path d="M13,26c-0.256,0-0.512-0.098-0.707-0.293l-12-12c-0.391-0.391-0.391-1.023,0-1.414l12-12c0.391-0.391,1.023-0.391,1.414,0s0.391,1.023,0,1.414L2.414,13l11.293,11.293c0.391,0.391,0.391,1.023,0,1.414C13.512,25.902,13.256,26,13,26z"/> </svg>
<span class="alt sr-only"></span>
</span>
</div>
<div class="arrow next">
<span class="svg svg-arrow-right">
<svg version="1.1" id="svg5-Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="14px" height="26px" viewBox="0 0 14 26" enable-background="new 0 0 14 26" xml:space="preserve"> <path d="M1,0c0.256,0,0.512,0.098,0.707,0.293l12,12c0.391,0.391,0.391,1.023,0,1.414l-12,12c-0.391,0.391-1.023,0.391-1.414,0s-0.391-1.023,0-1.414L11.586,13L0.293,1.707c-0.391-0.391-0.391-1.023,0-1.414C0.488,0.098,0.744,0,1,0z"/> </svg>
<span class="alt sr-only"></span>
</span>
</div>
</div>
</div>
</section>
</main>
The SCSS code is :
body {
font: 14px/2 "Open sans",sans-serif;
letter-spacing: 0.05em;
}
.btn {
display: inline-block;
padding: 13px 20px;
color: #fff;
text-decoration: none;
position: relative;
background: transparent;
border: 1px solid #e1e1e1;
font: 12px/1.2 "Oswald", sans-serif;
letter-spacing: 0.4em;
text-align: center;
text-indent: 2px;
text-transform: uppercase;
transition: color 0.1s linear 0.05s;
&::before {
content: "";
display: block;
position: absolute;
top: 50%;
left: 0;
width: 100%;
height: 1px;
background: #e1e1e1;
z-index: 1;
opacity: 0;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0.2s;
}
&::after {
transition:border 0.1s linear 0.05s;
}
.btn-inner {
position: relative;
z-index: 2;
}
&:hover {
color: #373737;
transition: color 0.1s linear 0s;
&::before {
top: 0;
height: 100%;
opacity: 1;
transition: height 0.2s ease, top 0.2s ease, opacity 0s linear 0s;
}
&::after {
border-color: #373737;
transition:border 0.1s linear 0s;
}
}
}
.slideshow {
overflow: hidden;
position: relative;
width: 100%;
height: 100vh;
z-index: 1;
.slideshow-inner {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.slides {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
.slide {
display: none;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
transition: opacity 0.3s ease;
&.is-active {
display: block;
}
&.is-loaded{
opacity: 1;
}
.caption {
padding: 0 100px;
}
.image-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-position: center;
z-index: 1;
background-size: cover;
image-rendering: optimizeQuality;
&::before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
}
}
.image {
width: 100%;
width: 100%;
object-fit: cover;
height: 100%;
}
&-content {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 2;
color: #fff;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.title {
margin: 0 auto 15px;
max-width: 1000px;
font: 300 50px/1.2 "Oswald", sans-serif;
letter-spacing: 0.35em;
text-transform: uppercase;
}
.text {
margin: 0 auto;
max-width: 1000px;
font-size: 18px;
line-height: 1.4;
}
.btn {
margin: 15px 0 0;
border-color: #fff;
&::before {
background:#fff
}
}
}
.pagination {
position: absolute;
bottom: 35px;
left: 0;
width: 100%;
height: 12px;
cursor: default;
z-index: 2;
text-align: center;
.item {
display: inline-block;
padding: 15px 5px;
position: relative;
width: 46px;
height: 32px;
cursor: pointer;
text-indent: -999em;
z-index: 1;
+ .page {
margin-left: -2px;
}
&::before {
content: "";
display: block;
position: absolute;
top: 15px;
left: 5px;
width: 36px;
height: 2px;
background: rgba(255, 255, 255, 0.5);
transition: background 0.2s ease;
}
&::after {
width: 0;
background: #fff;
z-index: 2;
transition: width 0.2s ease;
}
&:hover::before,
&.is-active::before {
background-color: #fff;
}
}
}
.arrows {
.arrow {
margin: -33px 0 0;padding: 20px;position: absolute;top: 50%;cursor: pointer;z-index: 3;
}
.prev {
left: 30px;
&:hover .svg {
left: -10px;
}
}
.next {
right: 30px;
&:hover .svg {
left: 10px;
}
}
.svg {
position: relative;
left: 0;
width: 14px;
height: 26px;
fill: #fff;
transition: left 0.2s ease;
}
}
}
The JavaScript code is:
var slideshowDuration = 500;
var slideshow=$('.main-content .slideshow');
function slideshowSwitch(slideshow,index,auto){
if(slideshow.data('wait')) return;
var slides = slideshow.find('.slide');
var pages = slideshow.find('.pagination');
var activeSlide = slides.filter('.is-active');
var activeSlideImage = activeSlide.find('.image-container');
var newSlide = slides.eq(index);
var newSlideImage = newSlide.find('.image-container');
var newSlideContent = newSlide.find('.slide-content');
var newSlideElements=newSlide.find('.caption > *');
if(newSlide.is(activeSlide))return;
newSlide.addClass('is-new');
var timeout=slideshow.data('timeout');
clearTimeout(timeout);
slideshow.data('wait',true);
var transition=slideshow.attr('data-transition');
if(transition=='fade'){
newSlide.css({
display:'block',
zIndex:2
});
newSlideImage.css({
opacity:0
});
TweenMax.to(newSlideImage,1,{
alpha:1,
onComplete:function(){
newSlide.addClass('is-active').removeClass('is-new');
activeSlide.removeClass('is-active');
newSlide.css({display:'',zIndex:''});
newSlideImage.css({opacity:''});
slideshow.find('.pagination').trigger('check');
slideshow.data('wait',false);
if(auto){
timeout=setTimeout(function(){
slideshowNext(slideshow,false,true);
},slideshowDuration);
slideshow.data('timeout',timeout);}}});
} else {
if(newSlide.index()>activeSlide.index()){
var newSlideRight=0;
var newSlideLeft='auto';
var newSlideImageRight=-slideshow.width()/8;
var newSlideImageLeft='auto';
var newSlideImageToRight=0;
var newSlideImageToLeft='auto';
var newSlideContentLeft='auto';
var newSlideContentRight=0;
var activeSlideImageLeft=-slideshow.width()/4;
} else {
var newSlideRight='';
var newSlideLeft=0;
var newSlideImageRight='auto';
var newSlideImageLeft=-slideshow.width()/8;
var newSlideImageToRight='';
var newSlideImageToLeft=0;
var newSlideContentLeft=0;
var newSlideContentRight='auto';
var activeSlideImageLeft=slideshow.width()/4;
}
newSlide.css({
display:'block',
width:0,
right:newSlideRight,
left:newSlideLeft
,zIndex:2
});
newSlideImage.css({
width:slideshow.width(),
right:newSlideImageRight,
left:newSlideImageLeft
});
newSlideContent.css({
width:slideshow.width(),
left:newSlideContentLeft,
right:newSlideContentRight
});
activeSlideImage.css({
left:0
});
TweenMax.set(newSlideElements,{y:20,force3D:true});
TweenMax.to(activeSlideImage,1,{
left:activeSlideImageLeft,
ease:Power3.easeInOut
});
TweenMax.to(newSlide,1,{
width:slideshow.width(),
ease:Power3.easeInOut
});
TweenMax.to(newSlideImage,1,{
right:newSlideImageToRight,
left:newSlideImageToLeft,
ease:Power3.easeInOut
});
TweenMax.staggerFromTo(newSlideElements,0.8,{alpha:0,y:60},{alpha:1,y:0,ease:Power3.easeOut,force3D:true,delay:0.6},0.1,function(){
newSlide.addClass('is-active').removeClass('is-new');
activeSlide.removeClass('is-active');
newSlide.css({
display:'',
width:'',
left:'',
zIndex:''
});
newSlideImage.css({
width:'',
right:'',
left:''
});
newSlideContent.css({
width:'',
left:''
});
newSlideElements.css({
opacity:'',
transform:''
});
activeSlideImage.css({
left:''
});
slideshow.find('.pagination').trigger('check');
slideshow.data('wait',false);
if(auto){
timeout=setTimeout(function(){
slideshowNext(slideshow,false,true);
},slideshowDuration);
slideshow.data('timeout',timeout);
}
});
}
}
function slideshowNext(slideshow,previous,auto){
var slides=slideshow.find('.slide');
var activeSlide=slides.filter('.is-active');
var newSlide=null;
if(previous){
newSlide=activeSlide.prev('.slide');
if(newSlide.length === 0) {
newSlide=slides.last();
}
} else {
newSlide=activeSlide.next('.slide');
if(newSlide.length==0)
newSlide=slides.filter('.slide').first();
}
slideshowSwitch(slideshow,newSlide.index(),auto);
}
function homeSlideshowParallax(){
var scrollTop=$(window).scrollTop();
if(scrollTop>windowHeight) return;
var inner=slideshow.find('.slideshow-inner');
var newHeight=windowHeight-(scrollTop/2);
var newTop=scrollTop*0.8;
inner.css({
transform:'translateY('+newTop+'px)',height:newHeight
});
}
$(document).ready(function() {
$('.slide').addClass('is-loaded');
$('.slideshow .arrows .arrow').on('click',function(){
slideshowNext($(this).closest('.slideshow'),$(this).hasClass('prev'));
});
$('.slideshow .pagination .item').on('click',function(){
slideshowSwitch($(this).closest('.slideshow'),$(this).index());
});
$('.slideshow .pagination').on('check',function(){
var slideshow=$(this).closest('.slideshow');
var pages=$(this).find('.item');
var index=slideshow.find('.slides .is-active').index();
pages.removeClass('is-active');
pages.eq(index).addClass('is-active');
});
/* Lazyloading
$('.slideshow').each(function(){
var slideshow=$(this);
var images=slideshow.find('.image').not('.is-loaded');
images.on('loaded',function(){
var image=$(this);
var slide=image.closest('.slide');
slide.addClass('is-loaded');
});
*/
var timeout=setTimeout(function(){
slideshowNext(slideshow,false,true);
},slideshowDuration);
slideshow.data('timeout',timeout);
});
if($('.main-content .slideshow').length > 1) {
$(window).on('scroll',homeSlideshowParallax);
}
I want to copy the files from the web pages to my website.
I changed the SCSS to CSS but it doesn't work. What's the problem?
The code I used to change the SCSS is:
sass filename.scss newfilename.css
But it looks bad after I change it.
In the CodePen link you posted, try and click the arrow in the top right corner of the CSS panel, and select "View compiled CSS". This will also give you the CSS you need.
There already a function to change SCSS on Codepen but if there any chance Codepen Does not work, try other website like JSFiddle,CSS Deck,JS Bin,Dabblet,Plunker,Liveweave.
Credit to https://www.sitepoint.com/7-code-playgrounds/
i find the problem , in :
https://codepen.io
can't the files all be in three windows so i need to download the slideshow from
the button in right down in right "Export.zip" and download the file and use it !
thanks for all you for staying with me ♥
Related
two class CSS not picking up both classes
Hi I'm following a tutorial. As far as I can see I have written exactly the same thing in my code but it is behaving differently. .container { display: flex; width: 90vw; } .panel { background-size: auto 100%; background-position: center; background-repeat: no-repeat; height: 80vh; border-radius: 50px; color: white; cursor: pointer; flex: 0.5; margin: 10px; position: relative; transition: flex 0.7s ease-in; } .panel h3 { font-size: 24px; position: absolute; bottom: 20px; left: 20px; margin: 0; opacity: 0; } .panel.active { flex: 5; } .panel.active h3 { opacity: 1; } <body> <div class="container"> <div class="panel active" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')"> <h3>Beautiful Sky</h3> </div> <div class="panel" style="background-image: url('./juskteez-vu-TIrXot28Znc-unsplash.jpg')"> <h3>Incredible sky</h3> </div> <div class="panel" style="background-image: url('./casey-horner-fsJB3KT2rj8-unsplash.jpg')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('./vincent-guth-uhoILl3HUZM-unsplash.jpg')"> <h3>Beautiful Sky</h3> </div> </div> </div> </body> but on the screen the panel that's active loses all the css from the panel class instead of using both. Any ideas why this might be? Thanks!
Actually it works but the problem is you are using 100% size of your images so its looks like this: I added border to demonstrate .container { display: flex; width: 90vw; } .panel { background-size: auto 100%; background-position: center; background-repeat: no-repeat; height: 80vh; border-radius: 50px; color: white; cursor: pointer; flex: 0.5; margin: 10px; position: relative; transition: flex 0.7s ease-in; border: red 2px solid; } .panel h3 { font-size: 24px; position: absolute; bottom: 20px; left: 20px; margin: 0; opacity: 0; } .panel.active { flex: 5; } .panel.active h3 { opacity: 1; } <body> <div class="container"> <div class="panel active" style="background-image: url('https://picsum.photos/id/266/200/300')"> <h3>Beautiful Sky</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/230/200/300')"> <h3>Incredible sky</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/217/200/300')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/227/200/300')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/137/200/300')"> <h3>Beautiful Sky</h3> </div> </div> </body> The solution is using background-size: cover; instead .container { display: flex; width: 90vw; } .panel { background-size: cover; background-position: center; background-repeat: no-repeat; height: 80vh; border-radius: 50px; color: white; cursor: pointer; flex: 0.5; margin: 10px; position: relative; transition: flex 0.7s ease-in; border: red 2px solid; } .panel h3 { font-size: 24px; position: absolute; bottom: 20px; left: 20px; margin: 0; opacity: 0; } .panel.active { flex: 5; } .panel.active h3 { opacity: 1; } <body> <div class="container"> <div class="panel active" style="background-image: url('https://picsum.photos/id/266/200/300')"> <h3>Beautiful Sky</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/230/200/300')"> <h3>Incredible sky</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/217/200/300')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/227/200/300')"> <h3>Northern Lights</h3> </div> <div class="panel" style="background-image: url('https://picsum.photos/id/137/200/300')"> <h3>Beautiful Sky</h3> </div> </div> </body>
Try to change value of background-size property to cover (background-size: cover). I think this is what you need
I ran your code in codepen. I only changed the background-images to colors since the were loaded locally. It is behaving as it should, the panel active div displaying everything defined in the panel class aswell. What are you missing? https://codepen.io/wischn/pen/OJwOQxp .container { display: flex; width: 90vw; } .panel { background-size: auto 100%; background-position: center; background-repeat: no-repeat; height: 80vh; border-radius: 50px; color: white; cursor: pointer; flex: 0.5; margin: 10px; position: relative; transition: flex 0.7s ease-in; } .panel h3 { font-size: 24px; position: absolute; bottom: 20px; left: 20px; margin: 0; opacity: 0; } .panel.active { flex: 5; } .panel.active h3 { opacity: 1; }
Stepper progress bar - responsive css
I would like to do a responsive stepper where in the lines in between steppers are connected to each step. Currently only workable with 4 steps, it becomes not responsive once it is more or less than 4 steps. Here is the jsfiddle, currently workable with 4 steps. .bullet.completed::after { content: ''; position: absolute; bottom: 10px; height: 1px; width: calc(133% - 21px); background-color: #000; margin-left: 7px; } I tried to change this part but it doesn't seem to work. Thanks for advance! #stepProgressBar { display: flex; justify-content: space-between; align-items: flex-end; width: 90%; margin: 0 auto; margin-bottom: 40px; } .step { text-align: center; width: 20%; position: relative; } .step-text { margin-bottom: 10px; color: #000; } .bullet { border: 1px solid #000; height: 20px; width: 20px; color: #000; display: inline-block; transition: background-color 500ms; line-height: 20px; } .bullet.completed { color: white; background-color: #000; } .bullet.completed::after { content: ''; position: absolute; bottom: 10px; height: 1px; width: calc(133% - 21px); background-color: #000; margin-left: 7px; } /* Base styles and helper stuff */ .hidden { display: none; } button { padding: 5px 10px; border: 1px solid black; transition: 250ms background-color; } button:hover { cursor: pointer; background-color: black; color: white; } button:disabled:hover { opacity: 0.6; cursor: not-allowed; } .text-center { text-align: center; } .container { max-width: 100%; margin: 0 auto; margin-top: 20px; padding: 40px; } <div class="container"> <div id="stepProgressBar"> <div class="step"> <p class="step-text">Super Duper Long Title</p> <div class="bullet completed">1</div> </div> <div class="step"> <p class="step-text">Long Long Title</p> <div class="bullet completed">2</div> </div> <div class="step"> <p class="step-text">Loooong Title</p> <div class="bullet completed">3</div> </div> <div class="step"> <p class="step-text">Loooong Title</p> <div class="bullet">4</div> </div> </div> </div>
Modify your .bullet.completed::after to display:flex, and set its width to 100% minus a modified margin-left value, which is equal to the width of the .bullet (20px): .bullet.completed::after { content: ''; position: absolute; bottom: 10px; height: 1px; display:flex; /* Added */ width:calc(100% - 20px); /* Modified */ background-color: #000; margin-left: 20px; /* Modified */ } Here it is with seven steps: const previousBtn = document.getElementById('previousBtn'); const nextBtn = document.getElementById('nextBtn'); const finishBtn = document.getElementById('finishBtn'); const content = document.getElementById('content'); const bullets = [...document.querySelectorAll('.bullet')]; const MAX_STEPS = 7; let currentStep = 1; nextBtn.addEventListener('click', () => { bullets[currentStep - 1].classList.add('completed'); currentStep += 1; previousBtn.disabled = false; if (currentStep === MAX_STEPS) { nextBtn.disabled = true; finishBtn.disabled = false; } content.innerText = `Step Number ${currentStep}`; }); previousBtn.addEventListener('click', () => { bullets[currentStep - 2].classList.remove('completed'); currentStep -= 1; nextBtn.disabled = false; finishBtn.disabled = true; if (currentStep === 1) { previousBtn.disabled = true; } content.innerText = `Step Number ${currentStep}`; }); finishBtn.addEventListener('click', () => { location.reload(); }); #stepProgressBar { display: flex; justify-content: space-between; align-items: flex-end; width: 90%; margin: 0 auto; margin-bottom: 40px; } .step { text-align: center; width: 20%; position: relative; } .step-text { margin-bottom: 10px; color: #000; } .bullet { border: 1px solid #000; height: 20px; width: 20px; color: #000; display: inline-block; transition: background-color 500ms; line-height: 20px; } .bullet.completed { color: white; background-color: #000; } .bullet.completed::after { content: ''; position: absolute; bottom: 10px; height: 1px; width:calc(100% - 20px); display:flex; background-color: #000; margin-left: 20px; } /* Base styles and helper stuff */ .hidden { display: none; } button { padding: 5px 10px; border: 1px solid black; transition: 250ms background-color; } button:hover { cursor: pointer; background-color: black; color: white; } button:disabled:hover { opacity: 0.6; cursor: not-allowed; } .text-center { text-align: center; } .container { max-width: 100%; margin: 0 auto; margin-top: 20px; padding: 40px; } <div class="container"> <div id="stepProgressBar"> <div class="step"> <p class="step-text">Super Duper Long Title</p> <div class="bullet">1</div> </div> <div class="step"> <p class="step-text">Long Long Title</p> <div class="bullet">2</div> </div> <div class="step"> <p class="step-text">Loooong Title</p> <div class="bullet">3</div> </div> <div class="step"> <p class="step-text">Title</p> <div class="bullet ">4</div> </div> <div class="step"> <p class="step-text">Title</p> <div class="bullet ">5</div> </div> <div class="step"> <p class="step-text">Title</p> <div class="bullet ">6</div> </div> <div class="step"> <p class="step-text">Title</p> <div class="bullet ">7</div> </div> </div> <div id="main"> <p id="content" class="text-center">Step Number 1</p> <button id="previousBtn" class="hidden"></button> <button id="nextBtn">Next</button> <button id="finishBtn" class="hidden">Finish</button> </div> </div>
How to add play button overlay on website
I've been having trouble with various play button options. This time i copied from codepen.io/martinkrulltott/pen/xwrXwR My version http://www.leatherspin.com/TEST.html
Check this solution added overlay play button .video-thumbnail { position: relative; display: inline-block; cursor: pointer; margin: 30px; } .top-img { position: relative; display: inline-block; cursor: pointer; margin: 30px; } .btm-img { position: relative; display: inline-block; cursor: pointer; margin: 30px; } .overlay { position: absolute; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .5s ease; background-color: rgba(0,0,0,0.7); text-align:center; } .top-img:hover .overlay ,.btm-img:hover .overlay { opacity: 1; } .overlay i { color:#fff; top: 42%; transform: translate(-50%,0); position: absolute; font-size:50px; } <link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" /> <div class="video-thumbnail top-img"> <img src="http://www.leatherspin.com/Girl-in-leather-gloves-with-gun-leather-jacket-overknee-leather-boots-8.jpg" alt="Video thumbnail"> <div class="overlay"> <i class="fa fa-play"></i> </div> </div> <div class="video-thumbnail btm-img"> <img src="http://www.leatherspin.com/girl-with-gun-leather-gloves-leather-pants-boots-170.jpg" alt="Video thumbnail"> <div class="overlay"> <i class="fa fa-play"></i> </div> </div>
Text on hover slide in left transition
I have an image gallery with some hover affects that I want to refine. When the user hovers on an image, the other pictures in the gallery get dimmed out. But I also want some text to slide in from the left on hover as well. Something like this website has http://gugroppo.com/projects. I have the text appear on hover but I can't get it to transition in from the left smoothly; or have my overlay effect appear smoothly as well. Everything just appears. Here's my codepen. window.sr = ScrollReveal({reset: true}); sr.reveal('img', {mobile:true}); body { margin: 0; padding: 0; } h2 { padding-bottom: 7.5%; color: #7bbe9a; text-align: center; font-size: 1.875em; font-family: 'Lato', sans-serif; } .gallery{ width: 100%; display: inline-block; flex-wrap: wrap; justify-content: center; padding-top: 7.5%; padding-bottom: 15%; background-color: #333; } .img-container { -webkit-transition: opacity 0.3s; -moz-transition: opacity 0.3s; -ms-transition: opacity 0.3s; -o-transition: opacity 0.3s; transition: opacity 0.3s; width: 33.33%; float: left; display: block; position: relative; } .img-container img{ display: block; width: 100%; height: auto; } #slide { position: absolute; left: -100px; transition: 1s; width: 100%; height: 100%; } .overlay { position: absolute; width: 100%; height: 100%; left: 0; top: 0; right: 0; bottom: 0; opacity: 0; /* background: rgba(123, 190, 154, 0.72); */ background: rgba(51,51,51, 0.2); } .text { color: white; position: absolute; top: 50%; left: 50%; font-size: 24px; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); text-align: center; font-family: 'Lato', sans-serif; } #parent:hover > .img-container:not(:hover) { opacity: 0.3; } .img-container:hover .overlay { opacity: 1; } #media(max-width:768px){ .img-container { width: 100% !important; } } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://unpkg.com/scrollreveal/dist/scrollreveal.min.js"></script> <body> <a class="anchor" name="portfolio"> <div class="gallery"> <h2>Portfolio</h2> </a> <div id="parent"> <div class="img-container"> <a href=""> <img src="https://img1.cgtrader.com/items/4716/33d9798412/large/wicker-laundry-basket-3d-model-obj-3ds-c4d.jpg" alt=""></a> <div class="overlay"> <div class="text">Basket</div> </div> </div> <div class="img-container"> <a href=""> <img src="https://cdn.shopify.com/s/files/1/0225/1115/products/buildings-rts-orc-smithy-low-poly-3d-model-2_400x.jpeg?v=1456744435" alt=""></a> <div class="overlay"> <div class="text">Train</div> </div> </div> <div class="img-container"> <a href=""> <img src="http://www.pycomall.com/images/P1/Bed_Room_Interior_3D_Model_in_Max_format_7.jpg" alt=""></a> <div class="overlay"> <div class="text">Bed</div> </div> </div> <div class="img-container"> <a href=""> <img src="http://mycreativedaddy.com/wp-content/uploads/chair-capitone-3d-model.jpg" alt=""></a> <div class="overlay"> <div class="text">Chair</div> </div> </div> <div class="img-container"> <a href=""> <img src="http://www.pycomall.com/images/P1/Restaurant_Interior_3D_Model_in_Max_format_4.jpg" alt=""></a> <div class="overlay"> <div class="text">Room</div> </div> </div> <div class="img-container"> <a href=""> <img src="https://3dexport.com/items/2008/07/29/11820/9454/wedding_ring._3d_model_c4d_max_obj_fbx_ma_lwo_3ds_3dm_stl_66996.jpg" alt=""></a> <div class="overlay"> <div class="text">Ring</div> </div> </div> <div class="img-container"> <a href=""> <img src="http://www.madsonline.net/wp-content/uploads/2017/07/living-room-interior-3d-model-in-max-format-3-3d-models-in-3d-living-room-model.jpg" alt=""></a> <div class="overlay"> <div class="text">Couch</div> </div> </div> <div class="img-container"> <a href=""> <img src="https://d1a9v60rjx2a4v.cloudfront.net/2013/10/03/00_54_27_730_00_1.jpg" alt=""></a> <div class="overlay"> <div class="text">Glass</div> </div> </div> <div class="img-container"> <a href=""> <img src="https://img1.cgtrader.com/items/5185/bb5b9f2fde/large/bailarina-3d-model-obj-3ds-fbx-ma-mb.jpg" alt=""></a> </div> </div> </body>
What you want to do is add overflow: hidden to your container .img-container{overflow: hidden;} Then initially start the text off the element. I did this by setting .text{left: -50%;} Finally you need to call the text back into the element on hover by using container:hover and setting the text back to 50%; .img-container:hover .text{left: 50%;} Lastly you will just need to add in some transition properties and attributes of your likely. Hope this helps. The follow CSS should accomplish what you are looking for body { margin: 0; padding: 0; } h2 { padding-bottom: 7.5%; color: #7bbe9a; text-align: center; font-size: 1.875em; font-family: 'Lato', sans-serif; } .gallery{ width: 100%; display: inline-block; flex-wrap: wrap; justify-content: center; padding-top: 7.5%; padding-bottom: 15%; background-color: #333; } .img-container { -webkit-transition: opacity 0.3s; -moz-transition: opacity 0.3s; -ms-transition: opacity 0.3s; -o-transition: opacity 0.3s; transition: opacity 0.3s; width: 33.33%; float: left; display: block; position: relative; overflow: hidden; } .img-container img{ display: block; width: 100%; height: auto; } #slide { position: absolute; left: -100px; transition: 1s; width: 100%; height: 100%; } .overlay { position: absolute; width: 100%; height: 100%; left: 0; top: 0; right: 0; bottom: 0; opacity: 0; /* background: rgba(123, 190, 154, 0.72); */ background: rgba(51,51,51, 0.2); } .text { color: white; position: absolute; top: 50%; left: -50%; font-size: 24px; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); text-align: center; font-family: 'Lato', sans-serif; } .img-container:hover .text { left: 50%; } #parent:hover > .img-container:not(:hover) { opacity: 0.3; } .img-container:hover .overlay { opacity: 1; } #media(max-width:768px){ .img-container { width: 100% !important; } }
How to use absolute positioning without overlap effect
So, I'm using a while loop with PHP. The while loop makes the following code: <img src='$user_six' class='avatar_friend'> Please don't worry about $user_six or the background info on the while loop. I know it works. I'm trying to put three avatars on top of a movie. The problem is that each image takes space and is ruining the spacing with the movies. This is the information of .avatar_friend: .avatar_friend { width: 36px; height: 36px; position: relative; z-index: 10; border: 1px solid white; } I think absolute positioning works better, but the images overlap each other. This is the information of .avatar_friend: .avatar_friend { width: 36px; height: 36px; position: absolute; z-index: 10; border: 1px solid white; } How can I have the best of both positions? I want proper spacing, but no overlapping. How can I achieve this effect? EDIT: I've tried doing the following: html <div id='container'> <img src='$user_six' class='avatar_friend'> </div> css #container { position: absolute; } .avatar_friend { width: 36px; height: 36px; position: relative; z-index: 10; border: 1px solid white; } This did not work... EDIT 2: html <!DOCTYPE html> <html> <head> <title> Movies </title> <link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css"> <link rel='stylesheet' href='main.css'> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src='main.js'></script> </head> <body> <!-- Navigation --> <div id='nav'> <!-- Profile Wrapper --> <ul class="profile-wrapper"> <li> <!-- user profile --> <div class="profile"> <img src="avatars/default.png" /> MatthewMalan <i class="fa fa-caret-down" id="caret-down"></i> <!-- more menu --> <ul class="menu"> <li>Sign Out</li> <li>Sign Out</li> <li>Sign Out</li> </ul> </div> </li> </ul> <!-- End of Profile Wrapper --> </div> <!-- End of Navigation --> <!-- Movie Content --> <div id='movie_content2'> <div id='movie_line'> <div id='movie_line2'></div> <!-- Dropdown Selection --> <nav> <ul id="dropdown_selection"> <li>Most Recent <ul> <li> Most Liked </li> <li> My History </li> <li> My Likes </li> </ul> </li> </ul> </nav> <!-- End of Dropdown Selection --> <div id='descriptive_div' number='1'> <i class='fa fa-caret-left' id='descriptive_caret' number='1'></i> <a href='like.php?number=7&page=1'><a href='like.php?number=7&page=1&code=1&sorting=recent'> <div class='like_button' number='1'> Like </div> </a></a> <span id='descriptive_div_text'> Professional, Clean, Ready to Go </span> <div id='files_left'> 3 Copies Left </div> </div><a href='open.php?destination=movies/56c7ede7d3ed3658.44679765.mp4'> <div class='movie_length' number='1'> <div id='movie_length_text' number='1'> 1h 20m </div> </div> </a><a href='open.php?destination=movies/56c7ede7d3ed3658.44679765.mp4'> <div class='movie_rating3' number='1'> <span id='movie_rating_text' number='1'> G </span> </div> </a><a href='open.php?destination=movies/56c7ede7d3ed3658.44679765.mp4'> <img src='covers/inside.jpg' class='movie_size' number='1'> </a><div id='descriptive_div' number='2'> <i class='fa fa-caret-left' id='descriptive_caret' number='2'></i> <a href='like.php?number=8&page=1'><a href='like.php?number=8&page=1&code=1&sorting=recent'> <div class='like_button' number='2'> Like </div> </a></a> <span id='descriptive_div_text'> s </span> <div id='files_left'> 1 Copy Left </div> </div><a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_length' number='2'> <div id='movie_length_text' number='2'> 2h 16m </div> </div> </a><a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_rating' number='2'> <span id='movie_rating_text' number='2'> PG-13 </span> </div> </a><a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <img src='covers/star wars.jpg' class='movie_size' number='2'> </a><img src='avatars/sam.jpg' class='avatar_friend'><img src='avatars/traek.jpg' class='avatar_friend'><img src='avatars/jessie.jpg' class='avatar_friend'><div id='descriptive_div' number='3'> <i class='fa fa-caret-left' id='descriptive_caret' number='3'></i> <a href='like.php?number=9&page=1'><a href='like.php?number=9&page=1&sorting=recent'> <div class='liked_button' number='3'> Like </div> </a></a> <span id='descriptive_div_text'> r </span> <div id='files_left'> 7 Copies Left </div> </div><a href='open.php?destination=movies/56e06853166618.33290858.mp4'> <div class='movie_length' number='3'> <div id='movie_length_text' number='3'> r </div> </div> </a><a href='open.php?destination=movies/56e06853166618.33290858.mp4'> <div class='movie_rating4' number='3'> <span id='movie_rating_text' number='3'> PG-13 </span> </div> </a><a href='open.php?destination=movies/56e06853166618.33290858.mp4'> <img src='covers/56e068530dc9f9.52895782.jpg' class='movie_size3' number='3'> </a><br><div class="complete_page">1</div> </div> </div> <!-- End of Movie Content --> </body> </html> css /* Rating of Movie Content */ .movie_rating, .movie_rating2, .movie_rating3, .movie_rating4, .movie_rating5, .movie_rating6, .movie_length, .movie_length2 { display: inline-block; width: 100px; height: 30px; background: #E10E0D; color: white; text-align: center; position: absolute; z-index: 5; font-family: 'Days One', sans-serif; cursor: pointer; margin-top: -10px; margin-left: 16px; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; border: 1px solid #FE4042; } .movie_rating4, .movie_rating5, .movie_rating6 { background: #7D5505; border: 1px solid #F9BA01; } .movie_length, .movie_length2 { width: 120px; background: #02477D; border: 1px solid #97D0F2; margin-top: 239px; } .movie_length2 { width: 75px; } .movie_rating2, .movie_rating5 { width: 60px; } .movie_rating3, .movie_rating6 { width: 40px; } #movie_rating_text, #movie_length_text { font-size: 25px; position: relative; top: 0px; font-family: 'Days One', sans-serif; letter-spacing: 1px; } /* Description of Movie */ #descriptive_div { position: absolute; width: 400px; min-height: 241px; background: black; color: white; z-index: 6; margin-left: 228px; margin-top: -10px; font-size: 16px; line-height: 25px; padding-bottom: 30px; border: 5px solid #ccc; display: none; } #descriptive_div_text { width: 370px; display: inline-block; position: relative; left: 14px; top: 14px; text-align: left; } #descriptive_caret { color: #ccc; font-size: 51px; position: absolute; margin-left: -19px; margin-top: 115px; display: none; } /* End of Description of Movie */ /* Movie Line */ #movie_line2 { width: 1px; height: 635px; background: #ccc; position: absolute; left: 1120px; top: 10px; z-index: 2; } /* End of Movie Line */ /* End of Rating of Movie Content */ /* Like Button */ .like_button, .liked_button { background: #0566AE; width: 50px; padding: 3px; color: white; text-align: center; position: absolute; margin-left: -95px; z-index: 6; border-radius: 3px; cursor: pointer; font-family: 'Days One', sans-serif; font-size: 18px; letter-spacing: 1px; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .liked_button { background: #2C599D; margin-left: -95px; margin-top: 0; } .like_button:hover { background: #2C599D; } .show { opacity: 1; } /* End of Like Button */ /* End of Movie Content */ /* Tab System for admin.php */ h1, h2, h3, h4 { padding: 0; margin: .1rem 0; border-left: 4px solid #4F2CCA; padding-left: 8px; } .material-tabs { display: block; float: left; padding: 16px; padding-top: 0; width: 100%; max-width: 480px; left: calc(50% - 480px/2); position: relative; margin: 96px auto; background: #fff; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23) !important; border-radius: 2px; } #media all and (max-width: 480px) { .material-tabs { max-width: 100%; left: 0; } } .visible { position: relative; opacity: 1; width: 100%; height: auto; float: left; -webkit-transition: opacity .35s ease; transition: opacity .35s ease; z-index: 3; } .hidden { position: absolute; opacity: 0; z-index: 0; -webkit-transition: opacity 0s ease; transition: opacity 0s ease; } .hidden img { display: none; } [class*="tabbed-section-"] { float: left; color: #000; } [class*="tabbed-section-"] img { display: block; width: 80%; margin: auto 10%; } .tabbed-section__selector { position: relative; height: 32px; top: -31.2px; left: -16px; padding: 0; margin: 0; width: 100%; float: left; } .tabbed-section__selector [class*="-tab-"] { float: left; display: block; height: 32px; line-height: 32px; width: 100px; text-align: center; background: #fff; font-weight: bold; text-decoration: none; color: black; font-size: 14px; } .tabbed-section__selector [class*="-tab-"].active { color: #4F2CCA; } .tabbed-section__selector a:first-child { border-top-left-radius: 2px; } .tabbed-section__selector a:last-of-type { border-top-right-radius: 2px; } .tabbed-section__highlighter { position: absolute; z-index: 10; bottom: 0; height: 2px; background: #4F2CCA; max-width: 100px; width: 100%; -webkit-transform: translateX(0); transform: translateX(0); display: block; left: 0; -webkit-transition: -webkit-transform 0.23s ease; transition: -webkit-transform 0.23s ease; transition: transform 0.23s ease; transition: transform 0.23s ease, -webkit-transform 0.23s ease; } .tabbed-section__selector-tab-3.active ~ .tabbed-section__highlighter { -webkit-transform: translateX(200px); transform: translateX(200px); } .tabbed-section__selector-tab-2.active ~ .tabbed-section__highlighter { -webkit-transform: translateX(100px); transform: translateX(100px); } .tabbed-section__selector-tab-1.active ~ .tabbed-section__highlighter { -webkit-transform: translateX(0); transform: translateX(0); } .divider { background: rgba(0, 0, 0, 0.1); position: relative; display: block; float: left; width: 100%; height: 1px; margin: 8px 0; padding: 0; overflow: hidden; } /* End of Tab system for admin.php */ /* Create */ #title, #length { font-size: 16px; border: 1px solid #ccc; padding: 11px; outline: none; border-radius: 3px; width: 400px; } #title:focus, #description:focus, #length:focus { border: 1px solid #A9A9A9; } #description { font-size: 16px; border: 1px solid #ccc; padding: 11px; outline: none; border-radius: 3px; width: 400px; resize: vertical; max-height: 70px; } #rating_text { position: relative; top: -10px; } #length_text { position: relative; top: -10px; } /* End of Create */ /* Dropdown Selection */ nav { margin: 10rem auto; width: 220px; position: absolute; left: 1150px; top: -140px; } nav ul { color: #fff; font-family: sans-serif; font-size: 1.4rem; letter-spacing: .1rem; position: relative; width: 100%; } nav a { background: #1A1A1A; color: inherit; display: block; text-decoration: none; padding: 1rem; } nav ul ul a:hover { background: #666; } nav ul ul { display: none; padding-top: 1rem; position: absolute; } nav ul:hover ul { display: block; } nav ul:first-child:hover > li:first-child:before { border: .7rem solid transparent; border-top-color: #fff; } nav ul ul > li:not(:last-child) { border-bottom: 1px solid white; } nav ul > li:first-child:before { content: ""; position: absolute; } nav ul:first-child > li:first-child:before { border: .7rem solid transparent; border-top-color: #fff; pointer-events: none; left: 175px; top: 30px; } .fa { margin-right: .5rem; } /* End of Dropdown Selection */ /* Files Left */ #files_left { color: red; width: 110px; padding: 1px; border: 1px solid red; text-align: center; border-radius: 10%; position: relative; left: 15px; top: 20px; } /* End of Files Left */ /* Avatar */ .avatar_friend { width: 36px; height: 36px; position: relative; z-index: 10; border: 1px solid white; } /* End of Avatar */ Some of the CSS may be for other pages. I realize this is a lot of information. Let me know if you need anything else...
First of all, you use the same id in 6 elements for every movie, which you shouldn't. An id is unique, so change that to like 'descriptive_div_1', 'descriptive_caret_1', etc (I did that in the samples below so you can see where). This is how a movie section looks like (repeated for each movie, no wrapper around each of them) <div id='descriptive_div_2' number='2'> <i class='fa fa-caret-left' id='descriptive_caret_2' number='2'></i> <a href='like.php?number=8&page=1'> <a href='like.php?number=8&page=1&code=1&sorting=recent'> <div class='like_button' number='2'> Like </div> </a> </a> <span id='descriptive_div_text_2'> s </span> <div id='files_left_2'> 1 Copy Left </div> </div> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_length' number='2'> <div id='movie_length_text_2' number='2'> 2h 16m </div> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_rating_2' number='2'> <span id='movie_rating_text_2' number='2'> PG-13 </span> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <img src='covers/star wars.jpg' class='movie_size' number='2'> </a> <img src='avatars/sam.jpg' class='avatar_friend'> <img src='avatars/traek.jpg' class='avatar_friend'> <img src='avatars/jessie.jpg' class='avatar_friend'> So to be able to target each avatar_friend in each movie section, you need CSS rules like this .avatar_friend { width: 36px; height: 36px; position: absolute; z-index: 10; border: 1px solid white; } div[number] + a + a + a ~ .avatar_friend:nth-of-type(3n+1) { left: 0px; } div[number] + a + a + a ~ .avatar_friend:nth-of-type(3n+2) { left: 36px; } div[number] + a + a + a ~ .avatar_friend:nth-of-type(3n+3) { left: 72px; } The problem with this is you need to know how many avatars_friend's it is, as you need to change the nth-of-type counter and the amount of CSS rules accordingly. By adding a wrapper like this for the avatar's, will fix it for you <div id='descriptive_div_2' number='2'> <i class='fa fa-caret-left' id='descriptive_caret_2' number='2'></i> <a href='like.php?number=8&page=1'> <a href='like.php?number=8&page=1&code=1&sorting=recent'> <div class='like_button' number='2'> Like </div> </a> </a> <span id='descriptive_div_text_2'> s </span> <div id='files_left_2'> 1 Copy Left </div> </div> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_length' number='2'> <div id='movie_length_text_2' number='2'> 2h 16m </div> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_rating_2' number='2'> <span id='movie_rating_text_2' number='2'> PG-13 </span> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <img src='covers/star wars.jpg' class='movie_size' number='2'> </a> <div class='avatar_friend_wrapper'> <img src='avatars/sam.jpg' class='avatar_friend'> <img src='avatars/traek.jpg' class='avatar_friend'> <img src='avatars/jessie.jpg' class='avatar_friend'> </div> .avatar_friend_wrapper { position: absolute; left: 0; } .avatar_friend { width: 36px; height: 36px; position: relative; z-index: 10; border: 1px solid white; } What I recommend to do, would be to change your PHP loops so they generate something like this instead, where each movie item has its own wrapper. With that you get a completely different control how to layout each movie info item based on screen size etc. <div class='movie_div_2' number='2'> <div id='descriptive_div_2' number='2'> <i class='fa fa-caret-left' id='descriptive_caret_2' number='2'></i> <a href='like.php?number=8&page=1'> <a href='like.php?number=8&page=1&code=1&sorting=recent'> <div class='like_button' number='2'> Like </div> </a> </a> <span id='descriptive_div_text_2'> s </span> <div id='files_left_2'> 1 Copy Left </div> </div> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_length' number='2'> <div id='movie_length_text_2' number='2'> 2h 16m </div> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <div class='movie_rating_2' number='2'> <span id='movie_rating_text_2' number='2'> PG-13 </span> </div> </a> <a href='open.php?destination=movies/56c7ede7d3ed3108.44679765.mp4'> <img src='covers/star wars.jpg' class='movie_size' number='2'> </a> <div class='avatar_friend_wrapper'> <img src='avatars/sam.jpg' class='avatar_friend'> <img src='avatars/traek.jpg' class='avatar_friend'> <img src='avatars/jessie.jpg' class='avatar_friend'> </div> </div>