鼠标悬停在图像上的集中文本

时间:2013-07-29 02:03:56

标签: css background

我一直在尝试将鼠标悬停在一张照片上,这张照片会使背景变暗并将文字带到最上面。

然后我想要一个很好的集中文本,当我被遗弃时。

这两件事都实现了,但后来遇到了一些小问题。

  • 如何在不指定图片宽度和高度的情况下集中文本(以启用响应式设计)

问题是,如果我指定宽度/高度,它会显示完全居中的文本,但是当我更改页面尺寸时,它会失去中心点。

HTML

<div id="bottomWide">            
    <ul>
       <li class="first">
            <img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt=""> 
            <div class="all-canvas">
                <div class="all-text">
                    <span class="title">A Heading</span><br>
                    <span class="text">Couples of Lines of Text will come here</span><br>
                    <span class="shop">See Details.</span>
                </div>
            </div>
        </li>
        <li class="second">
            <img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="">
                 <div class="all-canvas">
                <div class="all-text">
                    Some text here, style as needed
                </div>
            </div>
        </li>

    </ul> 
</div>

CSS

#bottomWide{
    width:100%;
    margin:0 auto;


}

#bottomWide ul{
    margin:0;
    padding:0;

}
#bottomWide li{
  list-style-type: none;
  display: inline-block;
    width:50%;
    text-align:justify;
    float: left;


     /* For Mouse Over*/
    position: relative;
    display: inline-block;
}
#bottomWide li:last-child img { 
   border-left: 4px solid #fff;
}
#bottomWide img{
    width:100%;
}



#bottomWide li div.all-canvas{
    position: absolute;
    top: 0;
    left: 0;
    /* 100% will equal the dimensions of the image, as nothing else will be inside the .container */
    width: 100%;
    height: 100%;
    color: #fff;
    background-color: #000;
    opacity: 0;
    /* This will create the fade effect */
    transition: opacity 0.3s;
    -webkit-transition: opacity 0.3s;
    /* Include all required vendor prefixes for opacity and transition */

    margin: 0 auto;
}
#bottomWide li:last-child div.all-canvas {
    margin-left: 4px;
}



#bottomWide li div.all-canvas:hover {
    opacity: 0.7;
}

#bottomWide li:last-child div.all-canvas:hover {
    opacity: 0.7;
    margin-left: 4px;
}

div.all-text {
    height:358px; /* This is what I want to change to %*/
    width: 623px; /* This is what I want to change to %*/ 
    text-align:center;
    border:1px solid silver;
    display: table-cell; 
    vertical-align:middle;
    margin: 0 auto; 
}

div.all-text span.title { padding: 3px; font: 18px/1.35 "Open Sans", Helvetica, sans-serif; text-transform: uppercase;}

感谢。

0 个答案:

没有答案