how to avoid slide transition in social icons on hover?
i want my all social icons in one png file and use transition also but it show up with sliding it not transition like two different images
#social_icons {
display:inline-block;
background: url(http://www.gobothell.com/wp-content/uploads/2012/01/FB-and-Twitter-icons-300x181.jpg) no-repeat center center;
background-position: 0px 0px;
width: 150px;
height: 175px;
transition: 0.5s ease, forward;
border: 1.5px solid blue;
margin:10px;
}
#social_icons:hover {
background: url(http://www.gobothell.com/wp-content/uploads/2012/01/FB-and-Twitter-icons-300x181.jpg) no-repeat center center;
background-position: -150px 0px;
width: 150px;
height: 175px;
}
#social_icons2 {
display:inline-block;
background: url(http://www.florestrekkingtour.com/userfiles/images/FB_icons.png) no-repeat center center;
width: 200px;
height: 200px;
transition: 0.5s ease, forward;
border: 1.5px solid blue;
margin:10px;
}
#social_icons2:hover {
background: url(https://cdn3.iconfinder.com/data/icons/inside/PNG/256x256/icontexto-inside-facebook.png) no-repeat center center;
background-position: 0px 0px;
background-size: 200px 200px;
width: 200px;
height: 200px;
}
h2 {
background:rgba(0, 0, 0, 0.7);
color:yellow;
text-align:center;
text-shadow:0px 0px 10px lime;
margin-top:45%;
}
1 image
<div id="social_icons"><h2>Hover me</h2></div>
2 images
<div id="social_icons2"><h2>Hover me</h2></div>
This is not possible with CSS3 Transitions with a single element, the property your transitioning(changing) is background-position, hence the reason it appear sliding,
If a Fade In/Fade Out effect is what you require, you could use a CSS3 Animation to fade the element out on hover, move it to the desired background position then fade back in the new image.
If a Cross-fade is what you require there is either background-image: cross-fade()
background-image: cross-fade(url("logo-box.png"), url("logo-bare.png"), 50%);
But it has very limited browser support i.e. http://caniuse.com/#feat=css-cross-fade.
Or probably the best option is using 2 elements and fade out one on top of the other, you could use a Pseudo Element (IE8+) to fake an extra element i.e.
#social_icons:before {
content:"";
display:inline-block;
position:absolute;
opacity:0;
background: url(https://cdn3.iconfinder.com/data/icons/inside/PNG/256x256/icontexto-inside- facebook.png) no-repeat center center;
background-position: 0px 0px;
background-size: 200px 200px;
width: 200px;
height: 200px;
}
See http://jsfiddle.net/sjmcpherso/kr7ec28q/ for working example
Related
I have a problem with my icon when on hover. I want to replace my img src during on hover: heres my code so far:
#aks {
width: 0px;
max-height: 0;
transition: max-height 0.15s ease-out;
overflow: hidden;
background: url("https://img.icons8.com/windows/32/000000/like.png") no-repeat;
padding: 50px;
}
#aks:hover {
background: url("https://img.icons8.com/officexs/32/000000/like.png")
no-repeat;
max-height: 500px;
transition: max-height 0.25s ease-in;
}
<img id="aks" src="https://img.icons8.com/windows/32/000000/like.png" />
What I really want to achieve is when hovered on outline heart icon will replace with heart filled icon but during replacing the outline icon it will show/animate from bottom height 0 to full height so it look like it filled the outline icon. here some example: codepen
any alternatives or solutions other than this is highly appreciated.
thanks in advance!
This isn't particularly easy on a CSS-only heart because the sliding animation would have to be applied to three completely distinct elements (the rotated square, plus the two circles).
For the sake of thoroughness, here is an example using a font that includes a heart. For simplicity, I used Webdings but you should use Font Awesome in actual live code.
The summary is your background is a 2x taller gradient that is 50% white and 50% red, and you slide the background from showing the white half to instead showing the red half upon hover. Two important properties of this will currently only work on webkit browsers: text-stroke, which adds the outline to the text -- and background-clip, which clips the non-text portion of the span's background.
span {
background-size: 100% 200%;
background-image: linear-gradient(to bottom, white 50%, red 50%);
color: transparent;
font-family: webdings;
font-size: 200px;
transition: background-position 2s;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-stroke-width: 5px;
-webkit-text-stroke-color: red;
text-stroke-width: 5px;
text-stroke-color: red;
}
span:hover {
background-position: 0 100%;
}
<span>Y</span>
Well if using css is an option for you then, you can take a look at this:
.heart {
background-color: red;
height: 30px;
width: 30px;
transform: rotate(-45deg);
transition: background-color 1s;
}
.heart::before,
.heart::after {
content: '';
background-color: red;
height: 30px;
width: 30px;
border-radius: 50%;
position: absolute;
transition: background-color 1s;
}
.heart::before {
top: -15px;
}
.heart::after {
left: 15px;
}
.heart:hover,
.heart:hover::before,
.heart:hover::after {
background-color: #F5A9AE;
}
body {
display: flex;
height: 100vh;
}
.heart {
margin: auto;
}
<div class="heart"></div>
You can do it with background animation like below:
.heart {
width: 50px;
height:50px;
padding-top:50px;
background:
url("https://img.icons8.com/officexs/32/000000/like.png") bottom padding-box content-box,
linear-gradient(#fff,#fff) bottom padding-box content-box,
url("https://img.icons8.com/windows/32/000000/like.png");
background-size:100% 100%;
background-repeat:no-repeat;
box-sizing:border-box;
transition:0.5s;
}
.heart:hover {
padding-top:0;
}
<div class="heart"></div>
How can we add a black shadow to a background image, shadow starting at opacity 1 and gradually decreasing to opacity 0, on all 4 sides of the image? (At least 50 pixels worth of "decreasing shadow opacity". box-shadow offers only a small amount of shadow in which the opacity goes down gradually.)
I've tried playing around with mask-image, for example: -webkit-mask-image: -webkit-gradient(linear, left 85%, left bottom, from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
This creates the desired shadow but only at the bottom of the image, not sure if this could be used to create it on the other 3 sides.
Edit: The shadow should be inside (I believe inset if box-shadow)
The goal of this will be to make our users' cover photos look good on our website's black background, even if they have brighter photos. The shadow inside the image should help the image blend in with the site's black background.
Something like this?
html,
body {
height: 100%;
}
div {
height: 100%;
display: flex;
justify-content: space-around;
align-items: center;
}
.inner {
width: 200px;
height: 200px;
background-image: url(http://via.placeholder.com/200x200);
background-size: cover;
background-position: center center;
box-shadow: 0px 0px 40px 5px #000000;
}
<div>
<div class="inner"></div>
</div>
Wait, wait....a voice is telling me the background of the page is a dark, dark, color. The shadow should be on the inside of the element, start from the darkest of darks and fade into the image, like this...
html,
body {
height: 100%;
background-color: #000000;
}
div {
height: 100%;
display: flex;
justify-content: space-around;
align-items: center;
}
.inner {
width: 200px;
height: 200px;
background-image: url(http://via.placeholder.com/200x200);
background-size: cover;
background-position: center center;
box-shadow: 0px 0px 40px 20px #000000 inset;
}
<div>
<div class="inner"></div>
</div>
What's that? Whoa, hold up... I'm sensing the box-shadow should go super, super deep... like this:
html,
body {
height: 100%;
background-color: #000000;
}
div {
height: 100%;
display: flex;
justify-content: space-around;
align-items: center;
}
.inner {
width: 200px;
height: 200px;
background-image: url(http://via.placeholder.com/200x200);
background-size: cover;
background-position: center center;
box-shadow: 0px 0px 70px 50px #000000 inset;
}
<div>
<div class="inner"></div>
</div>
;)
Sounds like the mind-reading is still off. So here's a final example using a linear-gradient.
html,
body {
height: 100%;
background-color: #000000;
}
div {
height: 100%;
display: flex;
justify-content: space-around;
align-items: center;
}
.inner {
width: 200px;
height: 200px;
background-image: radial-gradient(circle at center, rgba(0,0,0, 0.1) 0%, #000000 70%, #000000 100%), url(http://via.placeholder.com/200x200);
background-size: cover, cover;
background-position: center center, center center;
}
<div>
<div class="inner"></div>
</div>
A possibility is to use the CSS3 box-shadow property with the inset marker. This will pop a shadow inside a container or element (similar to what is sometimes called a vignette in image editors) which adheres to the element's proportions, so it might not be what you're after.
Ex. HTML
<div id="container"></div>
Ex. CSS
#container {
width:100px;
height:100px;
background-image:url(path/to/image.jpg);
background-size:cover;
-webkit-box-shadow:inset 0 0 50px #000000;
box-shadow:inset 0 0 50px #000000;
}
Playing with the vertical and horizontal offset values (here set at 0) may produce more effective results, for example something like this ...
width: 200px;
height: 200px;
box-shadow: inset 0 100px 50px -25px #000000;
... will give the impression of a vertical gradient, top-2-bottom, dark-2-light.
As always, there's a great explanation of the box-shadow property over # CSS-Tricks.
Hope that helped. :)
What I am looking to achieve is to display an image with a transparent background layer, this image would sit over a background which would have a white border and gray box centred in the image area.
Basically to give the image a partial gray background, then to leave the rest white, to give the appearance of the image to "float" over the gray background as well as allow me to make simple css changes to change the background verses having to redo the images to change the look.
this is the css I have tried:
.borderlist img {
text-align:center;
vertical-align:middle;
background:
linear-gradient
(255,255,255, 0.9),
url('../images/gray.png') no-repeat;
max-width: 100%;
height:auto;
}
And the html:
<span class="borderlist"><img src="images/bounty.png" alt="BOUNTY" title=" BOUNTY " width="225" height="155"></span><br>BOUNTY
I removed the underline from the <a> because it creates a weird underline on the <br>. If you want the text to be underlined, you could throw it in a <span> with a class that tells it to have it. but this is what I got. Let me know if you're needing it to do something different.
.overflowing-img {
display: inline-block;
text-align: center;
text-decoration: none;
}
.undrline {
text-decoration: underline;
}
.borderlist {
text-align: center;
}
.borderlist img {
text-align:center;
vertical-align:middle;
background-image: linear-gradient(rgba(160,160,160, 0.5), rgba(160,160,160, 0.5));
background-repeat: no-repeat;
background-size: 80% auto;
background-position: center center;
}
<a href="http://www.domain.com/bounty.html" class="overflowing-img">
<span class="borderlist">
<img src="http://pngimg.com/upload/gift_PNG5950.png" alt="BOUNTY" title=" BOUNTY " width="225" height="155">
</span>
<br>
<span class="undrline">BOUNTY<span>
</a>
I used a different image, but is this what you are attempting to achieve?
.borderlist img {
width: 200;
height: 100;
}
.borderlist {
width: 225px;
height: 125px;
text-align: center;
vertical-align: middle;
background: linear-gradient(to bottom, #c8c8c8, #ffffff);
margin: auto;
}
.whiteBorder {
width: 255px;
height: 155px;
background-color: #ffffff;
text-align: center;
}
<div class="whiteBorder">
<div class="borderlist">
<a href="http://www.domain.com/bounty.html">
<img src="http://en.wikipedia.org/static/images/project-logos/enwiki.png" alt="BOUNTY" title="BOUNTY">
<br>BOUNTY</a>
</div>
</div>
Try doing using :before in your css to overlay the image on top of a div.
div{
width: 200px; height: 200px;
background-color: lightgray;
box-sizing: border-box;
border: 20px solid white;
position: relative;
}
div:before{
content: "";
display: block;
margin: -20px;
width: 200px;
height: 200px;
background-image: url('https://i.stack.imgur.com/eLzG5.png');
background-size: contain;
background-repeat: no-repeat;
}
<div></div>
Lets go very simple first:
You can't move the image to left by changing css though
.borderlist {
background: grey;
border: 60px solid white;
box-sizing: border-box;
width: 260px;
}
<div class="borderlist">
<img src="https://s9.postimg.org/d0odjmlcv/dwa.png" height="100px" width="150px" />
</div>
You can do this too, create a container div, inside, create the grey div, then float the image above the grey div, like this (I think this is the best):
.borderlist {
padding: 5%;
background: white;
width: 160px;
height: 120px;
position: relative;
}
.grey {
position: absolute;
background: grey;
width: 130px;
height: 90px;
margin: 10px;
}
.float {
position: absolute;
}
<div class="borderlist">
<div class="grey">
</div>
<img class="float" src="https://s9.postimg.org/d0odjmlcv/dwa.png" height="100px" width="150px" />
</div>
Feel free to change and play around to understand it properly
If you're OK with using a mask (white colored background covering the edges), you could use multiple backgrounds coupled with a background color. (credit to user Dave Cripps for the demo image that I shamelessly stole from his demo for mine.)
a {
text-align:center;
display:inline-block;
}
.borderlist {
display:inline-block;
text-align:center;
vertical-align:middle;
background:
linear-gradient(to right, white 15%, transparent 15%, transparent 85%, white 85%), linear-gradient(to bottom, white 15%, transparent 15%, transparent 85%, white 85%);
background-color: #eee;
transition: background-color 0.4s;
}
a:hover .borderlist {
background-color: #5C5;
}
.borderlist img {
height:auto;
}
<span class="borderlist"><img src="http://en.wikipedia.org/static/images/project-logos/enwiki.png " alt="BOUNTY" title=" BOUNTY " width="225" height="155"></span><br>BOUNTY
This design is created in photoshop and I'm trying to convert to html and css.
I have a background image (with the green lights), an overlay with reduced opacity and some text with an icon positioned at the center. How can I attain the effect shown below in html and css?
you could apply a border-radius to the inner element and a box-shadow like so:
Codepen Demo
div {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: url(...) no-repeat;
background-size: cover;
}
p {
border-radius: 50%;
/* add responsive behaviour */
height : 60vw;
width : 60vw;
/* but limit its max-height/width */
max-height : 400px;
max-width : 400px;
/* apply a gray shadow outside */
box-shadow : 0 0 0 50vmax rgba(255,255,255, .4);
}
50vmax is a shadow spread wide enough and middle alignment can be done e.g. via flexbox positioning. Just adjust the alpha value of the shadow (or the color) as you prefer.
Final result
Check here!
Basically you can create a transparent round shape with a big white (or black) border!
background: transparent;
border-radius: 50%;
border: 1000px solid rgba(0, 0, 0, 0.5);
JSFiddle
.container {
height:400px;
width:400px;
position:relative;
overflow:hidden;
}
.overlay {
top:50%;
left:50%;
margin-top:-500px;
margin-left:-500px;
width: 200px;
height: 200px;
border-radius: 50%;
position: absolute;
background-color: transparent;
border-style: solid;
box-sizing: content-box;
z-index:999;
pointer-events:none;
border: 400px solid rgba(0,0,0,.9);
}
<div class="container">
<div class="overlay"></div>
</div>
I have two problems with my portfolio section which is not as smooth as I want it to be. Here they are:
I wanted my projects to change background-color and show a small plus sign when hovering over them. In the same time I wanted to add a "transition: all 0.5s ease-in-out;" but the result is not what I expected. It probbaly happens because my "plus sign" should be located in another div but I didn't know how to make it work. Instead I put it here:
.projectshot a .over:hover{
position: absolute;
background: url(http://www.iconsea.com/uploadimage/smallsort/4015/4dxtdhpaxqw.png) center center no-repeat rgba(51, 51, 51, 0.6);
border-radius: 8px;
height: 150px;
width: 200px;
margin: 10px;
}
This is the effect I wanted to achieve: http://bjorsberg.se/
The second problem that bothers me is that, if you look really carefully, when you approach each of the projects with the mouse the mouse pointer starts to "dance" and it behaves crazy??? How can I fix that???
Here is my JSFiddle:
http://jsfiddle.net/8fCMA/2/
.plus{
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
margin: -49px 0 0 -56px;
background: url(img/plus.png) center center no-repeat;
}
I am quite new to web design (4 months since I started learning) and I am clearly not good with positioning div's inside div inside another div... So, please feel free to correct my fiddle if you see any trouble I created. Thanks!
I would simplify the html structure if I were you, as it is not necessary.
e.g.: projectshot can look like this:
<div class="projectshot">
<a href="http://www.yahoo.com" target="_blank">
<img alt="Sushi" src="...">
</a>
</div>
and you can add the "cover" as :before pseudoelement.
Then - in css all you need to do is to add this to the "cover" element:
opacity: 0;
transition: opacity .2s;
and - on hover - change the opacity to 1:
opacity: 1;
here's the updated demo
(I've removed a lot of your html/css code just for demo purposes)
I've just made some small changes including:
Moving the hover to the .projectshot box.
Moving background-position and background-repeat to the non
hover definition.
Adding the transitions.
It works for now but you can still remove a lot of code. Even the html can be heavily reduced.
I suggest you to have a look at that too (DEMO).
.projectshot{
position: relative;
padding: 10px;
height: 150px;
margin-bottom: 30px;
display: inline-block;
}
.projectshot img{
height: 150px;
width: 200px;
border-radius: 8px;
-webkit-box-shadow: 0 9px 13px rgba(0,0,0,.14);
-moz-box-shadow: 0 9px 13px rgba(0,0,0,.14);
box-shadow: 0 9px 13px rgba(0,0,0,.14);
}
.projectshot:hover .over{
background-image: url(http://www.iconsea.com/uploadimage/smallsort/4015/4dxtdhpaxqw.png);
background-color: rgba(51, 51, 51, 0.6);
transition: all 0.5s ease-in-out;
}
.projectshot:hover {
cursor: pointer;
}
.over{
position: absolute;
border-radius: 8px;
height: 150px;
width: 200px;
box-sizing:border-box;
-moz-box-sizing:border-box;
background-repeat: no-repeat;
background-position: center center;
transition: all 0.5s ease-in-out;
}
.inner{
background: rgba(113,122,137,.85);
border-radius: 8px;
width: 100%;
height: 100%;
display: none;
}
.plus{
width: 100px;
height: 100px;
position: absolute;
left: 50%;
top: 50%;
margin: -49px 0 0 -56px;
background: url(img/plus.png) center center no-repeat;
}