[attribute|=value], attribute starts with word - HTML CSS CSS Selector

HTML CSS examples for CSS Selector:attribute starts with word

Description

The [attribute|=value] selector selects elements whose attribute starts with the specified word.

The word must be a whole word, like lang="en", or followed by a hyphen( - ), like lang="en-us".

Example

Select and style elements, where the class attribute's value starts with "top":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
[class|=top] {
    background: red;
}
</style><!--from  w  w  w. ja v  a2s . c o m-->
</head>
<body>

<h1 class="top-header">Welcome</h1>
<p class="top-text">Hello world!</p>
<p class="content">Are you <span class='top'> learning CSS</span>?</p>

</body>
</html>

Related Tutorials