Css中怎么让导航栏链接到页面指定的部位?

html-css019

Css中怎么让导航栏链接到页面指定的部位?,第1张

CSS只能控制HTML元素的外观

你说的“链接到页面指定部位”需要使用HTML中的锚链接:

一、在要链接到的地放加上 <a name="ss"></a>

二、在导航上这样写 <a href="#ss"></a>

如果导航要链接到a.html的指定位置,这样写 <a href="a.html#ss"></a>

这是个例子,保存成html文件就可以看。

<a href="#ss">点击</a>

<p>111</p><p>111</p><p>111</p><p>111</p><p>111</p>

<p>111</p><p>111</p><p>111</p><p>111</p><p>111</p>

<a name="ss"></a>

<p>111</p><p>111</p><p>111</p><p>111</p><p>111</p>

<p>111</p><p>111</p><p>111</p><p>111</p><p>111</p>

<p>111</p><p>111</p><p>111</p><p>111</p><p>111</p>

那需要css+js来实现

代码片段如下:

<style type="text/css">

#autoimg {

max-width:500px/*IE7、FF、Opera等其他非IE6浏览器下最大宽度为500px*/

}

</style>

<img src="图片路径" id="autoimg" />

<script language="javascript">

//IE6浏览器下图片autoimg的最大宽度为500px

function set_autoimg_width() {

var width = parseInt(document.getElementById("autoimg").width)

if (width >0) {

if (width >500)

document.getElementById("autoimg").width = 500

window.clearInterval(iid)

}

}

var iid = window.setInterval(set_autoimg_width, 100)

</script>

上面的CSS和JS可以让图片的宽度自动适应为小于或等于500PX。

举一反三,你根据你的需要调整宽度的值就可以了。