I'm trying to do a simple animation using only css. The idea is that when I hover a social icon it will seem like it's lifting up. I managed to do that but now i want to use "border" to seem like it's the icon's shadow. I reduced the thickness of the border on hover but I wanted to make it seem more realistic and somehow reduce the width of the border when hovering over. Any ideas?
Here is my fiddle: http://jsfiddle.net/Iulius90/sck4Lzz9/
html
<div>
<img src="http://fc05.deviantart.net/fs70/f/2012/204/7/b/logo_skype_by_jackal807-d58ctxc.png">
</div>
css
div {
width:200px;
height:200px;
background-color:tomato;
}
img {
width: 100px;
height:100px;
margin: 50px;
border-bottom: 3px solid #222;
transition: all 0.35s ease;
}
div img:hover {
margin-top: 22px;
padding-bottom:28px;
border-bottom: 1px solid #222;
transition: all 0.35s ease;
cursor: pointer;
}
You can simply use a solid linear gradient as a background image, and manipulate its dimensions upon hover. Note: You might want to use vendor prefixes to generate CSS gradients that are cross browser compatible.
img {
background-image: linear-gradient(to top, rgba(0,0,0,.5) 0%, rgba(0,0,0,.5) 100%);
background-position: center bottom;
background-repeat: no-repeat;
background-size: 100% 3px;
width: 100px;
height:100px;
margin: 50px;
transition: all 0.35s ease;
}
div img:hover {
background-size: 50% 1px;
margin-top: 22px;
padding-bottom:28px;
transition: all 0.35s ease;
cursor: pointer;
}
http://jsfiddle.net/teddyrised/sck4Lzz9/26/
Related
I have a hover effect that moves a new background-color over an existing one, making it appear the background is fading to the right. For some reason a bit of the background-color is showing on the left side of the blocks.
The only thing I could think of was my black border, but I have a border set in the elements natural style.
Does anyone know what is causing this?
#service-tabs-left {
float: left;
margin-left: 150px;
}
#service-tabs-right {
float: right;
margin-right: 150px;
}
.service-tab-block {
position: relative;
font-size: 1.6em;
padding: 1em 25px;
text-align: center;
display: block;
margin: 30px 0;
cursor: pointer;
border: 1px solid #838557;
background-image: linear-gradient(to right, #000 50%, #838557 50%);
background-size: 200% 100%;
background-repeat: no-repeat;
background-position: bottom right;
transition:width 0.2s ease;
-webkit-transition:width 0.2s ease;
}
.service-tab-block.active {
background: #000;
color: #FFF;
}
.service-tab-block:hover {
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
background-position: bottom left;
color: #FFF;
border: 1px solid #000;
}
<div id="service-tabs-left">
<h1 class="service-tab-block" id="service_tab1">DEMOLITION</h1>
<h1 class="service-tab-block" id="service_tab2">ENVIRONMENTAL SOLUTIONS</h1>
<h1 class="service-tab-block" id="service_tab3">CONCRETE CRUSHING</h1>
</div>
<div id="service-tabs-right">
<h1 class="service-tab-block" id="service_tab4">ASSET RECOVERY</h1>
<h1 class="service-tab-block" id="service_tab5">SCRAP METAL RECYCLING</h1>
<h1 class="service-tab-block" id="service_tab6">FOUNDATION REMOVAL</h1>
</div>
You have to change the background-size property from 200% to 201%. The extra 1% gives the cover you need.
https://jsfiddle.net/o7sxoton/
I fixed it by changing the linear gradient for black to 49% on .service-tab-block
BTW , this is one of those issues you can see by adjusting your browsers zoom for anyone who was wondering.
.service-tab-block {
background-image: linear-gradient(to right, #000 49%, #838557 50%);
Set this:
.service-tab-block{
box-sizing:border-box;
-moz-box-sizing:border-box;
}
I am trying to mask image (with text shadow) using CSS property -webkit-mask-image.
I understand that I can use background-clip however I need to do this using only mask-image
property for some reason. However upon trying it out I was stack with some CSS codes.
here's my CSS code:
#masking h1, span.mask-text {
font-size: 230px;
font-family: 'Lilita One', sans-serif;
text-align: center;
margin: 0 auto;
padding: 0;
-webkit-text-fill-color:transparent;
position:absolute;
left: 100px;
}
#masking h1 {
text-shadow: 3px 3px 0px #34495e;
z-index:2;
}
span.mask-text {
-webkit-mask-image: url('http://halloweenmaternitycostumes.com/wp-content/uploads/2014/11/paper.jpg') no-repeat center center;
background-size: cover;
z-index:5;
-webkit-transition:all 0.7s ease;
-moz-transition:all 0.7s ease;
-o-transition:all 0.7s ease;
transition:all 0.7s ease;
}
span.mask-text:hover{
cursor: pointer;
-webkit-mask-image: ('http://halloweenmaternitycostumes.com/wp-content/uploads/2014/11/paper-hover.jpg') no-repeat center center;
background-size: cover;
z-index:5;
}
span.mask-text:after {
content: 'Mask Text';
text-transform: uppercase;
}
Here's an image what I am trying to do:
Here's the jsFiddle version: http://jsfiddle.net/cmtr3txu/2/
If you could show me the solution using jsFiddle that would be great.
I updated your code here:
http://jsfiddle.net/cajvgkxt/3/
To add a background to the text, do as follows... Note: background must come before clipping!
span{
font-size: 50px;
font-family: Helvetica, Arial;
background: url(http://www-users.cs.umn.edu/~interran/texture/lic2.gif);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<span>Text</span>
Your code does two things novel-- animation and text-shadow. For the text-shadow, I made sure that your span and h1 both had font-weight:bold (by default, one is bold and the other is not). For the animation, I left it up to you to customize. You'll need to change the easing and background position.
So I'll try and be brief - we have a slider on our website and when we upload the images the text on the slider is difficult to read, so we figured out that if we added a white overlay in photoshop to the picture, the slider looks much better.
However, this is not a great solution because once the post moves to the general column, we find that the image with the overlay by photoshop is now not as appealing to the eye.
The solution that was asked ,was can we add a semi-transparent overlay to the div that holds the slider, so that way any image uploaded will have that semi transparent overlay only in the slider.
I did some research on here and other sites working with overlay and css - and have worked it into a set where I'm almost there but am missing some fundamental pieces I think.
Right now its working on hover only, so I need to figure that out, but if you see the example you'll understand
In my utopia - if I click on RUN on jsfiddle, that image should have the overlay on it already, not on hover and I think I'm missing where I'm supposed to make edits
http://jsfiddle.net/9LXcU/
.box {
border:1px solid #000;
padding:5px;
height:151px;
width:195px;
}
.overlay {
background:rgba(255, 0, 0, .75);
text-align:center;
opacity:0;
width:100%;height:100%;
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
-o-transition: all 0.3s ease-in-out;
-ms-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
.box:hover {
border:1px solid #555;
border-radius:5px;
}
.box:hover .overlay {
opacity:12;
}
.search {
position:relative;
top:60px;
}
Well, here is a FIDDLE that may be what you want.
CSS
.box {
border:1px solid #000;
padding:5px;
height:151px;
width:195px;
text-align:center;
background: url('http://www.breastcanceranswers.com/wp-content/uploads/2013/10/featuredimagebcam.jpg');
background-repeat: no-repeat;
background-position: 50% 50%;
}
.overlay {
width: 100%;
height: 100%;
background-color: pink;
opacity: 0.5;
color: red;
vertical-align: middle;
}
This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 6 years ago.
I have been trying to use css to show a Hidden Div fade in whenever I hover its parent element.
So far all I have managed to do was to get the hidden div to show, but there are no easing transitions what so ever.
Here is my Code on JSfiddle http://jsfiddle.net/9dsGP/
Here is my Code:
HTML:
<div id="header">
<div id="button">This is a Button
<div class="content">
This is the Hidden Div
</div>
</div>
</div>
CSS:
#header #button {width:200px; background:#eee}
#header #button:hover > .content {display:block; opacity:1;}
#header #button .content:hover { display:block;}
#header #button .content {
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
opacity:0;
clear: both;
display: none;
top: -1px;
left:-160px;
padding: 8px;
min-height: 150px;
border-top: 1px solid #EEEEEE;
border-left: 1px solid #EEEEEE;
border-right: 1px solid #EEEEEE;
border-bottom: 1px solid #EEEEEE;
-webkit-border-radius: 0px 7px 7px 7px;
-moz-border-radius: 0px 7px 7px 7px;
-khtml-border-radius: 0px 7px 7px 7px;
border-radius: 0px 7px 7px 7px;
-webkit-box-shadow: 0px 2px 2px #DDDDDD;
-moz-box-shadow: 0px 2px 2px #DDDDDD;
box-shadow: 0px 2px 2px #DDDDDD;
background: #FFF;
}
Any clue as to what Im doing wrong? Just trying to get a smooth effect for the hidden content when I hover over the button. Thanks in advance!
display:none; removes a block from the page as if it were never there.
A block cannot be partially displayed; it’s either there or it’s not.
The same is true for visibility; you can’t expect a block to be half
hidden which, by definition, would be visible! Fortunately, you can
use opacity for fading effects instead.
- reference
As an alternatiive CSS solution, you could play with opacity, height and padding properties to achieve the desirable effect:
#header #button:hover > .content {
opacity:1;
height: 150px;
padding: 8px;
}
#header #button .content {
opacity:0;
height: 0;
padding: 0 8px;
overflow: hidden;
transition: all .3s ease .15s;
}
(Vendor prefixes omitted due to brevity.)
Here is a working demo. Also here is a similar topic on SO.
#header #button {
width:200px;
background:#ddd;
transition: border-radius .3s ease .15s;
}
#header #button:hover, #header #button > .content {
border-radius: 0px 0px 7px 7px;
}
#header #button:hover > .content {
opacity: 1;
height: 150px;
padding: 8px;
}
#header #button > .content {
opacity:0;
clear: both;
height: 0;
padding: 0 8px;
overflow: hidden;
-webkit-transition: all .3s ease .15s;
-moz-transition: all .3s ease .15s;
-o-transition: all .3s ease .15s;
-ms-transition: all .3s ease .15s;
transition: all .3s ease .15s;
border: 1px solid #ddd;
-webkit-box-shadow: 0px 2px 2px #ddd;
-moz-box-shadow: 0px 2px 2px #ddd;
box-shadow: 0px 2px 2px #ddd;
background: #FFF;
}
#button > span { display: inline-block; padding: .5em 1em }
<div id="header">
<div id="button"> <span>This is a Button</span>
<div class="content">
This is the Hidden Div
</div>
</div>
</div>
You cannot use height: 0 and height: auto to transition the height. auto is always relative and cannot be transitioned towards. You could however use max-height: 0 and transition that to max-height: 9999px for example.
Sorry I couldn't comment, my rep isn't high enough...
I found a solution while tinkering around.
People who directly wanna see the results:
With click: https://jsfiddle.net/dt52jazg/
With Hover: https://jsfiddle.net/7gkufLsh/1/
Below is the code:
HTML
<ul class="list">
<li>Hey</li>
<li>This</li>
<li>is</li>
<li>just</li>
<li>a</li>
<li>test</li>
</ul>
<button class="click-me">
Click me
</button>
CSS
.list li {
min-height: 0;
max-height: 0;
opacity: 0;
-webkit-transition: all .3s ease-in-out;
transition: all .3s ease-in-out;
}
.active li {
min-height: 20px;
opacity: 1;
}
JS
(function() {
$('.click-me').on('click', function() {
$('.list').toggleClass('active');
});
})();
Please let me know whether there is any problem with this solution 'coz I feel there would be no restriction of max-height with this solution.
I faced the problem with display:none
I have several horizontal bars with transition effects but I wanted to show only part of that container and fold the rest while maintaining the effects. I reproduced a small demo here
The obvious was to wrap those hidden animated bars in a div then toggle that element's height and opacity
.hide{
opacity: 0;
height: 0;
}
.bars-wrapper.expanded > .hide{
opacity: 1;
height: auto;
}
The animation works well but the issue was that these hidden bars were still consuming space on my page and overlapping other elements
so adding display:none to the hidden wrapper .hide solves the margin issue but not the transition, neither applying display:none or height:0;opacity:0 works on the children elements.
So my final workaround was to give those hidden bars a negative and absolute position and it worked well with CSS transitions.
Jsfiddle
Made some changes, but I think I got the effect you want using visibility. http://jsfiddle.net/9dsGP/49/
I also made these changes:
position: absolute; /* so it doesn't expand the button background */
top: calc(1em + 8px); /* so it's under the "button" */
left:8px; /* so it's shifted by padding-left */
width: 182px; /* so it fits nicely under the button, width - padding-left - padding-right - border-left-width - border-right-width, 200 - 8 - 8 - 1 - 1 = 182 */
Alternatively, you could put .content as a sibling of .button, but I didn't make an example for this.
max-height
.PrimaryNav-container {
...
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
...
}
.PrimaryNav.PrimaryNav--isOpen .PrimaryNav-container {
max-height: 300px;
}
https://www.codehive.io/boards/bUoLvRg
When you need to toggle an element away, and you don't need to animate the margin property. You could try margin-top: -999999em. Just don't transition all.
I styled a link so that when you hover it, there will appear a border on the top; and when you hover off the border will disappear with a transition. The border slides in instead of fading in when you hover over it and off. I want the border to fade in instead of slide. How can I do this? Here is a JsFiddle
HTML
<div>Text</div>
CSS
div {
line-height: 50px;
width: 100px;
text-align: center;
cursor: pointer;
transition: border .2s ease-in-out;
-webkit-transition: border .2s ease-in-out;
-moz-transition: border .2s ease-in-out;
}
div:hover {
border-top: 3px solid #000;
}
html, body {
margin: 0;
padding: 0;
}
If you want to animate the color, animate the color, not the entire border. You're now also animating it from 0 pixels to 3 pixels, so of course it slides in. You should just give it a default transparent border instead.
div {
line-height: 50px;
width: 100px;
text-align: center;
cursor: pointer;
transition: border-color .5s ease-in-out;
border-top: 3px solid transparent;
}
div:hover {
border-top-color: #000;
}
Sample on JSfiddle
As a sidenote: -moz-transition is obsolete nowadays, since FF17 or so Mozilla supports the CSS Transitions module without prefix.
Update dec 2014: as I noticed this answer is still being viewed and upvoted frequently, please note that transition is no longer prefixed in any current or recently superseded browsers.
In this case - you are going to need to have a border to begin with as well. Make it transparent in the first state. This way it will not "grow" into place... and the color will just fade as it changes.
http://jsfiddle.net/kLnQL/11/
div {
border: 3px solid transparent;
}
div:hover {
border: 3px solid #f06;
}