0

I've been trying to achieve the effect of mouse over on a picture which dims its background and brings over a text on top.

Then I wanted a nice centralized text when I moused over.

These both things were achieved, but then I ran into a small problems.

  • How can I centralized the text without specifying width and height of the picture (to enable responsive design)

The Problem is that If I specify the width/Height, it would show the text perfectly centered, but when I change the page dimensions, it loses the center point.

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;}

Thanks.

Steve
  • 2,546
  • 8
  • 49
  • 94
  • Nice code, I hope you realize that it won't stop people from being able to copy the image without the text. – lewisjb Jul 29 '13 at 02:07
  • your image doesn't appear. possible duplicate of this one.. http://stackoverflow.com/questions/489340/how-do-i-vertically-align-text-next-to-an-image-with-css – bot Jul 29 '13 at 02:31

0 Answers0