css和sprites - 出乎意料的结果

时间:2012-01-29 08:50:23

标签: css sprite

我在这里做错了什么?我无法让精灵正常工作。当我检查元素时,它不是正确的高度或宽度。我已经让sprite工作了一个带有背景图像的容器div,但我不认为在这种情况下有一个包装器是正确的。

这是我正在尝试做的事情..

<html>
<style>
.bottomtable{display:block;}
.bottomtable .close {float: right;margin-right:5px;margin-top:25px;display:inline;position:relative;background-image:url('http://www.freeimagehosting.net/o2gz4');background-position:-278px -18px;height:7px;width:7px;}
.bottomtable .close a {height:7px;width:7px;}
.bottomtable .titletext{text-align: right;float: right;margin-right:5px;margin-top:-20px;display:block;}
.bottomtable h5{margin:0;padding:0;font-size: 14px;font-weight:normal;display: inline;}
.bottomtable ul {display:block;padding:5px;margin:0;}
.bottomtable li {list-style-type:none;padding:10px;margin:0;height:75px;display:block;}
.bottomtable li a{text-decoration:underline;font-weight:bold;display:block;margin-bottom:5px;}
.bottomtable li a span{display:block;text-decoration:underline;font-weight:bold;margin:2px 0 4px;}
.bottomtable ul img {display:inline;float:left;margin-top:-2px;margin-right:20px;}
</style>
<body>
<div class="bottomtable">
<ul>
    <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>                        </li>
    <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>
    <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>
    <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>

</ul>
</div>
</style>
</html>

`

你只能看到X的一小部分。

如果我没有在链接之间放置那个空白区域,它根本没有显示任何内容......必须有一些我只是做错了。它是什么?我检查了网站的大小,他们似乎并不需要那个空间。

2 个答案:

答案 0 :(得分:0)

这是一个工作示例(包含您的代码)http://jsfiddle.net/vFLRe/26/

<html> 
<style> 
.bottomtable .close {float:right;margin-right:5px;margin-top:25px;background-image:url('http://www.freeimagehosting.net/o2gz4');background-position:-278px -18px;height:25px;width:25px;display:block;border:1px solid black;} 
.bottomtable .close a {height:25px;width:25px;} 
</style> 
<body> 
<div class="bottomtable"> 
<ul> 
    <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title=""></a>this is some text here..............<div style="clear: right;"></div>                        </li>  
</ul> 
    </div> 
    </body>
</html> 

答案 1 :(得分:0)

这件事有效。请检查:

<html>
   <style>
     .bottomtable{display:block;}
     .bottomtable .close {background-image:url("http://www.freeimagehosting.net/newuploads/o2gz4.png");background-position: -278px -18px;color: #FFFFFF;display: inline;float: right;height: 10px;margin-right: 5px; margin-top: 10px;position: relative;width: 11px;}
     .bottomtable .close a {height:7px;width:7px;}
     .bottomtable .titletext{text-align: right;float: right;margin-right:5px;margin-top:-20px;display:block;}
     .bottomtable h5{margin:0;padding:0;font-size: 14px;font-weight:normal;display: inline;}
     .bottomtable ul {display:block;padding:5px;margin:0;}
     .bottomtable li {list-style-type:none;padding:10px;margin:0;height:75px;display:block;}
     .bottomtable li a{text-decoration:underline;font-weight:bold;display:block;margin-bottom:5px;}
     .bottomtable li a span{display:block;text-decoration:underline;font-weight:bold;margin:2px       0 4px;}
     .bottomtable ul img {display:inline;float:left;margin-top:-2px;margin-right:20px;}
</style>
<body>
   <div class="bottomtable">
     <ul>
        <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>                                  </li>
       <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>
       <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>
       <li><h5><a href="#">some title</a></h5><a href="javascript://close" class="close" title="">&nbsp;</a>this is some text here..............<div style="clear: right;"></div>    </li>

     </ul>
   </div>
 </body>
</html>

您的背景图片路径错误。您必须指定http://www.freeimagehosting.net/newuploads/o2gz4.png

的完整图片网址

希望这有帮助