我如何将一个跨度的样式设置为不使用javascript的链接? [英] How do i style a span to look like a link without using javascript?

查看:103
本文介绍了我如何将一个跨度的样式设置为不使用javascript的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的网站,我需要使用< span> ,而不是< a> 'm主要使用ajax,因此,而不是链接我已经onclick ajax事件作为属性在我的跨度。

因此,我不得不手动设置样式跨度看起来像链接。我使用悬停和访问伪类来更改背景和文本颜色,但要将鼠标的默认值更改为悬停时的指针手指,我需要使用JavaScript吗?或者我可以使用css来做到这一点?



另外,我刚刚意识到...我不能使用< a> 标签,而不是< span> ,但是只是代替href,我会包含一个onclick?它应该是一样的,不是吗?

解决方案

  span {
cursor :指针;
颜色:蓝色;
text-decoration:下划线;
}

另外,您可以使用:hover 伪类来设计元素在徘徊时的样式(您可以使用任何样式,而不仅仅是最初使用的样式)。防爆。

  span:hover {
text-decoration:none;
text-shadow:1px 1px 1px#555;
}

例子


For my website i'll need to use <span> instead of <a> because i'm using mostly ajax and thus instead of links i have onclick ajax events as attributes in my spans.

As a result, i've had to manually style the spans to look like links. I've used hover and visited pseudo classes to change background and text colour, but to change the mouse default to a pointer finger on hover, will i need to use javascript? Or can i do that using css?

Also, i've just realized...couldnt i just use the <a> tag anyways instead of <span>, but just instead of an href, i would include an onclick? It should work just the same, no?

解决方案

span {
     cursor:pointer;
     color:blue;
     text-decoration:underline;
}

Additionally you can use :hover pseudo-class to style the element when hovered(you can use any styles not just the ones originally used). Ex.

span:hover {
     text-decoration:none;
     text-shadow: 1px 1px 1px #555;
}

Example

这篇关于我如何将一个跨度的样式设置为不使用javascript的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆