So i'm trying to change the hover effect of my divs. When I started the project I had it just the way I want it now, but back then I didn't want it that way, so I changed it. Now I can't seem to change it back.
so here is my code,
HTML
<div id="left">
<div id="leftImage">
//the background image
</div>
<div id="overlayLeft">
//a logo that goes on top of the image when not hovering over it
</div>
</div>
<div id="right">
<div id="rightImage">
//the background image
</div>
<div id="overlayRight">
//a logo that goes on top of the image when not hovering over it
</div>
</div>
CSS
body {
background: #ffff;
}
/* Setup for the halves of the screen */
#right
{
/* Set rules to fill background */
min-height: 100%;
min-width: 50%;
/* Set up proportionate scaling */
width: 50%;
height: auto;
position: fixed;
top: 0;
right: 0;
background: #389A7A;
background-size:cover;
}
#left
{
/* Set rules to fill background */
min-height: 100%;
min-width: 50%;
/* Set up proportionate scaling */
width: 50%;
height: auto;
position: fixed;
top: 0;
left: 0;
background: #0C4270;
background-size:cover;
}
/* Setup for the image containers */
#rightImage, #leftImage
{
opacity:1.00;
filter: alpha(opacity=100); /* For IE8 and earlier */
background: rgba(0, 0, 0, 0.15);
-webkit-transition: opacity 2.00s ease;
-moz-transition: opacity 2.00s ease;
transition: opacity 2.00s ease;
position: relative;
}
#rightImage:hover, #leftImage:hover
{
opacity:0.15;
filter: alpha(opacity=15); /* For IE8 and earlier */
background: rgba(0, 0, 0, 1.0);
}
#rightImage:hover + #overlayRight, #leftImage:hover + #overlayLeft
{
visibility: visible;
-webkit-transition: visibility 0.5s ease;
-moz-transition: visibility 0.5s ease;
transition: visibility 0.5s ease;
}
/* Setup for the images */
.rightImage
{
/* Set rules to fill background */
min-width: 50%;
min-height: 100%;
/* Set up proportionate scaling */
width: 50%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0px;
right: 0;
}
.leftImage
{
/* Set rules to fill background */
min-width: 50%;
min-height: 100%;
/* Set up proportionate scaling */
width: 50%;
height: auto;
/* Set up positioning */
position: fixed;
top: 0px;
left: 0;
}
/* Setup for the logo image */
#overlayLeft
{
visibility: hidden;
}
.overlayLeft
{
/* Set rules to fill background */
min-width: 40%;
/* Set up proportionate scaling */
width: 40%;
/* Set up positioning */
position: absolute;
top: 35%;
left: 30%;
pointer-events: none;
}
#overlayRight
{
visibility: hidden;
}
.overlayRight
{
/* Set rules to fill background */
min-width: 40%;
/* Set up proportionate scaling */
width: 40%;
/* Set up positioning */
position: absolute;
top: 40%;
right: 30%;
pointer-events: none;
}
And here is the code in action: JsFiddle
So what i want to achieve is that when I hover the left div the effect that now happens ons the left div must happen on the right div. The piece of code that is making the hovering work is this the piece below:
#rightImage:hover, #leftImage:hover
{
opacity:0.15;
filter: alpha(opacity=15); /* For IE8 and earlier */
background: rgba(0, 0, 0, 1.0);
}
I tought one of the following operators would work: "+", "~", or just a simple space between :hover and the next div (#rightImage:hover #leftImage).
Yet I cannot seem to get it to work..
What am I doing wrong? Is it that the elements doesn't have the same parent? I tried adding a parent div arround the whole html. Yet that didn't work.
As far as I am aware hover states can only affect the element being hovered or child elements. You'll need to use some light javascript to achieve this.
You should be able to wrap both your #left and #right div's and then apply the hover style to that element. Like this:
<div class="wrapper">
<div id="left"> ... </div>
<div id="right"> ... </div>
</div>
and then ...
.wrapper:hover #rightImage, .wrapper:hover #leftImage{
opacity:1.00;
filter: alpha(opacity=100);
/* For IE8 and earlier */
background: rgba(0, 0, 0, 1.0);
}
See this fiddle.
Related
Here is a link to a demo
I'm not sure what I'm missing, I've done this before a few times but It's been a day of fighting this particular CSS. I want the image to enlarge, but stay within the dimensions, so a zoom effect versus any enlargement. I've attempted to move the overflow:hidden into other parent or children, but it doesn't have an effect. I've played around with the display settings as well.
Any advice? The JSfiddle link is above, and the code below. Thanks for taking a look!
#purple-square {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/purple_card.png");
border-radius: 10px;
}
#migraine-dentistry {
width: 355px;
height: 255px;
background-image: url("../img/website_cards/migraine_dentistry_card.png");
border-radius: 10px;
}
/* need position: relative in shell otherwisee the elements disappear */
#shell {
margin: auto;
width: 355px;
height: 255px;
position: relative;
transform-origin: center;
transition: 0.3s ease-in-out;
}
#shell:hover {
transform: scale(1.2);
}
#container {
width: 100%;
overflow: hidden;
display: inline-block;
transition: 0.3s;
margin: 0 auto;
}
#container div {
position: absolute;
left: 0;
transition: 0.3s ease-in-out;
}
#container:hover {
transition: ease-in-out 0.3s;
}
#container div.bottom:hover {
opacity: 0;
}
and here is the HTML setup:
<body>
<div id="shell">
<div id="container">
<div id='purple-square' class="top"></div>
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
Full working code snipped below my steps
remove unnecessary elements Removed purple square, because it's never seen in wanted animation.
Removed the part the full #container div.bottom:hover part.
Removed every style that begins with #shell in the css and later trigger the animation on #container:hover.
main issue Add an #migraine-dentistry after the #container:hover animation, so if someone hovers the container it effects the #migraine-dentistry element. (#container:hover #mi.. {trans..})
In this (#container:hov..) element remove everything and
insert transform: scale(1.2);
because we just want to scale if user is hovering.
Remove whole #container div {..} style element, because we will directly add these styles to the #migraine-dentistry element.
In #container define px values for
> width: 355px; and height: 255px;
just because we not use the #shell element anymore. Also
> set position: relative; and z-index: 2;
that the #migrain.. element is inside his parent. And
> set border-radius: 15px;
for styling. Finally
>remove the display and transition values
because they are simply not needed.
last In #migraine-de.. styles
>set width: 100%; and height: 100%;
to fit div to parent.
> remove border-radius tag
because it's set by the #container
> add transition: 0.3s ease-in-out;
to transition like you wanted.
#container {
border-radius: 15px;
width: 355px;
height: 255px;
overflow: hidden;
z-index: 2;
position: relative;
}
#container:hover #migraine-dentistry {
transform: scale(1.2);
}
#migraine-dentistry {
width: 100%;
height: 100%;
transition: 0.3s ease-in-out;
background-image: url('https://images.unsplash.com/flagged/photo-1563248101-a975e9a18cc6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80');
}
<body>
<div id="shell">
<div id="container">
<div id='migraine-dentistry' class="bottom"></div>
</div>
</div>
</body>
I know these long nights where you just can't get it done.
Hi i need help with some css/html
i want to hover over an image and then another image/text appears with the background image becoming opacity :0.5
<style>
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('images/men.png');
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity = 0);
background-image: url('images/men2.png');
align:bottom;
}
.your-hover:hover {
opacity: 0.5;
filter: alpha(opacity = 50);
}
</style>
<div class="your-img">
<div class="your-hover"></div>
</div>
this is the code i am using. men.png is the main image and the men2.png is the image that should appear when i hover over men.png.
but when i hover over men.png its opacity is 1 and the hovered image is 0.5
how do i make the background image 0.5 and the hovered image 1
As far as I know, there isn't a CSS only way to lower the opacity of the background image only. Also, the hover will have to be on the parent as the child cannot affect the parent's styling.
The tricky part is that if you lower the opacity of the parent, the child will also have its opacity lowered. To get around this, you can play with :after and applying a background: rgba() doing something like:
JS Fiddle
.your-img {
width: 344px;
/* your image width and height here */
height: 857px;
background-image: url('images/men.png');
position: relative;
}
.your-img:after {
content: '';
top: 0;
bottom: 0;
width: 100%;
display: inline-block;
background: rgba(0, 0, 0, 0);
position: absolute;
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity=0);
background-image: url('images/men2.png');
align: bottom;
display: none;
}
.your-img:hover::after {
background: rgba(0, 0, 0, .5);
}
.your-img:hover .your-hover {
display: block;
opacity: 1;
filter: alpha(opacity=50);
}
if i understand the question correctly, you want hovering on the outer div to show the inner?
you just need to add a css rule for outer:hover > inner
.your-img:hover > .your-hover {
opacity: 0.5;
filter: alpha(opacity = 50);
}
Example
Hello you can simplify your code a lot but just having this css. There is no need to create a separate hover div. When you apply the pseudo class :hover to the .your-img class all you need to do is set the opacity there and the new url to your other background image.
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('http://placehold.it/350x150');
}
.your-img:hover {
width: 341px;
height: 225px;
background-image: url('http://placehold.it/350x150');
opacity: 0.5;
Here is a fiddle to illustrate https://jsfiddle.net/gward90/25bcmmhb/
Your code has quite a few errors, particularly where the hover is. You need to have the hover on the parent. Also, in your code youu are trying to make the parent go to 0.5 opacity and the child to 1. This isn't possible, the child is inside the parent, and it will already be 0.5 opacity because the parent is, so you will never get it back to 1.
I have left 2 scripts for you to try below, the first is a modified version of yours which should get the hover working, but you will have issues with the opacity as i described above, the second is a modified html and style to give you an example of how it should be laid out.
Example
.your-img {
width: 344px; /* your image width and height here */
height: 857px;
background-image: url('images/men.png');
}
.your-img:hover .your-hover{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.your-hover {
width: 341px;
height: 225px;
opacity: 0;
filter: alpha(opacity = 0);
background-image: url('images/men2.png');
align:bottom;
}
</style>
<div class="your-img">
<div class="your-hover"></div>
</div>
<style>
.parent {
width: 344px; /* your image width and height here */
height: 857px;
position: relative;
background-image: url('images/men.png');
}
.parent:hover .img-1{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.parent:hover .img-2{
opacity: 0.5;
filter: alpha(opacity = 50);
}
.img-1 {
background-image: url('images/men.png');
position: absolute;
height: 100%;
width: 100%;
}
.img-2 {
background-image: url('images/men2.png');
position: absolute;
opacity: 0;
filter: alpha(opacity = 0);
width: 341px;
height: 225px;
bottom: 0;
}
</style>
<div class="parent">
<div class="img-1"></div>
<div class="img-2"></div>
</div>
I'm trying to display a panoramic image with a specific size and a hidden overflow to eventually enable user-induced panning (the code is not included below).
I'm adding the image this way:
<div class="pan">
<img src="http://lorempixel.com/image_output/sports-q-c-1920-480-7.jpg">
</div>
I am setting the image size parameters this way:
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid;
}
However, when I change the width, the height changes proportionally, and I don't have any overflow to hide. The image is 13632 × 2936.
This is the result I get from the code above:
When setting the size this way, I get the image below:
.pan {
width: 400px;
height: 400px;
overflow: hidden;
border: red solid;
}
Trying to override img parameters set to 100% (for other purposes), I get a distorted image--still no hidden overflow:
.pan img {
height: 800px;
width: 400px;
transition: opacity .6s linear .8s;
}
Other code related to .pan and a container (from tutorial cited below) :
.pan img{
transition: opacity .6s linear .8s;
}
.pan img.loaded{ opacity: 1; }
.img-pan-container, .img-pan-container img{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
.img-pan-container{
position: relative;
overflow: hidden;
cursor: crosshair;
height: 100%;
width: 100%;
}
.img-pan-container img{
-webkit-transform: translateZ(0); -ms-transform: translateZ(0); transform: translateZ(0);
position: absolute;
top: 0;
left: 0;
}
For info, I am trying to implement this example. However, I am not currently focusing my question on the rest of the panning code, as I am having issues just getting the image sized correctly with the hidden overflow.
The img child has to be larger than the parent .pan, see snippet below with an image of 1920px width and 480px height. But this will crop parts of the image.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block /* fix inline gap */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE
Based on your updated question, it is most likely you have in your css img set as max-width:100%, see the same snippet above with that property set.
Snippet
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display:block; /* fix inline gap */
max-width:100% /* YOUR ISSUE */
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
UPDATE OP's Comment:
This may be the case...How can I override img for only this class?
If you can't find the origin and/or want to keep the max-width:100% for other imgs you can override by using max-width:none on .pan > img
.pan {
width: 800px;
height: 400px;
overflow: hidden;
border: red solid /* demo */
}
img {
display: block; /* fix inline gap */
max-width: 100% /* YOUR ISSUE */
}
.pan > img {
max-width: none
}
<div class="pan">
<img src="http://lorempixel.com/1920/480/" />
</div>
You can try to archive cover effect for image using this css:
.pan {
...
position: relative;
}
img {
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
transform: translate(-50%, -50%);
}
JSFiddle here
In a Rails 3.2 app I am displaying user avatars using a responsive, flippable CSS circle. But due to padding needed on a parent element, the avatar is not centered in the circle.
How can I center this circle? Where possible, I would prefer to keep this semantically marked up with an img tag, rather than as a background image on a div.
Also, can this be optimized? I've a lot of nested divs at present!
The code is below, and a jsfiddle here.
<div class='responsive-container'>
<div class='responsive-inner'>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flip-inner">
<div class="front">
<div class="circle">
<div class="circle-inner">
<%= image_tag #user.avatar %>
</div>
</div>
</div>
<div class="back">
<div class="circle">
<div class="circle-inner">
<%= #user.name %>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
.responsive-container{
position: relative;
width: 50%;
}
.responsive-container:before{
content: "";
display: block;
padding-top: 100%;
}
.responsive-inner{
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.flip-container {
perspective: 1000;
-webkit-perspective: 1000; /* Safari and Chrome */
}
/* flip the pane when hovered */
.flip-container:hover .flip-inner, .flip-container.hover .flip-inner {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.flip-inner {
transition: 0.6s;
-webkit-transition: 0.6s; /* Safari */
transform-style: preserve-3d;
-webkit-transform-style: preserve-3d; /* Safari and Chrome */
position: relative;
}
.front, .back {
backface-visibility: hidden;
-webkit-backface-visibility:hidden; /* Chrome and Safari */
-moz-backface-visibility:hidden; /* Firefox */
-ms-backface-visibility:hidden; /* Internet Explorer */
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.front {
z-index: 2;
}
.back {
transform: rotateY(180deg);
-ms-transform:rotateY(180deg); /* IE 9 */
-webkit-transform:rotateY(180deg); /* Safari and Chrome */
}
.circle {
width: 100%;
height: 0;
padding: 50% 0; //padding top & bottom must equal width
border-radius: 50%;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
overflow: hidden;
border: 1px #000 solid;
}
.circle-inner {
display: table;
width:100%;
}
.circle-inner img {
height: auto;
width: 100%;
}
.circle-inner p {
display: table-cell;
vertical-align: middle;
text-align: center;
}
</style>
why dont you use border-radius instead of circle? will be much easier i think.
http://bavotasan.com/2011/circular-images-with-css3/
Trying to experiment with a responsive design. But using a bad resolution screen isn't helping. On my main screen it looks fine, they are all in line and if I shrink the browser the elements shrink into the min and max size.
On my main screen (1366 x 768) the segment looks like this:
However on another resolution (1280 x 720) it distorts:
Here is my CSS:
//Thumbnails
#menu {
text-align: center;
}
.fader {
/* Giving equal sizes to each element */
//width: 250px;
//height: 375px;
//width: 33%;
//height: 55%;
max-width: 250px;
max-height: 375px;
min-width: 125px;
min-height: 188px;
/* Positioning elements in lines */
display: inline-block;
/* This is necessary for position:absolute to work as desired */
position: relative;
/* Preventing zoomed images to grow outside their elements */
overflow: hidden; }
.fader img {
/* Stretching the images to fill whole elements */
width: 100%;
height: 100%;
/* Preventing blank space below the image */
line-height: 0;
/* A one-second transition was to disturbing for me */
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-ms-transition: all 0.3s ease;
transition: all 0.3s ease; }
.fader img:hover {
/* Making images appear bigger and transparent on mouseover */
opacity: 0.5;
width: 120%;
height: 120%; }
.fader .text {
/* Placing text behind images */
z-index: -10;
/* Positioning text top-left conrner in the middle of elements */
position: absolute;
top: 50%;
left: 50%; }
.fader .text p {
/* Positioning text contents 50% left and top relative
to text container's top left corner */
margin-top: -50%;
margin-left: -50%;
}
I am trying to make it so that no matter what resolution the third image doesn't drop down to another line. It should just shrink
Thank you for reading.
Try This:
HTML
<body>
<div class="wrapper">
<div class="first">
<img src="img/CourseExample1.png">
</div>
<div class="second">
<img src="img/CourseExample2.png">
</div>
<div class="third">
<img src="img/CourseExample3.png">
</div>
</div>
</body>
CSS
body{
margin: 0;
padding: 0;
}
.wrapper{
margin:0px auto;
width: 100%;
}
.first{
width:33%;
float: left;
}
.second{
width:33%;
float:left;
}
.third{
width:33%;
float:left
}
.wrapper img{
width:95%;
}