CSS Attr Selectors

CSS Tutorial


Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

CSS Advanced


Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

CSS Responsive

CSS Grid

CSS Attribute Selectors

CSS [attribute] Selector

The [attribute] selector selects elements with a specific attribute.

The example selects all <a> elements with a target attribute:

HTML
				
					<h2>CSS [attribute] Selector</h2>
<p>The links with a target attribute gets a orange background:</p>
<a href="https://www.webhostguru.com">webhostguru.com</a>
<a href="http://www.disn.com" target="_blank">disn.com</a>
<a href="http://www.craft.org" target="_top">craft.org</a>
				
			
CSS
				
					a[target] {
  background-color: orange;
}
				
			

Output

attribute selector

CSS [attribute=”value”] Selector

The [attribute=”value”] selector selects elements with a specific attribute and value.

The example selects all <a> elements with a target=”_blank” attribute:

HTML
				
					<h2>CSS [attribute] Selector</h2>
<p>The links with a target attribute gets a orange background:</p>
<a href="https://www.webhostguru.com">webhostguru.com</a>
<a href="http://www.disn.com" target="_blank">disn.com</a>
<a href="http://www.craft.org" target="_top">craft.org</a>
				
			
CSS
				
					a[target=_blank] {
  background-color: orange;
}

				
			

Output

css attr selector

CSS [attribute~=”value”] Selector

The [attribute~=”value”] selector selects elements with an attribute value that consists of  specific word.

HTML

				
					<h2>CSS [attribute~="value"] Selector</h2>
<p>All images with the title attribute containing the word "flower" get a yellow border.</p>
<img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20150%20113'%3E%3C/svg%3E" title="bord" width="150" height="113"  data-recalc-dims="1" data-lazy-src="https://i0.wp.com/www.animationsource.org/sites_content/spirit/img_screenshot/142123.jpg?resize=150%2C113&#038;ssl=1"><noscript><img decoding="async" src="https://i0.wp.com/www.animationsource.org/sites_content/spirit/img_screenshot/142123.jpg?resize=150%2C113&#038;ssl=1" title="bord" width="150" height="113"  data-recalc-dims="1"></noscript>
<img loading="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20224%20162'%3E%3C/svg%3E" title="bord" width="224" height="162"  data-recalc-dims="1" data-lazy-src="https://i0.wp.com/images.tele.quebec/produits2/284406/default/w1152_h648.jpg?resize=224%2C162&#038;ssl=1"><noscript><img loading="lazy" decoding="async" src="https://i0.wp.com/images.tele.quebec/produits2/284406/default/w1152_h648.jpg?resize=224%2C162&#038;ssl=1" title="bord" width="224" height="162"  data-recalc-dims="1"></noscript>
<img loading="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20200%20358'%3E%3C/svg%3E" title="tree" width="200" height="358"  data-recalc-dims="1" data-lazy-src="https://i0.wp.com/www.animationsource.org/sites_content/spirit/img_screenshot/142531.jpg?resize=200%2C358&#038;ssl=1"><noscript><img loading="lazy" decoding="async" src="https://i0.wp.com/www.animationsource.org/sites_content/spirit/img_screenshot/142531.jpg?resize=200%2C358&#038;ssl=1" title="tree" width="200" height="358"  data-recalc-dims="1"></noscript>
				
			
CSS
				
					[title~=bord] {
  border: 5px solid pink;
}
				
			

Output

css attr

CSS [attribute|=”value”] Selector

The [attribute|=”value”] selector selects elements with the specific attribute, whose value be exactly the specified value or the specified value followed by a hyphen (-).

HTML
				
					<h2>CSS [attribute|="value"] Selector</h2>
<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="topcontent">Are you Okay?</p>
				
			
CSS
				
					[class|=top] {
  background: pink;
}
				
			

Output

attribute value selector

CSS [attribute$=”value”] Selector

The [attribute$=”value”] selector select elements whose attribute value ends with a specified value.

The example selects all elements with a class attribute value that ends with “test”:

HTML
				
					<h2>CSS [attribute$="value"] Selector</h2>
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="my-test">The third div element.</div>
<p class="mytest">This is some text in a paragraph.</p>
				
			
CSS
				
					[class$="test"] {
  background: pink;
}
				
			

Output

$ value attribute selector

CSS [attribute*=”value”] Selector

The [attribute*=”value”] selector selects elements that has attribute value consist a specified value.

The example selects all elements with a class attribute value that contains “te”:

HTML
				
					<h2>CSS [attribute*="value"] Selector</h2>
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="my-test">The third div element.</div>
<p class="mytest">This is some text in a paragraph.</p>
				
			
CSS
				
					[class*="te"] {
  background: pink;
}
				
			

Output

attribute in css

Styling Forms

The attribute selectors can be used for styling forms without class or ID:

HTML
				
					<h2>Styling Forms</h2>
<form name="input" action="" method="get">
  Firstname:<input type="text" name="Name" value="first" size="20">
  Lastname:<input type="text" name="Name" value="last" size="20">
  <input type="button" value="Example Button">
</form>
				
			
CSS
				
					input[type=text] {
  width: 150px;
  display: block;
  margin-bottom: 10px;
  background-color: pink;
}

input[type=button] {
  width: 120px;
  margin-left: 35px;
  display: pink;
}
				
			

Output

styling form using attribute selector