0

As you can see on this jsfiddle http://jsfiddle.net/L9k5c/ my "Hello" text is positionned outside of my red circle instead of centered in it (this is issue 1). Issue 2 is that this "Hello" text makes the "onmouse over" circle not aligned with the red circle anymore. How could I fix these 2 issues? (for issue 1 I know that I could play with padding and margins but I guess that this would not a clean solution + it would not fix issue 2. Many thanks

<div class="ch-item ch-img-1"><p>hello</p>
    <div class="ch-info">
        <h3>Use what you have</h3>
        <p>by Angela</p>
    </div>
</div>

CSS:

.ch-item {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    position: relative;
    cursor: default;
    box-shadow: 
        inset 0 0 0 16px rgba(255,255,255,0.6),
        0 1px 2px rgba(0,0,0,0.1);

    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;
}

.ch-img-1 { 
    background: red;
}

.ch-info {
    position: absolute;
    background: rgba(63,147,147, 0.8);
    width: inherit;
    height: inherit;
    border-radius: 50%;
    opacity: 0;

    -webkit-transition: all 0.4s ease-in-out;
    -moz-transition: all 0.4s ease-in-out;
    -o-transition: all 0.4s ease-in-out;
    -ms-transition: all 0.4s ease-in-out;
    transition: all 0.4s ease-in-out;

    -webkit-transform: scale(0);
    -moz-transform: scale(0);
    -o-transform: scale(0);
    -ms-transform: scale(0);
    transform: scale(0);

    -webkit-backface-visibility: hidden;

}

.ch-info h3 {
    color: #fff;
    font-size: 18px;
    margin: 0 30px;
    padding: 45px 0 0 0;
    height: 100px;
    font-family: 'Open Sans', Arial, sans-serif;
}

.ch-info p {
    color: #fff;
    font-style: italic;
    padding-left:80px;
    font-size: 12px;
    border-top: 1px solid rgba(255,255,255,0.5);
    opacity: 0;
    -webkit-transition: all 1s ease-in-out 0.4s;
    -moz-transition: all 1s ease-in-out 0.4s;
    -o-transition: all 1s ease-in-out 0.4s;
    -ms-transition: all 1s ease-in-out 0.4s;
    transition: all 1s ease-in-out 0.4s;
}


.ch-item:hover {
    box-shadow: 
        inset 0 0 0 1px rgba(255,255,255,0.1),
        0 1px 2px rgba(0,0,0,0.1);
}
.ch-item:hover .ch-info {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -o-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
    opacity: 1;
}

.ch-item:hover .ch-info p {
    opacity: 1;
}
4

2 回答 2

2

您可以使用absolute positionandtransform轻松实现您想要的。

jsFiddle 演示

.ch-item p {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    margin: 0;
}
  • PS - Usingtransform不适用于 IE 8 及更低版本,但您已经在其他地方使用它,所以我想没关系。
于 2013-09-07T12:21:48.830 回答
1

这是更新的小提琴

正如您position:relative;在包装器中使用的那样,您可以使用position:absolute;它的内部内容来定位它

.ch-item p{
position:absolute;
top:35%;
left:40%;
}

还可以opacity:0在悬停时为您的问候文字制作..因为在您的示例中,您的问候文字在悬停后仍然可见

.ch-item:hover p{
opacity:0;
}

第二次修改小提琴

于 2013-09-07T12:25:32.033 回答