47

The many ways to link shapes using HTML and CSS

 4 years ago
source link: https://www.tuicool.com/articles/F3Ynma7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

:bulb: Tip of the Week

supported by f22U3uf.png!web

Styling links with CSS selectors

CSS selectors offer a powerful way to add style, and contextual information, to HTML elements, and while you can target element IDs, classes, etc.the spec hash been fleshed out over the years to support lots of other things you can easily select to style.

John Rhea highlights the wide variety in which they can be used in this excellent article , but for today we're just going to look at how they can be utilised for links .

Let's say you want to style links to PDF documents, signifying to the user that the link is to a 'document', rather than a Web page. This can beachieved like so:

a[href$=".pdf"] {

background: url('https://i.imgur.com/n8EHrrI.png')

0 50% no-repeat;

padding-left: 20px;

}

The $= operator in the attribute selector targets the end of the attribute value, looking specifically for links to PDFs. It will then add the linked PDF icon before the full link, like so:

JZbEnuv.png!web

This is just one quick example of how this can be used. You could also use this technique to style links tocertain sites, style internal links differently to those that are outbound, or even to style certain images by targeting the src attribute of a file. It's worth playing around and experimenting!

This Tip of the Week is sponsored byFlatiron School, where you can learnsoftware engineering,data science, orUX/UI design in just 15 weeks online or on campus.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK