Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26647

How can I use CSS sprites?

I'm trying to use CSS sprites but the second element doesn't come out right. I don't understand what I'm doing wrong. I try to set the top property to -45 which should give me the yahoo graphics but it comes out blank. What is wrong?

enter image description here

Mockup

enter image description here

CSS

#googlelink {
    width: 102px;
    height: 44px;
    background: url(/_/img/openidlogos.png) 0 0;
}

#yahoolink {
    width: 102px;
    height: 44px;
    background: url(/_/img/openidlogos.png) 0 -45;
}

If I use the above code then the google link renders ok but the next doesn't where I try to offset to area that should be drawn.

enter image description here

<!DOCTYPE html>
<html dir="ltr" lang="en-IN" class="js">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="description"
          content="Find free ads about all different kind of items for sale in {% if regionname and regionname != 'None' %}{{regionname}}{% else %}{% if cityname and cityname != 'None' %}{{cityname}}{% else %}{% if country and country != 'None' %}{{country}}{% endif %}{% endif %}{% endif %}">
    <meta name="googlebot" content="noarchive">
    {% if cursor %}
    <link rel="next" href="/delhi/?o=2">
    {% endif %}
    <link rel="canonical" href="/q">

    <title></title>
    <!-- CSS INCLUDES: -->

    <link href="/static/css/koolindex_in.css?{{VERSION}}" rel="stylesheet" type="text/css">

    <link href="/static/css/common_in2.css?{{VERSION}}" rel="stylesheet" type="text/css">
    <!-- HEADEXTRAS: -->

    <link rel="icon" href="/img/favicon_in.ico?07217" type="image/x-icon">
    <!--
        <link rel="shortcut icon" href="/img/favicon_in.ico?07217" type="image/x-icon">
        <link rel="shortcut icon" href="/img/favicon_in.png?07217" type="image/png">
        <link rel="apple-touch-icon" href="/img/favicon_ios_in.png?07217" type="image/png">
        <link rel="icon" href="/img/favicon_us.ico?51340" type="image/x-icon">
            <link href="https://plus.google.com/123122342342345" rel="publisher">-->

    <!-- JAVASCRIPTS: -->
    <script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="/static/js/common.min.js"></script>
    <script type="text/javascript" src="/static/js/arrays_v2.js"></script>
    <script type="text/javascript" src="/static/js/searchbox.min.js"></script>

    <script type="text/javascript"><!--

    function cities(obj) {


        if (obj.value == '3') {

            //undisplay cities options municipality_control2

            document.getElementById('municipality_control').style.display = 'none'

        } else {

            $('#cities').load('/cities?regionId=' + obj.value);

        }

        document.getElementById("citiess").className = "selectbox munics ";

    }

$(function() {
  $("#searchtext").focus();
});
    //-->
    </script>
</head>
<body>
{% include "kooltopbar.html" %}


<div id="wrapper">
 {% if request.host == "www.koolbusiness.com"  %}

    <h1 id="logo" class="sprite_index_in_in_en_logo spritetext">koolbusiness.com - The right choice for buying &amp;
        selling in india</h1>
{% endif %}


    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <!-- v2 -->
    <ins class="adsbygoogle"
         style="display:inline-block;width:728px;height:15px"
         data-ad-client="ca-pub-7211665888260307"
         data-ad-slot="9119838994"></ins>
    <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
    </script>

    <div id="border1"></div>

<section id="searchbox">

     <form id="search_form" action="." method="post">
<table><tr><td>
LOG IN</td><td>
         <input placeholder="YOUR E-MAIL OR USERNAME" name="email" size="20" id="searchtext" title="email" class="placeholder" type="text"
           value="{{query}}"></td><td> <input placeholder="YOUR PASSWORD" name="email" size="20" id="searchtext" title="email" class="placeholder" type="text"
           value="{{query}}">
</td><td>
    <input id="searchbutton" value="Login" class="button" type="submit"></td>
</tr>

    <tr><td>
    </td><td>YOUR E-MAIL</td><td> PASSWORD</td><td>

    </tr>
    <tr><td>
CREATE ACCOUNT
    </td><td><input placeholder="YOUR E-MAIL OR USERNAME" name="email" size="20" id="searchtext" title="email" class="placeholder" type="text"
           value="{{query}}"></td><td> <input placeholder="YOUR PASSWORD" name="email" size="20" id="searchtext" title="email" class="placeholder" type="text"
           value="{{query}}">
</td><td>
    <input id="searchbutton" value="Login" class="button" type="submit"></td>
</tr> <tr><td>
    </td><td>YOUR E-MAIL</td><td>DESIRED PASSWORD</td><td>

    </tr> <tr><td>
    OR LOG IN WITH </td><td><img id="googlelink"> </td><td><img id="yahoolink">  facebook</td><td></td></tr>

</table>

</form>


</section>



</div>


</body>
</html>

Upvotes: 0

Views: 76

Answers (2)

Nilesh Mahajan
Nilesh Mahajan

Reputation: 3516

You miss out giving units to the value, your code should look like following css rule

yahoolink {

width: 102px;
height: 44px;
background: url(/_/img/openidlogos.png) 0 -45px;

}

Your CSS code is working for google is because, when in general writing CSS rules if you are giving values in 0 you dont need to mention unit to those. but if you are putting numbers rather than 0, then you must mention units to those.

Upvotes: 1

Lu&#237;s P. A.
Lu&#237;s P. A.

Reputation: 9739

Your CSS should be like this:

#yahoolink {
    width: 102px;
    height: 44px;
    background: url(/_/img/openidlogos.png) no-repeat 0 -45px;
}

Note: give a unit measure..in this case is (px) and set no-repeat.

Upvotes: 3

Related Questions