I have a CSS question with this image hover effect - "Fiddle". I can't use width 100% in .img-overlay to get the overlay to cover the whole areas of the two pictures, so I have to use width:138px for the first one and width:300px for the second. In doing so, I end up making 4 more classes (.img-overlay2 .img-overlay2.2 .img-overlay2 h4 .img-overlay2 p, .img-wrap:hover .img-overlay2) Is there a more concise way to achieve that? Can I avoid some of the duplication?
CSS
.img-wrap{
overflow:hidden;
position:relative;
}
.img-overlay{
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity = 0);
position:absolute;
width:138px;
height:100%;
z-index:1000;
}
.img-overlay h4, .img-overlay p{
padding:0 10px;
}
.img-wrap:hover .img-overlay{
opacity:0.75;
filter: alpha(opacity = 75);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}
.img-overlay2{
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity = 0);
position:absolute;
width:300px;
height:100%;
z-index:1000;
}
.img-overlay2.2{
width:100%;
}
.img-overlay2 h4, .img-overlay2 p{
padding:0 10px;
}
.img-wrap:hover .img-overlay2{
opacity:0.75;
filter: alpha(opacity = 75);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}
You can try to use something like this http://jsfiddle.net/EyAdp/
HTML:
<div class="a image"><div class="overlay"></div></div>
<div class="b image"><div class="overlay"></div></div>
CSS:
.a {
width:150px;
height:60px;
background-image:url("http://placekitten.com/150/60");
}
.b {
width:100px;
height:50px;
background-image:url("http://placekitten.com/100/50");
}
.image {
position:relative;
}
.overlay {
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
}
.overlay:hover {
background-color:rgba(1,1,1,0.3);
}
yes... you can avoid the duplications easily. see the following approach:
.img-wrap{
overflow:hidden;
position:relative;
}
.img-overlay{
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity = 0);
position:absolute;
height:100%;
z-index:1000;
}
.img-overlay h4, .img-overlay p{
padding:0 10px;
}
.img-wrap:hover .img-overlay{
opacity:0.75;
filter: alpha(opacity = 75);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}
.img-overlay138{
width:138px;
}
.img-overlay300{
width:300px;
}
and you html:
<div class="img-wrap">
<a href='#'><img src='http://wizzywizzyweb.gmgcdn.com/media/products/payday-2-4-pack/boxart/small-payday-2-4-pack_boxart_tall-136x159.jpg' alt="bbh"/></a><div
class="img-overlay img-overlay138">
<p>dfdfdf</div></div>
<div class="img-wrap">
<a href='#'><img src='http://wizzywizzyweb.gmgcdn.com/media/smallofferboxes/2013/09/13/Voucher-Low-offer-box04_.jpg' alt="ddfdf"/></a><div
class="img-overlay img-overlay300">
<p>dfdfdf
</div></div>
If you need to keep the class names - without changing your markup or CSS much, you can reduce the duplication by defining common attributes once, then overriding specific attributes later in your stylesheet:
Demo Fiddle
.img-overlay,
.img-overlay2 {
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity=0);
position:absolute;
width:138px;
height:100%;
z-index:1000;
}
.img-overlay2 {
width:300px;
}
.img-overlay h4, .img-overlay p,
.img-overlay2 h4, .img-overlay2 p {
padding:0 10px;
}
.img-wrap:hover .img-overlay,
.img-wrap:hover .img-overlay2 {
opacity:0.75;
filter: alpha(opacity=75);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}
By adding two additional class definitions and adding them to your overlay elements while removing references to img-overlay2:
Demo Fiddle
HTML:
<div class="img-overlay small">...
<div class="img-overlay large">...
CSS:
.img-wrap {
overflow:hidden;
position:relative;
}
.img-overlay {
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity=0);
position:absolute;
width:138px;
height:100%;
z-index:1000;
}
.img-overlay.small {
width: 138px;
height: 159px;
}
.img-overlay.large {
width: 300px;
height: 120px;
}
.img-overlay h4, .img-overlay p {
padding:0 10px;
}
.img-wrap:hover .img-overlay {
opacity:0.75;
filter: alpha(opacity=75);
transition:opacity 0.25s;
-moz-transition:opacity 0.25s;
-webkit-transition:opacity 0.25s;
}
If you can apply dimensions on your img-wrap element, you could change to something like this:
Demo Fiddle
HTML:
<div class="img-wrap small">…</div>
<div class="img-wrap large">…</div>
CSS:
.img-wrap {
overflow:hidden;
position:relative;
}
.img-wrap.small {
width: 138px;
height: 159px;
}
.img-wrap.large {
width: 300px;
height: 120px;
}
.img-overlay {
background-color:#8DBDD8;
bottom:0;
color:#222;
opacity:0;
filter: alpha(opacity=0);
position:absolute;
width:100%;
height:100%;
z-index:1000;
}
Related
I'm trying to build a Team section on a Website. I have a Div with an Image and Name of the Person. When I hover over the name, I would like to have a link to appear on its place and move the Name upwards.
Something like this (TEAM Section):
https://www.templatemonster.com/de/demo/55809.html
I tried using a solution I found here and modifying it, but it doesnt really work like I want it to:
#stuff {
position: absolute;
top: 100px;
opacity: 0.0;
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
-ms-transition: all 500ms ease-in-out;
-o-transition: all 500ms ease-in-out;
transition: all 500ms ease-in-out;
}
#hover {
width:80px;
height:20px;
background-color:green;
margin-top: 50px;
margin-bottom:15px;
}
#hover:hover {
margin-top:25px;
margin-bottom: 25px;
opacity: 1.0;
}
#stuff:hover {
opacity: 1.0;
}
<link rel="stylesheet" type="text/css" href="main.css">
<section>
<div id="hover">Hover</div>
<div id="stuff">stuff</div>
Is there a simple solution with CSS and/or Bootstrap?
I made an example using just css.
section {
margin:5px auto;
}
.hover-div {
color:#FFF;
width:200px;
}
.hover-div .stuff {
background-color:#F00;
height:100px;
margin-top:0;
position:relative;
width:100%;
z-index:2;
-webkit-transition:margin-top 0.3s;
transition:margin-top 0.3s;
}
.hover-div .stuff-hidden {
background-color:#00F;
height:0;
width:100%;
-webkit-transition:height 0.3s;
transition:height 0.3s;
}
.hover-div:hover .stuff {
margin-top:-40px;
}
.hover-div:hover .stuff-hidden {
height:40px;
}
.image {
background-color:#0F0;
height:100px;
text-align:center;
width:100%;
}
<section>
<div class="image">image</div>
<div class="hover-div">
<div class="stuff">Stuff</div>
<div class="stuff-hidden">Hidden stuff</div>
</div>
</section>
I'm working on this project here:
https://codepen.io/WHITE-RABBIT/pen/aMzLWy
I've got pretty much everything in place, but when I use zoom to check that my elements stay in place, I find that all of my content shifts downward. The widths pretty much remain the same, but the headers seem to cause some space and also for the life of me I cannot get my links container to not change size. I know there is probably a fairly simple solution for this, but I have been wracking my brain for hours and I just cannot think of what I did wrong here.
I will split this into sections.
Header:
/**HEADER SECTION**/
.header
{
width:100%;
height:5vmin;
max-height:5vmin;
left:0vmin;
top:0vmin;
margin-top:0vmin;
position:relative;
pointer-events:auto;
z-index:30;
background-color:RED;
}
.header h1
{
font-family:Barlow;
font-size:2vmin;
color:#9dc7ff;
font-weight:bold;
text-transform:uppercase;
letter-spacing:0.5vmin;
margin-top:1vmin;
position:relative;
display:inline-block;
background-color:GREEN;
}
.header u
{
text-decoration:none;
font-size:2vmin;
letter-spacing:0.1vmin;
font-weight:100;
font-style:italic;
font-family:'Black Han Sans', sans-serif;
color:#ff6ade;
}
.header-links
{
width:70%;
height:auto;
padding-top:0%;
margin-top:-3.5vmin;
margin-left:24.2vmin;
right:0%;
position:fixed;
float:right;
background-color:BLUE;
}
.header-links a
{
font-family:Roboto;
font-size:1.02vmin;
letter-spacing:0.2vmin;
width:auto;
height:auto;
position:relative;
padding-bottom:2vmin;
padding-top:0vmin;
color:WHITE;
margin-right:2vmin;
text-decoration:none;
text-transform:uppercase;
display:inline;
border-bottom:0vmin solid RGBA(255,255,255,0.0);
-webkit-transition: all 0.7s ease-in-out;
-moz-transition: all 0.7s ease-in-out;
-ms-transition: all 0.7s ease-in-out;
-o-transition: all 0.7s ease-in-out;
transition: all 0.7s ease-in-out;
}
.header-links a:hover
{
border-bottom:2px solid #2de3ff;
color:#ff2dce;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.header span
{
display:inline-block;
width: 0.5vmin;
max-width:0.5vmin;
max-height:0.5vmin;
height: 0.5vmin;
top:-0.1vmin;
margin-right:2vmin;
position:relative;
background-color:#2de3ff;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
Sider:
.sider
{
width:29%;
height:80vmin;
position:relative;
z-index:2;
margin-top:-7vmin;
pointer-events:auto;
background-color:TRANSPARENT;
}
.sider display
{
height:40%;
width:100%;
top:8vmin;
position:relative;
display:inline-block;
background-image:URL('https://i.imgur.com/KrGRmvE.gif');
background-size:cover;
background-position:center;
-webkit-border-radius: 20px 20px 0px 0px;
border-radius: 10% 10% 10% 10%;
}
.title
{
height:4vmin;
width:90%;
left:1vmin;
position:relative;
display:inline-block;
top:9vmin;
font-family:Barlow;
font-size:1.9vmin;
line-height:1.2vmin;
}
.sider desc
{
height:auto;
width:95%;
left:1vmin;
top:10vmin;
position:relative;
display:inline-block;
font-family:'Roboto Condensed', sans-serif;
font-size:1.3vmin;
font-weight:100;
line-height:1.5vmin;
opacity:0.8;
text-align:justify;
letter-spacing:0.03vmin;
}
.title icon
{
height:8vmin;
width:8vmin;
max-height:8vmin;
max-width:8vmin;
display:inline-block;
position:relative;
margin-top:-4vmin;
margin-right:1vmin;
left:0vmin;
float:left;
background-color:PURPLE;
background-image:URL('https://i.redd.it/glxbid0p79r11.jpg');
background-size:cover;
border:0.5vmin solid BLACK;
-webkit-border-radius: 50%px;
border-radius: 50%;
}
.buttons-container
{
height:auto;
width:100%;
margin-top:13vmin;
white-space:nowrap;
font-family:Roboto;
line-height:0vmin;
text-transform:uppercase;
}
.button
{
height:2.3vmin;
width:2.3vmin;
max-height:2.3vmin;
max-width:2.3vmin;
margin-right:1vmin;
display:inline-block;
background-image:URL('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217361/discord-icon-free-download-at-icons8-33230.png');
background-position:center;
background-repeat:no-repeat;
background-size:cover;
}
.button2
{
height:2.3vmin;
width:2.3vmin;
margin-right:1vmin;
display:inline-block;
background-image:URL('https://s3-us-west-2.amazonaws.com/s.cdpn.io/217361/kisspng-league-of-legends-computer-icons-riot-games-wall-decals-5b11738fe19235.371578411527870351924.png');
background-position:center;
background-repeat:no-repeat;
background-size:cover;
}
.buttons-container span
{
top:-0.8vmin;
margin-right:1vmin;
display:inline-block;
position:relative;
background-color:GREEN;
font-size:1vmin;
}
The HTML section can be seen on the pen. I'm not going to post it because I am 99% sure that it has nothing to do with my HTML.
I appreciate everyone's time. Hopefully I can find a solution to this soon. Thank you.
Your design isn't responsive, you're working with your screen size only but when the design is displayed in another screen everything will not be the same as it was in your screen
You can follow this guide to get better results
body{
margin:0;
padding:0;
background-color:#f1ff36;
font-family:verdana;
}
.center{
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
}
a{
position:relative;
text-decoration:none;
border:2px solid transparent;
width:100px;
height:50px;
text-align:center;
line-height:50px;
display:inline-block;
font-size:24px;
color:#262626;
}
a:before{
content:'';
position:absolute;
top:-2px;
left:-2px;
width:0;
height:0;
background:transparent;
border:2px solid transparent;
}
a:hover:before{
animation:animate 1s linear forwards;
}
#keyframes animate{
0%{
width:0;
height:0;
border-top-color:#262626;
border-right-color:transparent;
border-bottom-color:transparent;
border-left-color:transparent;
}
50%{
width:100%;
height:0;
border-top-color:#262626;
border-right-color:#262626;
border-bottom-color:transparent;
border-left-color:transparent;
}
100%{
width:100%;
height:100%;
border-top-color:#262626;
border-right-color:#262626;
border-bottom-color:transparent;
border-left-color:transparent;
}
}
a:hover:after{
animation:animate2 1s linear forwards;
animation-delay:1s;
}
#keyframes animate2{
0%{
width:0;
height:0;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:transparent;
border-left-color:#262626;
}
50%{
width:0;
height:100%;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:#262626;
border-left-color:#262626;
}
100%{
width:100%;
height:100%;
border-top-color:transparent;
border-right-color:transparent;
border-bottom-color:#262626;
border-left-color:#262626;
}
}
animate2 is not working at all tell me the error which is occuring in this code.
In this code as you can see there are two animations first animation is working fine but the second animation ie animate2 is not working at all. Tell me at which point I am making the mistake I am really confused and frustrated trying and trying to run this code but to no avail.
I think you forgot to add empty content block a:after
Take a look at this codepen
a:before, a:after {
I have a small link with a thumbnail and an excerpt, using css transitions I want the thumbnail to fade out on hover and the excerpt to appear. I'm using % in oppose to pixels as I want my website responsive, however when I add this to my site the excerpt is spread out the width of the page as it has absolute positioning, below is a jfiddle, could anyone help me?
.col {
width:29%;
margin:0 auto;
}
.post-thumbnail {
position:relative;
float:left;
overflow:auto;
width:100%; height:278px;
background:#2F3B45;
}
.post-thumbnail img {
width:100%; height:223px;
padding:0; margin:0;
transition:opacity 0.3s ease-in-out;
-moz-transition:opacity 0.3s ease-in-out;
-webkit-transition:opacity 0.3s ease-in-out;
-o-transition:opacity 0.3s ease-in-out;
}
.col:hover .post-thumbnail img {
opacity:0;
filter:alpha(opacity=00);
}
.post-excerpt {
width:100%;
z-index:9999;
opacity:1;
filter:alpha(opacity=1);
}
.post-excerpt p {
text-align:justify;
color:#a3aaac;
font-family:'Open Sans', helvetica, arial, sans-serif;
font-size:9pt; font-weight:200;
line-height:18pt;
text-decoration:none; width:100%;
}
.col:hover .post-excerpt {
opacity:1;
filter:alpha(opacity=1);
}
.post-title {
position:absolute;
bottom:0px; left:0px;
width:100%; height:55px;
background:#ff0000; z-index:9999;
text-align:center; line-height:52px;
}
.post-title a {
font-family:'Open Sans', helvetica, arial, sans-serif;
font-size:10pt; font-weight:200;
color:#000; text-decoration:none;
}
.post-more {
position:absolute;
bottom:0px; left:0px;
width:100%; height:0px;
background:#ff0000;
opacity:0.0;
filter:alpha(opacity=00);
}
.col:hover .post-title {
cursor:pointer;
position:absolute;
bottom:0px; left:0px;
width:100%; height:95px;
background:#ff0000; line-height:44px;
}
.col:hover .post-more {
cursor:pointer;
position:absolute;
bottom:0px; left:0px;
width:100%; height:47px;
background:#fff url(http://liamhodnett.com/img/new/read-entry.png)top left no-repeat;
z-index:99999;
}
http://jsfiddle.net/P3k9A/
Thanks guys!
Set the parent to relative, then set the children to absolute.
Here are the ones I changed:
.col {
width:29%;
margin:0 auto;
position:relative; /* <- here */
}
.post-thumbnail {
position:absolute; /* <- here */
top: 0px;
float:left;
overflow:auto;
width:100%; height:278px;
background:#2F3B45;
}
.post-excerpt {
position: absolute; /* <- here */
width:100%;
z-index:9999;
opacity:0;
filter:alpha(opacity=0);
}
I believe this is what you were after: http://jsfiddle.net/P3k9A/1/
(I also changed the opacity to 0 on the excerpt in the fiddle).
i have an image in my website that when i mouse over it this goes left 105px:
.view img {
position: absolute;
z-index: 0;
transition:left 0.5s;
-webkit-transition:left 0.5s;
}
.view:hover img{
left: -105px;
}
i want to divide this "view" into 2 segments horizontally that every segment works different ,when mouse over one segment of the image then image goes left in 105px and another segment do it in another direction (right).i means writing something like this:
.view img {
position: absolute;
z-index: 0;
transition:left 0.5s;
-webkit-transition:left 0.5s;
}
.view:hover 25% right img{
left: -105px;
}
.view:hover 25% left img{
right: 105px;
}
how can i do this?
you can use :before and :after from css3
markup:
<div>hallo JAPAN</div>
style:
div{
position:relative;
width:100px;
height:80px;
background-color:#ccc;
margin:100px auto;
}
div:before,div:after{
content:'';
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
opacity:0;
-webkit-transition: all 300ms ease-in-out;
-moz-transition: all 300ms ease-in-out;
transition: all 300ms ease-in-out;
}
div:before{
background-color:red;
background-image:url(http://www.marcwitteveen.com/wp-content/uploads/2013/01/apple-logo.png);
background-repeat:no-repeat;
background-position:center;
}
div:after{
background-color:red;
background-image:url(http://mywindows8themes.com/wp-content/uploads/2011/11/windows_8_metro_logo.png);
background-repeat:no-repeat;
background-position:center;
}
div:hover:before{
left:-100%;
}
div:hover:after{
left:100%;
}
div:hover:before,div:hover:after{
opacity:1;
}
like this http://jsfiddle.net/nXdMn/