简体   繁体   English

有没有办法在 CSS 中使用 href="tel" ?

[英]Is there a way to use href="tel" in CSS?

I'm currently making a website using a builder called 'Elementor'.我目前正在使用名为“Elementor”的构建器制作网站。 In my footer, I added an icon which I would like to make clickable, so that when you click it on your phone it uses the href="tel" function and pops up the number on your dial screen.在我的页脚中,我添加了一个图标,我想让它可以点击,这样当你在手机上点击它时,它会使用href="tel"功能并在拨号屏幕上弹出号码。

However, I can't seem to find a way to do this using CSS, as Elementor only let's me add custom CSS to icons.但是,我似乎无法找到使用 CSS 执行此操作的方法,因为 Elementor 仅让我将自定义 CSS 添加到图标。 The number itself below the icon is clickable, but this is done using the following HTML:图标下方的数字本身是可点击的,但这是使用以下 HTML 完成的:

<a href="tel:1-562-867-5309">1-562-867-5309</a>

Is there any way to do this using CSS?有没有办法使用 CSS 做到这一点?

CSS won't be able to wrap an anchor around it as it is used for styling elements. CSS将无法在其周围包裹锚,因为它用于样式元素。

  1. Your options would be to somehow get the icon within the tags that are currently there. 您的选择是以某种方式在当前存在的标签内获取图标。

  2. Use CSS to style the current tag using background-image and padding. 使用CSS通过背景图片和填充来设置当前标签的样式。

  3. Use jQuery to wrap it in an anchor. 使用jQuery将其包装在锚点中。

Yes you can use css attribute selector是的,您可以使用css 属性选择器

 a[href ^= 'tel:']:before { content: '\\1F4F1'; }
 <a href="tel:1-562-867-5309">1-562-867-5309</a>

With a pseudo-element 带有伪元素

 a:before { content: '\\260E'; } a { display: flex; flex-direction: column; text-align: center; text-decoration: none; } 
 <a href="tel:1-562-867-5309">1-562-867-5309</a> 

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

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