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
Related
CSS newbie here.
I have this image and I want to reveal it from right to left, what do I have to add/change to this code?
.arr1 {
display:block;
position:absolute;
left:1001px;
top:920px;
width:0;
height:99px;
background:url(../img/arr1.png) no-repeat;
background-size:254px 99px;
opacity: 0;
transition: 0.5s linear;
pointer-events: none;
&:hover{
opacity: 1;
pointer-events: all;
width: 254px;
transition-delay: 1s;
}
}
A bit difficult to give a reliable answer without more code, but from what you posted, change the absolute position of the container to right instead of left and add the width of the image to the former left value, resulting in 1255px:
.arr1 {
display:block;
position:absolute;
right:1255px;
top:920px;
width:0;
height:99px;
background:url(../img/arr1.png) no-repeat;
background-size:254px 99px;
opacity: 0;
transition: 0.5s linear;
pointer-events: none;
&:hover{
opacity: 1;
pointer-events: all;
width: 254px;
transition-delay: 1s;
}
}
You might also want to add background-position: right to .arr1, depending how you want the image to be revealed.
So i made a php form with chekboxes which i show as images. Now i gave them a transition thing witch goes from opacity 0.5 to 1 if you click on them
now i would have liked to change the border color from red to yellow but if I combine those 2 transition only one seems to work. The opacity is there but it instantly goes from 0.5 to 1 and not in a 2 second timespan
Here is my css with 2 transitions:
img {
width: 100%;
max-width: 390px;
height: 100%;
max-height: 250px;
margin: -3px;
border-radius:15px;
transition:opacity 2s ease;
opacity: 0.5;
transition: border 1s ease;
border: red 3px solid;
}
now there is a little bit more of important code which I cannot display cause the nice stackoverflow editor does not accept it as css
I still hope someone can help me
You can have multiple transitions by seperating them with a comma on the same transition: rule.
img {
width: 100%;
max-width: 390px;
height: 100%;
max-height: 250px;
margin: -3px;
border-radius:15px;
transition:opacity 2s ease, border 1s ease;
opacity: 0.5;
border: red 3px solid;
}
In the case you have multiple transitions, all with the same duration and timing function, you can use the shorthand all:
transition: all 2s ease;
Working Example
I'm using the following CSS code on my linked images:
a img:hover {
filter: alpha(opacity=80);
-khtml-opacity: 0.8;
-moz-opacity: 0.8;
opacity: 0.8;
background: #f00;
}
The idea is that when a user hovers over an image, this will be slightly tinted with red. The browser though seems to ignore the "background: #f00;" property.
What am I doing wrong?
Thanks in advance
It won't work as you are having image, so you need to have an overlay element, probably a div
Demo
HTML
<div class="wrap">
<img src="http://images.google.co.in/intl/en_ALL/images/logos/images_logo_lg.gif" />
<div class="overlay"></div>
</div>
CSS
.wrap {
position: relative;
display: inline-block;
}
.overlay {
position: absolute;
width: 100%;
height: 100%;
background: transparent;
top: 0;
}
.wrap:hover .overlay {
background: rgba(250, 0, 0, .1);
}
Note: You should have a positioned relative container, else your absolute positioned div will run out in the wild, moreover, you can remove display: inline-block; and provide respective height and width to the container element, see to it that it sticks to your image, alternatively you can also use transitions for smooth effect
For transition you need to modify the class like this
.overlay {
position: absolute;
width: 100%;
height: 100%;
background: transparent;
top: 0;
transition: background 1s;
-moz-transition: background 1s;
-webkit-transition: background 1s;
-o-transition: background 1s;
}
Demo Transition
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/
I want a div to float next to my input but instead it's floating over top of it, and I'm not sure why. It's as if the div is set to use absolute positioning. I think I'm probably just overlooking something silly, but what is it?
html:
<input type="file" id="files" name="file" />
<div id="progress_bar"><div class="percent">0%</div></div>
css:
input { float: left;}
#progress_bar {
margin: 10px 0;
padding: 3px;
border: 1px solid #000;
font-size: 14px;
//clear: both;
opacity: 0;
-moz-transition: opacity 1s linear;
-o-transition: opacity 1s linear;
-webkit-transition: opacity 1s linear;
}
#progress_bar.loading {
opacity: 1.0;
}
#progress_bar .percent {
background-color: #99ccff;
height: auto;
width: 0;
}
I have an example here:
http://jsfiddle.net/sWrvU/
which is based on the read files demo on html5rocks http://www.html5rocks.com/en/tutorials/file/dndfiles/
Uncomment clear:both to see the demo actually work (i.e. you can press the button because there's not a div on top of it), but then obviously the div still isn't floated next to the input.
Using display: block instead of opacity removes the transition, which I'm guessing you're trying to keep.
The Progress bar isn't "floating over top" so much as the input is floating underneath. If you float the progress bar as well, things should go a little better: http://jsfiddle.net/cjc343/sWrvU/24/
I changed it to use display instead of opacity since opacity means the element is still there even though it is transparent.
CSS
input {
float: left;
}
#progress_bar {
margin: 10px 0;
padding: 3px;
border: 1px solid #000;
font-size: 14px;
display:none;
-moz-transition: opacity 1s linear;
-o-transition: opacity 1s linear;
-webkit-transition: opacity 1s linear;
}
#progress_bar.loading {
display:block;
}
#progress_bar .percent {
background-color: #99ccff;
height: auto;
width: 0;
}