Mastering Cascading Style Sheet - Structuring Your Code - Attribute Selectors

  • Posted on: 20 May 2017
  • By: Hernando Cadet
css3

The world of technology, will blow you away, and if you don’t think technology, has the capacity, to do that, then you don’t live on this current world.

The world of technology, in particular computer and the Internet, have captivated the world for many years.

However, Technology has yet, to create its greatest creation, when I say technology, I am talking about the spirit, behind technology, which allowed us to have the Internet.

In today’s article, we are going to talk about more selectors, as we did in other series of this article, called CSS Mastery Structuring Your Code.

Today, we are going to talk, about selectors, in particular, about attribute selectors, to understand the importance of them in cascading style sheets.

Attribute selectors, allow a designer to target an element based on the existence, of an attribute, or the attribute’s value, as the name suggests.

Interesting and powerful things can be achieved, when the attribute selector, is being used, to style a document.

When an element has a title attribute and a user hover over that title, a tooltip, or a message that appears when a cursor is positioned over an icon, image, hyperlink, or other element in a graphical user interface; then this behavior can be used, to expand the meaning of things, such as images and abbreviations; CSS.

Only by hovering over the element, can someone tell, if this information exists, because there is no other way of seeing this extra information.

The attribute selector, can also be used, to style elements with titles different from other elements, by giving them a dotted, bottom border.

More contextual information can be provided, changing the cursor, from a pointer to a question mark, when the cursor hovers over the element, indicating that this element is different from most; abbr[title] {border-bottom: 1px dotted #777;} abbr[title]:hover {cursor: help;}.

Styles based on a particular value, can also be applied, in addition to styling an element, based on the existence of an attribute.

The ranking system for websites online, which is based on Google’s standard for example, uses attributes, mainly to give sites, linked to a rel attribute of nofollow, no added benefit.

Google, is a very good source of traffic at the moment, and having benefits from Google, to a site is a very valuable commodity.

As a possible way to show disapproval of a target site, a web site can use an image link this way; a [rel=”nofollow”] {background-image: URL (nofollow.gif); padding-right: 20px ;}.

Internet Explorer 6 does not support attribute selector, which is one clever way of using attribute elements.

This would allow a website designer, to apply one style to IE and then another style to more standard-compliant browsers.

Since IE has problems displaying 1-pixel dotted borders, choosing to render them dashed instead, is better for the browser.

A designer can choose to apply, dotted-border style only to browsers, which will apply the style correctly, using attribute selectors.

In order for a designer to achieve this, a class attribute is targeted, rather than using a class selector; .intro {border-style: solid;} [class=”intro”] {border-style: dotted;}.

Multiple values can be part of one attribute, when they are separated by comas, to style the document.

Thank you for reading this article!!!