I am trying to build a simple css slider that shows specific text when in the :target state. The text actually appears fine but what's happening is it's just appearing instead of sliding in. I have left:0 set on the parent and the idea being that when the slide id is selected the parent should move to left: -100%/-200%/-300% depending on the slide targeted. Hope this makes sense, markup is below.
Appreciate any advice where I have gone wrong.
.slider__wrapper {
width: 300px;
margin: 50px auto 0 auto;
}
.slider {
position: relative;
overflow: hidden;
}
.slider__inner {
position: relative;
width: 300%;
left: 0;
transition: all .6s;
}
.slider__slides {
float: left;
width: 33.333%;
font-size: 25px;
}
.slider__toggle {
display: inline-block;
margin-right: 10px;
margin-top: 20px;
font-size: 16px;
}
#slide--1 {
background: red;
}
#slide--2 {
background: yellow;
}
#slide--3 {
background: green;
}
#slide--1:target~.slider__inner {
left: 0;
transition: all .6s;
}
#slide--2:target~.slider__inner {
left: -100%;
transition: all .6s;
}
#slide--3:target~.slider__inner {
left: -200%;
transition: all .6s;
}
<div class="slider__wrapper">
<div class="slider">
<div class="slider__inner">
<div class="slider__slides" id="slide--1">
slide 1
</div>
<div class="slider__slides" id="slide--2">
slide 2
</div>
<div class="slider__slides" id="slide--3">
slide 3
</div>
</div>
</div>
<div class="slider__toggle">
01
02
03
</div>
</div>
Related
basically all i want to do is: Have a picture and when someone hovers over it i want some text to appear in its position(in the middle to be exact). What I have done so far is make the picture disappear on hover but i cannot get the text to be appeared..
Html:
<div class="container">
<img id="atp "class="atp" src="atp.jpg">
<div class="center">Some text</div>
</div>
Css:
atp{
display:block;
margin-left:auto;
margin-right:auto;
width:27%;
height:50%;}
container{
position: relative;
text-align: center;
}
.center{
position: absolute;
top:50%;
left:50%;
opacity: 0;
}
So basically, what i seek to be done is .atp:hover{opacity:0;} and what I also want is on atp's hover the .center{opacity:1;] So is there a way to put the opacity of center's to 1 when I am in the atp:hover{} code block?
Hope everything looks fine, thanks in advance!
Here is the code. Hope it will help you. if any changes please let me know.
/********* Simple or original overlay *******/
/* Main container */
.overlay-image {
position: relative;
width: 100%;
}
/* Original image */
.overlay-image .image {
display: block;
width: 100%;
height: auto;
}
/* Original text overlay */
.overlay-image .text {
color: #fff;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
/********* Overlay on hover *******/
/* New overlay on hover */
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
/* New overlay appearance on hover */
.overlay-image:hover .hover {
opacity: 1;
}
/********* Background and text only overlay on hover *******/
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.5);
}
<div class="overlay-image">
<a href="LINK_URL">
<div class="normal">
<div class="text">Image + text ORIGINAL</div>
</div>
<div class="hover">
<img class="image" src="https://dummyimage.com/200x150/00ccff/fff.png" alt="Alt text hover" />
</div>
</a>
</div>
#atp {
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
width: 27%;
height: 50%;
z-index: 50;
}
.container {
position: relative;
text-align: center;
}
.center {
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
}
#atp:hover {
opacity: 0;
}
try this, using z-index. It worked with me :)
I'm sure this is an easy fix but I am new to HTML/CSS - I want a piece of text in a div to slide over another div which contains an image as well as text. Currently the slider div is not covering the entire div as the background text is preventing it from doing that. How do I make it completely overlap?
Here is my code:
.items-tall {
background-color: #F473FF;
height: 450px;
overflow: hidden;
}
.items-tall-slider {
background-color: black;
height: 450px;
width: 100%;
margin-left: -100%;
transition: 0.5s;
color: white;
font-size: 60px;
text-align: center;
line-height: 450px;
}
.items-tall:hover .items-tall-slider {
margin-left: 0%;
transition: 0.5s;
}
<div class="row">
<div class="col-4 col-m-6 items-tall">
This is my title.<br> I currently want all this text behind the slider. Hover over this.
<div class="items-tall-slider"> Sliding info. </div>
</div>
Add this to your .items-tall-slider:
position:absolute;
top:0;
and this for positioning:
.row {
position:relative;
}
.items-tall {
background-color: #F473FF;
height: 450px;
overflow: hidden;
}
.items-tall-slider {
background-color: black;
height: 450px;
width: 100%;
margin-left: -100%;
transition: 0.5s;
color: white;
font-size: 60px;
text-align: center;
line-height: 450px;
position:absolute;
top:0;
}
.items-tall:hover .items-tall-slider {
margin-left: 0%;
transition: 0.5s;
}
.row {
position:relative;
}
<div class="row">
<div class="col-4 col-m-6 items-tall">
This is my title.<br>
I currently want all this text behind the slider. Hover over this.
<div class="items-tall-slider">
Sliding info.
</div>
</div>
</div>
You also missed one </div> closing tag. I've added that in this example.
In your example the easiest solution would be to add position: absolute; top: 0 to the .items-tall-slider. This has the potential undesired side effect though, that the slider doesn't take any space anymore. Therefore any other elements in your page could be overlapped by your slider as well.
If you don't want this side effect, you could add a negative margin to your slider like this (or in the example below) and therfore overlap your text:
.items-tall-slider {
margin-top: -40px;
}
.items-tall-slider {
margin-top: -40px;
}
.items-tall {
background-color: #F473FF;
height: 450px;
overflow: hidden;
}
.items-tall-slider {
background-color: black;
height: 450px;
width: 100%;
margin-left: -100%;
transition: 0.5s;
color: white;
font-size: 60px;
text-align: center;
line-height: 450px;
}
.items-tall:hover .items-tall-slider {
margin-left: 0%;
transition: 0.5s;
}
<div class="row">
<div class="col-4 col-m-6 items-tall">
This is my title.<br> I currently want all this text behind the slider. Hover over this.
<div class="items-tall-slider"> Sliding info. </div>
</div>
I've come across a strange bug in Safari browser rendering.
When I hover over element (green .hover) which makes its child element (pink .pop) visible, the child stays visible even after the hover has ended. It's visible but not selectable - I can select text "behind" the child element as you can see in the screenshot below.
HTML:
<div class="hover">
Hover me! (display)
<div class="pop pop--display">
I will cover your content in Safari indefinitely
</div>
</div>
<div class="content">
Content
</div>
CSS:
.hover {
position: relative;
overflow: hidden;
}
.pop {
position: absolute;
top: 80%;
left: 10px;
}
.hover:hover {
overflow: visible;
}
.pop--display {
display: none;
}
.hover:hover .pop--display {
display: block;
}
It seems to be caused by changing overflow hidden/visible of the parent element together with changing of display none/block (or visibility hidden/visible) of the child element. I came across this bug using JavaScript but mere CSS :hover can reproduce it.
Tested on Safari 8.0.6 (10600.6.3) and 9.0.1 (11601.2.7.2).
/* basic styling and formating */
.hover {
padding: 10px 0;
width: 200px;
background: green;
}
.pop {
padding: 20px;
height: 90px;
width: 140px;
background: pink;
}
.content {
width: 200px;
padding-top: 20px;
height: 100px;
background: grey;
}
.test + .test {
margin-top: 30px;
}
/* overflows and positioning */
.hover {
position: relative;
overflow: hidden;
}
.pop {
position: absolute;
top: 80%;
left: 10px;
}
.hover:hover {
overflow: visible;
}
/* variations */
.pop--display {
display: none;
}
.hover:hover .pop--display {
display: block;
}
.pop--visibility {
visibility: hidden;
}
.hover:hover .pop--visibility {
visibility: visible;
}
<div class="test">
<div class="hover">
Hover me! (default)
<div class="pop">
I will cover your content in Safari indefinitely
</div>
</div>
<div class="content">
Content
</div>
</div>
<div class="test">
<div class="hover">
Hover me! (display)
<div class="pop pop--display">
I will cover your content in Safari indefinitely
</div>
</div>
<div class="content">
Content
</div>
</div>
<div class="test">
<div class="hover">
Hover me! (visibility)
<div class="pop pop--visibility">
I will cover your content in Safari indefinitely
</div>
</div>
<div class="content">
Content
</div>
</div>
The only solution I could came to is to use opacity with pointer-events. I expect opacity: 0; pointer-events: none to act the same way as visibility: hidden.
But I'm still not sure if this is a right approach...
The corresponding CSS is:
.pop--opacity {
opacity: 0;
pointer-events: none;
}
.hover:hover .pop--opacity {
opacity: 1;
pointer-events: auto;
}
/* basic styling and formating */
.hover {
padding: 10px 0;
width: 200px;
background: green;
}
.pop {
padding: 20px;
height: 90px;
width: 140px;
background: pink;
}
.content {
width: 200px;
padding-top: 20px;
height: 100px;
background: grey;
}
.test + .test {
margin-top: 30px;
}
/* overflows and positioning */
.hover {
position: relative;
overflow: hidden;
}
.pop {
position: absolute;
top: 80%;
left: 10px;
}
.hover:hover {
overflow: visible;
}
.pop--opacity {
opacity: 0;
pointer-events: none;
}
.hover:hover .pop--opacity {
opacity: 1;
pointer-events: auto;
}
<div class="test">
<div class="hover">
Hover me! (opacity)
<div class="pop pop--opacity">
I will cover your content in Safari indefinitely
</div>
</div>
<div class="content">
Content
</div>
</div>
I want to reduce element size a bit as an effect, when it is hovered over with a mouse. However, this looks buggy because as the element reduces in size, the "hover area" gets smaller as well, which can result into the element not being hovered anymore, which further results into this "size flickering".
Is there a proper way to implement element size reduction on hover, while keeping the hover area size the same? Without extra elements?
Here is a fiddle: https://jsfiddle.net/ahvonenj/88f5by59/
Required code for fiddle linking:
#di
{
position: absolute;
left: 15px;
top: 15px;
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di:hover
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
Wrapping it in a div would be better, as commented. But if adding no other elements is a must, you could work with pseudo elements.
Make the visible part a pseudo element (like :before), and keep the main one just for hovering:
TIP: If you want the transition effect on both mouse over and out, set the property to the main css rule, not to the hover one
#di
{
position: absolute;
left: 15px;
top: 15px;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di:before {
content: "";
display: block;
background-color: #2980b9;
width: 100px;
height: 100px;
}
#di:hover:before
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<div id = "di">
</div>
You can wrap the div inside a container and "bind" the hover event to the parent.
P.S obviously it is a solution with adding other elements.
#container
{
position: absolute;
left: 15px;
top: 15px;
box-sizing: border-box;
}
#container, #di{
width: 100px;
height: 100px;
}
#di{
background-color: #2980b9;
}
#container:hover #di
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<div id="container">
<div id="di">
</div>
</div>
Yep, this is your answer. You have to add one more element. See this fiddle:
https://jsfiddle.net/vwy4utf5/
html:
<div id = "di">
<div id="diin">
</div>
</div>
CSS
#di{width:101px; height:101px; cursor:pointer; position: absolute;
left: 15px;
top: 15px;}
#diin
{
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
transition: all 200ms linear;
}
#di:hover > div
{
width: 50px;
height: 50px;
transition: all 200ms linear;
}
I tried it using Jquery, didn't specified by OP but I guess it can help somebody.
So changed css to make parent positioning of new parent:
#di {
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di_parent {
padding: 0;
overflow: hidden;
position: absolute;
left: 15px;
top: 15px;
}
#di_parent:hover > DIV {
width: 50px;
height: 50px;
transition: all 200ms linear;
}
Then added some JQuery to create a container to each object to maitain size as is suggested above.
$('#di').each(function(i, v){
var o, p;
o=$(v);
p=$('<div id="di_parent"></div>');
p.css({height:o.outerHeight(),width:o.outerWidth()});
o.after(p);
p.append(o.detach());
});
Working fiddle:
https://jsfiddle.net/88f5by59/11/
$('#di').each(function(i, v){
var o, p;
o=$(v);
p=$('<div id="di_parent"></div>');
p.css({height:o.outerHeight(),width:o.outerWidth()});
o.after(p);
p.append(o.detach());
});
#di {
background-color: #2980b9;
box-sizing: border-box;
width: 100px;
height: 100px;
}
#di_parent {
padding: 0;
overflow: hidden;
position: absolute;
left: 15px;
top: 15px;
}
#di_parent:hover > DIV {
width: 50px;
height: 50px;
transition: all 200ms linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id = "di">
</div>
Hope it helps!
I have a small bug that I can't seem to locate. In my snippet you can see how whenever you hover over the image, opactiy and an image scale takes place, as well as a box comes over the image. That is perfect, but my issue is whenever you hover over the text below it, the hover effect takes place over the image.
I can't seem to figure out how for the hover effect to only take place when the mouse is hovering over the image.
Any suggestions would be appreciated.
$('.home-img-block img').addClass(function() {
return (this.width / this.height > 1) ? 'wide' : 'tall';
});
#home-img-block-section {
width: 100%;
height: 900px;
}
#home-img-blocks {
width: 100%;
height: 750px;
}
.home-img-block {
width: 33.33%;
float: left;
display: block;
overflow: hidden;
position: relative;
}
.home-img-container {
position: relative;
overflow: hidden;
cursor: pointer;
}
.home-img-block:hover .overlay {
background: rgba(0, 0, 0, 0.6);
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}
.home-img-container:after {
content: attr(data-content);
color: #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: all 0.5s;
border: 1px solid #fff;
padding: 20px 25px;
text-align: center;
}
.home-img-container:hover:after {
opacity: 1;
}
.home-img-block img {
display: block;
transition: all 1s ease;
}
.home-img-block:hover img {
transform: scale(1.25);
background: rgba(0, 0, 0, 0.3);
width: 33.33%;
max-height: 100%;
overflow: hidden;
}
.home-img-block img.wide {
max-width: 100%;
max-height: 100%;
height: auto;
width: 100%;
}
.home-img-block img.tall {
max-width: 100%;
max-height: 100%;
width: auto;
}
#home-img-block-wording-container {
width: 100%;
height: 300px;
}
.home-img-wording-blocks {
width: 100%;
height: 100%;
text-align: center;
display: inline-block;
vertical-align: top;
}
.home-img-wording-block-title {
padding-top: 30px;
font-size: 1.7em;
}
.home-img-wording-block-description {
padding: 25px 50px 0 50px;
font-size: 1.1em;
color: #5d5d5d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="home-img-block-section">
<div id="home-img-blocks">
<div class="home-img-block fadeBlock1">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test1.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">WEB DESIGN</div>
<div class="home-img-wording-block-description">The OD team can see your web design visions brought
to life, creating a site that promotes your uniqueness through specific functionalities and features.</div>
</div>
</div>
<div class="home-img-block fadeBlock2">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test2new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">ECOMMERCE</div>
<div class="home-img-wording-block-description">Custom built solutions catered towards you end goal.
gfdgfdsg greg reg regrfesg fdsg gretswtgy tgreswt treswt trgegfd gsvbd fbgre greasgv drfdg greaag gredr</div>
</div>
</div>
<div class="home-img-block fadeBlock3">
<div data-content="FIND OUT MORE" class='home-img-container'>
<img src="http://optimumwebdesigns.com/images/test3new.jpg">
<div class="overlay"></div>
</div>
<div class="home-img-wording-blocks">
<div class="home-img-wording-block-title">MARKETING STRATEGIES</div>
<div class="home-img-wording-block-description">MARKETING STRATEGIES gfdgf fdggs gfsg gfsg gf sgf g
gfdsg sdfggfs gfdsgssdfg fdggfds gfdsg gfds gfdgs gf dsgfdsgfgs gfdgfs gtrg resg reg rgesgresrgrg</div>
</div>
</div>
</div>
</div>
.home-img-block:hover .overlay
and
.home-img-block:hover img
replace them with
.home-img-container:hover .overlay
.home-img-container:hover img
otherwise you're triggering when you hover over the whole container instead of only wheen hovering the img one.