Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CSS classes to Format a href:tel link

Tags:

html

css

I've recently inherited a site that's built entirely in HTML and CSS and uses an FTP portal. In the interest of making the site more mobile friendly I'm trying to implement click-to-call phone numbers throughout their website. The code I'm been using for the click to call is the classic:

<a href="tel:#number">#number></a>

There is a master CSS document for the site that provides the formatting for the various elements of their site. There is a .phonenumber class that sets the phone numbers at a size of 48px, makes the font arial, and red. Currently all the phone numbers are coded like so:

<span class="phonenumber"> phone #</span>

However, this formatting disappears when I turn the phone # portion into a <a href=tel>. Even though the link is between the <span> the formatting does not seem to apply. Is there a way to format a click-to-call link using CSS classes? Or to manually set the attributes so that the number retains its red, 48px formatting while still acting as a link? Right now it appears I can either have it as a link or have it formatted. Please let me know if there is a work around.

like image 281
Sad Bones Malone Avatar asked Jul 20 '15 15:07

Sad Bones Malone


People also ask

Can you do href in CSS?

You cannot simply add a link using CSS. CSS is used for styling. You can style your using CSS. If you want to give a link dynamically to then I will advice you to use jQuery or Javascript.

How do I specify a link in CSS?

The :link selector is used to select unvisited links. Note: The :link selector does not style links you have already visited. Tip: Use the :visited selector to style links to visited pages, the :hover selector to style links when you mouse over them, and the :active selector to style links when you click on them.

Can you href a class in HTML?

Yes you can use either id or class as long as you are targeting them correctly.

What is HTML href?

What is the HTML a href attribute? In HTML, the inline a (anchor) element denotes a hyperlink from one web address to another. All functional a elements must contain the href (hypertext reference) attribute inside the opening a tag. The href attribute indicates the destination of the hyperlink.


1 Answers

You can use Attribute Selectors to match the begining of the href value to "tel", using the prefix comparision ^=:

a[href^="tel:"] {
}

This would match only the a tags which href property starts with the "tel" value:

Example:

a[href^="tel:"] {
  color: red;
}
<a href="http://www.google.com">Test 1</a><br />
<a href="tel:+123456">Test 2</a>
like image 150
LcSalazar Avatar answered Sep 24 '22 07:09

LcSalazar