I'm trying to create a transition from a white background to an image background. This way when the viewer hovers over a section it goes from plain to styled.
Here's my current code:
div.camp {
background: #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 8px;
padding: 8px;
transition: all 1s linear 0s;
}
div.camp:hover {
background: #EFFFD5 url("http://www.alpinejosh.com/host/sp/images/camp.png");
background-position: center bottom;
background-repeat: repeat-x;
border: 1px solid #CECECE;
}
Here's the page this code is on: http://www.summitpost.org/eldorado-peak/150316#chapter_7
From what I understand it's easy to have background colors transition. But it seems as though background images are not supported for transition.
Unfortunately you cannot use transition on background images in the way you've specified. You can see the W3C list of animation property types here.
You could potentially lay your white background over the top, then animate its opacity on hover (to show the image beneath).
Code Sample
You could obviously make this prettier. I've just cobbled something together to give you an idea.
div.camp {
border: 1px solid #CCCCCC;
background: #EFFFD5 url("http://www.alpinejosh.com/host/sp/images/camp.png");
background-position: center bottom;
background-repeat: repeat-x;
border-radius: 8px;
position: relative;
}
div.camp-overlay {
padding: 8px;
border-radius: 8px;
position: absolute;
z-index:50;
width: 100%;
height: 100%;
background:white;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
}
div.camp-overlay:hover {
background: rgba(255,255,255,0); /* use opacity for older browsers*/
}
HTML for the above CSS
<div class="camp">
<div class="camp-overlay"></div>
</div>
JSFiddle of the above
http://jsfiddle.net/p7mcy/
What you could do is make two div elements, one on top of the other, and fade top div out on hover.
<div class="wrapper">
<div class="image"></div>
<div class="white-bg"></div>
</div>
.wrapper{position:relative;}
.image, .white-bg{position:absolute; top:0; left:0; width:100px; height:50px;}
.image{background:red;}
.white-bg{background:white; z-index:9999; -webkit-transition:opacity 0.3s linear; opacity:1;}
.white-bg:hover{opacity:0;}
Should work
fiddle: http://jsfiddle.net/b46z8/5/
Related
I introduced a hover animation over a button. The hover animation works perfectly fine, but it has the side-effect that you can no longer click on the button once the animation ends. I would like to change this but I can't seem to figure out how.
.chooseFileBtn, .submitFileBtn{ /* ignore the '.submiteFileBtn' here */
margin-top:180%;
padding-left: 30%;
padding-right:30%;
padding: 10px 20px;
border-radius: 8px;
background-color: #E55300;
transition: all 500ms ease;
/*transition: all 0.5s; */
}
.chooseFileBtn:before {
content:'';
position:absolute;
top:34.1%;
left:41.1%;
height:5.6%;
width:0px;
border-radius: 8px;
background:rgba(255,255,255,0.3);
transition: all 2s ease;
}
.chooseFileBtn:hover:before {
width:8.72%;
}
The chooseFileBtn is just a standard button, it shouldn't be relevant for the solution to my issue, but if you would like me to share it with you then feel free to ask. Also, this is written in a seperate .css file. This .css file is linked to the main .html file.
You dont need to wrap your anchor in a div!!
That is why your anchor is not working after animation because it covers your anchor.
<a class="chooseFileBtn" href="#" id="uploadLink" onClick="chooseUpload();">
<h1 align="center" id="chooseFileBtnText">Upload file</h1>
</a>
CSS
.chooseFileBtn, .submitFileBtn{ /* ignore the '.submiteFileBtn' here */
display: block;
padding: 10px 20px;
border-radius: 8px;
background-color: #E55300;
transition: all 500ms ease;
/*transition: all 0.5s; */
}
.chooseFileBtn:before {
content:'';
position:absolute;
top:0;
left:0;
height:50%;
width:0px;
border-radius: 8px;
background:rgba(255,255,255,0.3);
transition: all 2s ease;
}
.chooseFileBtn:hover:before {
width:100%;
}
See my fidde https://jsfiddle.net/o2gxgz9r/47362/
Ok, so i have a little bit of a weird problem.
I have been working on a little website for a school project and i needed a panel of buttons on the side.
So i made some divs and made them link to my other pages and so on.
But then a weird problem came up. The area where i could click my divs was not confined to the area of the margin, but it went out to the full length of the page's horizontal axis, but not the vertical.
I have tried searching around for some kind of solution to this problem, but can't seem to find any. I have also tried to change the margin of my divs, but nothing seems to work.
This is the HTML code for my div and the link
<a href="main.html">
<div class="MenuTop">
<p id="MenuTextOn">Forside</p>
</div>
</a>
And this is the CSS code associated with that div element.
.MenuTop {
position: relative;
border-width: 3px;
border-style: solid;
border-color: black;
width: 70px;
height: 60px;
border-radius: 15px 30px;
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
background: -webkit-linear-gradient(bottom right, gray, #F0F0F0);
margin: 15px;
It should be noted that i'm new to this, but understand the basic principles.
Thanks for helping in advance! :D
You don't need to put a div inside an a element, just style the a starting with a display:block (to have it as a div by default):
Let's also organise better the CSS
.MenuTop {
/* positioning */
position: relative;
/* box-model */
display: block;
width: 70px;
height: 60px;
margin: 15px;
border-width: 3px;
border-style: solid;
border-color: black;
/* style */
background: -webkit-linear-gradient(bottom right, gray, #F0F0F0);
border-radius: 15px 30px;
opacity: 1;
/* effects */
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
Have a look here: https://jsfiddle.net/7063nkfg/
Read about inline and block elements in HTML - http://www.impressivewebs.com/difference-block-inline-css/
P.S.You don't need to put DIV and P tags into A, this will make your code difficult to read and undestand.
Make it all simplier, with styles:
html:
<div>
Text1
Text2
Text3
</div>
css:
a.menu {
display: block;
box-sizing: border-box;
padding: 15px;
width: 70px;
height: 60px;
/* other styles */
}
I'm completely new to CSS & Wordpress, I've spent all night trying and looking for a solution to this - so hopefully you can help me.
I have this image, and when someone hovers over it I want the white/see-through portion in the middle to fill with the colour #f7ca18 from the bottom to the top
http://wp.tek-monkey.com/wp-content/uploads/2015/06/circle1_test_seethrough.png
I've tried the following just to try and get a simple transition from the white/see-through inner to my desired colour, however none of them have worked. I'm not sure if I'm doing something wrong in wordpress; under appearance>editor I paste the css code at the bottom, and then on the page with the image I edit the image and type into the box (Image CSS Class) .circle-testfor example.
.circle-test {
background: #ffffff;
transition-property: background;
transition-duration: 1s;
transition-timing-function: linear;
}
.circle-test:hover {
background: #f7ca18;
}
.circle-test:hover{
background-color: #f7ca18;
}
.circle-test{
background:none;
}
.circle-test:hover{
background:#f7ca18;
}
Totally doable. The trick to this is adding a border-radius of 100% to create a circle around the image. Here are three ways you can do this.
Codepen
I also cropped & re-exported your image so that it's a perfect 275px square (If you ever need to do bg transitions on an irregularly-shaped image, you could look into SVG). You're more than welcome to download that image and use it instead!
I did this kind of quickly, so let me know if you have any questions!
/* Option 1: Image only */
.circle-test {
display: block;
margin: 0 auto;
border-radius: 100%;
background-image: url('http://www.heavilyedited.com/hands-temp.png');
background-repeat: no-repeat;
-webkit-transition: background 1s linear;
-moz-transition: background 1s linear;
transition: background 1s linear;
}
.circle-test:hover {
background-color: #f7ca18;
}
/* Option 2: Div with background image*/
.circle-test2 {
display: block;
width: 275px;
height: 275px;
margin: 0 auto;
border-radius: 100%;
background-image: url('http://www.heavilyedited.com/hands-temp.png');
background-repeat: no-repeat;
transition: background 1s linear;
}
.circle-test2:hover {
background-color: #1D9B8D;
}
/* Option 3: Image is inside div*/
.circle-test3 {
display: block;
width: 275px;
height: 275px;
margin: 0 auto;
border-radius: 100%;
background-image: url('http://www.heavilyedited.com/hands-temp.png');
background-repeat: no-repeat;
-webkit-transition: background 1s linear;
-moz-transition: background 1s linear;
transition: background 1s linear;
}
.circle-test3:hover {
background-color: #00aeef;
}
<!-- Option 1: Image only -->
<img src="http://www.heavilyedited.com/hands-temp.png" class="circle-test"/>
<!-- Option 2: Div with background image -->
<div class="circle-test2">
</div>
<!-- Option 3: Image is inside div-->
<div class="circle-test3">
<img src="http://www.heavilyedited.com/hands-temp.png" />
</div>
I am a complete newbie when it comes to HTML and CSS and just building my very first website. I want to create an image that, when hovered, displays text and fades the image to a lower opacity. I've got the fade all worked out, as well as the opacity change. My only issue is that the text, which is contained within the element I want to fade, also fades and I would like to keep it at 100% opacity. I have tried setting opacity to 1 for the text but it does not override the opacity change of its container. For example, I have:
<div class="textbox">
<p class="boxtext">This is the text that will eventually go inside the box. It is blah lljsd iofu isduf iou eiosu dfi eiou sdiofu ioe soidfu oidu foiu foisu doiu eoiusodidfu oei osidfuosdiu ieu oisduf oiueoisu dfoi oiu soifu iod fioeo dfs.</p>
</div>
And also
div.textbox {
background-color: white;
margin-left: 2.5vw;
border: 2px solid lightgray;
width: 15vw;
height: 600px;
float: left;
}
div.textbox:hover {
background-color: lightgray;
border: 2px solid lightgray;
opacity: 0.5;
}
p.boxtext {
margin: 5% 5%;
}
This creates the hover that I want, but I can't keep the text opacity at 100%.
Edit: Thank you for providing the rgba() solution, this solves the problem. I have another case of the same problem except that there is a background image instead of a solid background color. Is there a similar workaround?
Edit2: Issues with fade breaking after replacing opacity change with a separate transparent .png.
a#imglink1 {
background-image: url('https://www.profilesinhistory.com/wp-content/uploads/2012/11/Apollo-11-NASA-Photograph-Signed-Neil-Armstrong-Michael-Collins-Buzz-Aldrin-200x200.jpg');
width: 200px;
height: 200px;
float: left;
-o-transition: 0.5s;
-ms-transition: 0.5s;
-moz-transition: 0.5s;
-webkit-transition: 0.5s;
transition: 0.5s;
}
a#imglink1:hover {
background-image: url('../images/apollo_transparent.png');
-o-transition: 1s;
-ms-transition: 1s;
-moz-transition: 1s;
-webkit-transition: 1s;
transition: 1s;
}
a#imglink1:hover p {
visibility: visible;
}
Since you're using a solid background color you can use rgba to only change the opacity of the background/borders and not affect the content inside. In your example:
div.textbox:hover {
background-color: rgba(222,222,222,.5);
border: 2px solid rgba(222,222,222,.5);
}
https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgba()
For images you can accomplish a fade using :before and :after and fading the opacity of those elements:
a#imglink2 {
width: 200px;
height: 200px;
float: left;
position: relative;
}
a#imglink2 p
{
position: relative;
z-index:2;
}
a#imglink2:before
{
background-image: url('http://images2.layoutsparks.com/1/239061/welcome-orange-vintage-design.gif');
width: 200px;
height: 200px;
position: absolute;
top:0; left:0;
content:'';
z-index:1;
opacity:1;
transition: .3s opacity linear;
}
a#imglink2:after
{
background-image: url('http://images.all-free-download.com/images/graphicmedium/vintage_christmas_background_32295.jpg');
width: 200px;
height: 200px;
position: absolute;
top:0; left:0;
content:'';
z-index:1;
opacity:0;
transition: .3s opacity linear;
}
a#imglink2:hover:before
{
opacity:0;
}
a#imglink2:hover:after
{
opacity:1;
}
http://codepen.io/seraphzz/pen/ikJqB
I am trying to tint images onHover. I have the css working but some of the images which have rounded edges or don't completely fill the parent show the black background:
(The far left has the mouse over it)
How can hide the black so only the img is tinted?
Here is my css:
.thumb {
width:150px;
height:150px;
margin: 0px 5px 14px 14px;
float:left;
display:inline;
background: black;
overflow:hidden;
cursor: pointer;
/*border: 2px solid #00A3C6; */
}
.thumb img {
display: block;
-webkit-transition: all 0.25s linear;
-moz-transition: all 0.25s linear;
-ms-transition: all 0.25s linear;
-o-transition: all 0.25s linear;
transition: all 0.25s linear;
}
.thumb:hover img {
opacity: 0.7;
}
If the image has rounded corners, you can use border-radius in your css to set rounded corners of the "tint" container.
If the actual image has a white border... you're kind of out of luck. You can crop images but you don't have any way to doing this dynamically for any kind of image.
How can hide the black so only the img is tinted?
Try removing background: black from .thumb ?
P.S. display: inline is also not needed there