Text Overlay on Image Hover - Responsive

寵の児 提交于 2020-01-06 12:44:28

问题


I am using this tutorial to create an overlay on my images with text:

http://codepen.io/pdelsignore/pen/uqenH

It works great, however I have a responsive website and if I try to enter a % as the width / height of the '.box' the image disappears. It appears it can only be a fixed with (i.e. px) which obviously doesn't scale.

.box {  
cursor: pointer;  
height: 250px;   
position: relative;  
overflow: hidden;  
width: 400px;
font-family: 'Open Sans', sans-serif;
}  

Does anyone have any ideas? Thanks in advance!


回答1:


Try giving min-width and min-height a try.

min-width: 100%;
min-height: 100%;



回答2:


In live project usually we use any responsive framework. Like bootstrap or foundation. So I think you could ignore as framework will handle this properly. No need to use any % to make it responsive. For Bootstrap we use

 <div class="row">
    <div class="col-md-4">
        <div class="box">  
            <img src="http://files.room1design.com/oldcity.jpg"/>  
            <div class="overbox">
                <div class="title overtext">
                    Walk This Way
                </div>
                <div class="tagline overtext">
                    Follow the path of stone, a road towards an ancient past
                </div>
            </div>
        </div>  <!-- End box -->
    </div>  <!-- End Col-4 -->
 </div>  <!-- End row -->



回答3:


I believe the dimensions of .box as a percentage would be based on the height of the parent. since no height is specified on the body it has no frame of reference. try adding the following to get percentages working on .box.

html, body {
    height:100%;
}

here is an updated codepen with a few other changes to illustrate the use of percentages after giving your body dimension.

http://codepen.io/anon/pen/dPREBE



来源:https://stackoverflow.com/questions/28162888/text-overlay-on-image-hover-responsive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!