Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 导航图标图像_Css - Fatal编程技术网

Css 导航图标图像

Css 导航图标图像,css,Css,所以我想用一些图标图片来导航我的网站。目前,我正在使用HTML5导航标签执行以下操作 <nav> <a href="index.html"><img src="images/whatever.png"/></a> <a href="dash.html"><img src="images/whatever.png"/></a> </nav> 你可以这样做: <nav>

所以我想用一些图标图片来导航我的网站。目前,我正在使用HTML5导航标签执行以下操作

<nav>
    <a href="index.html"><img src="images/whatever.png"/></a>
    <a href="dash.html"><img src="images/whatever.png"/></a>
    </nav>

你可以这样做:

<nav>
    <a class="home" href="index.html">Home</a>
    <a class="dash" href="dash.html">Dash</a>
</nav>
nav a {
  display:inline-block; //so you can set width and height
  text-indent:-999em; //to hide the text
}
.home {
    background-image: url(../whatever.png);
    width: 100px; //image width
    height: 50px; /image height
}

您还可以使用精灵工作表保存文件大小和图像请求。(这在生成精灵图像时很有用)

因此,使用此代码:

<nav>
  <a class="home" href="index.html">Home</a>
  <a class="dash" href="dash.html">Dash</a>
</nav>

其中
0 0
0-100
是精灵表中图像左上角的x和y坐标。

谢谢@内森,这是一个方便的精灵发生器工具。
nav a {
  display:inline-block; //so you can set width and height
  text-indent:-999em; //to hide the text
}
.home {
    background-image: url(../whatever.png);
    width: 100px; //image width
    height: 50px; /image height
}
<nav>
  <a class="home" href="index.html">Home</a>
  <a class="dash" href="dash.html">Dash</a>
</nav>
nav a { 
  /* whatever positioning rules or floats you need for the links */
  height: 50px;
  width: 100px;
  text-indent: -9999px;
} 

.home { background: url(iconsprite.png) 0 0 no-repeat; }
.dash { background: url(iconsprite.png) 0 -100 no-repeat; }