C. Felipe C. Felipe - 1 year ago 91
CSS Question

CSS Transition and div inside another div behaves crazy

I have two problems with my portfolio section which is not as smooth as I want it to be. Here they are:

  1. 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/

  2. 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:


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!

Answer Source

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="...">

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)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download