简体   繁体   English

'切换'电话:链接打开和关闭...最好只有CSS

[英]'Switching' a Tel: link on and off… Preferably CSS only

I have read in a few other posts that creating a tappable link for a phone number can be done with tel: in an anchor tag 我在其他一些帖子中读过,可以使用tel:在锚标签中创建电话号码的可点击链接

I would like to implement this in a responsive website.. something like this: 我想在响应式网站中实现这一点..这样的事情:

<a href="tel://1-555-555-5555">Call Us! <span>(555) 555-5555</span></a>

(the span tag I plan to use to hide the phone# with CSS) (我计划使用span标记隐藏手机#with CSS)

The idea is that on a desktop you will only see "Call Us! (555) 555-5555", but not be an actual link 这个想法是在桌面上你只会看到“给我们打电话!(555)555-5555”,但不是一个实际的链接

But when we scale down to mobile, you will then see a stylized link that just says "Call Us!" 但是,当我们缩小到移动设备时,您会看到一个风格化的链接,只是说“打电话给我们!” that you can click. 你可以点击。

I'm sure there is a way to accomplish this with JavaScript or JQuery... but is there anyway to accomplish this with CSS Media Queries? 我确信有一种方法可以通过JavaScript或JQuery实现这一目标......但是无论如何使用CSS Media Queries实现这一目标?

Note: Visual styling is no problem.. just looking for a reasonable solution for the "switching" concept. 注意:视觉样式没有问题。只是为“切换”概念寻找合理的解决方案。

Thanks in advance! 提前致谢!

There really isn't anything wrong with leaving the link on desktop computers. 将链接留在台式计算机上确实没有任何问题。 This would for example allow you to click the link to call via Skype or other VOIP program you might have installed. 例如,这将允许您单击通过Skype或您可能已安装的其他VOIP程序呼叫的链接。

If you still want to change the link, just create two of them. 如果您仍想更改链接,只需创建其中两个。 One that is shown for desktops, the other for mobiles. 一个用于桌面,另一个用于移动设备。

You could create 2 links, one to show on desktop and one for mobile 您可以创建2个链接,一个用于在桌面上显示,另一个用于移动

OR 要么

Use css to style the anchor with phone number in them to default cursor so it does not look like a link even when you hover. 使用css将锚点中的电话号码设置为默认光标,这样即使您悬停也不会看起来像链接。 To complement this, you need to use js to disable the click action. 为了补充这一点,您需要使用js来禁用单击操作。

This is all assuming you can detect what device you are on reliably. 这是假设您可以可靠地检测到您所使用的设备。

I think your best bet would be to add an ID to your anchor tag and through your media query you can hide it on the desktop version there no need for the span. 我认为您最好的选择是为您的锚标签添加ID,通过媒体查询,您可以将其隐藏在桌面版本上,而不需要跨度。

Then for your non anchor text hide that when you are scaled down through another ID in a media query. 然后,当您通过媒体查询中的另一个ID缩小时,您的非锚文本会隐藏。

<a href="tel:123456789" class="tel-link">TEL: 123-456-789</a>

@media screen and (min-width: 600px) {
    .tel-link {
        color: #000 !important;
        text-decoration: none !important;
    }
}

This will display the phone number in plain black for the browsers over 600px wide ( so it doesn't look like a link ) even though it still has a link. 对于宽度超过600px的浏览器,这将显示纯黑色的电话号码(因此它看起来不像链接),即使它仍然有链接。 I think it's ok because you can make a call from PC nowadays. 我认为没关系,因为你现在可以通过PC打电话了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM