Jump to content

Recommended Posts

ive been researching how to provide a background image to a div and have it be responsive in size.  as the browser window narrows, i would like the image to get smaller.  the image used is a sprite so that upon hover, you see a different version of the original image.  it works great except that at varying browser widths, the hover event causes a slight dislocation of the hover image.  you can see what i mean at the link below.  at full-width, it seems to work great in all browsers.  as the browser shrinks, the hover event at times causes glitches.  anyone have thoughts on whats going on here or a better way to tackle the responsive sprite problem?

 

url: http://buildmyweb.org/new/

 

 

html:

<div id='hexagon_container'>
    <a href='' class="services_hexagon"></a>
    <a href='' class="services_hexagon"></a>
    <a href='' class="services_hexagon"></a>
    <a href='' class="services_hexagon"></a>
</div>

css:

#hexagon_container                { float:left; width:100%; background:#feb914; }
.services_hexagon                 { float:left; display:block; width:15%; height:0; padding-bottom:13%; margin-right:13.33%; text-indent:-3000px; background:url('pics/octagons/oct_gd.png') center top; background-size:cover; }
.services_hexagon:last-of-type    { margin-right:0px; }
.services_hexagon:hover           { background-position:center bottom; }
Edited by BuildMyWeb
Link to comment
https://forums.phpfreaks.com/topic/295015-responsive-background-images-for-div/
Share on other sites

  • 1 month later...

"last-of-type " should be applied on <p>.

 

This give you some idea:

#hexagon_container {
    float:left;
    width:100%;
    background:#feb914;
}
.services_hexagon {
    float:left;
    display:block;
    width:100%;
    height:100%;
    padding-bottom:13%;
    margin-right:13.33%;
    text-indent:-3000px;
    background:url('pics/octagons/oct_gd.png') center top;
    background-size:cover;
}
.services_hexagon:last-of-type {
    margin-right:0px;
}
.services_hexagon:hover {
    background-position:center bottom;
    background-color: yellow;
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.