Skip to main content

The CSS class Selector

The class selector selects HTML elements with a specific class attribute.

To select elements with a specific class, write a period (.) character, followed by the class name.

Example

In this example all HTML elements with class="center" will be red and center-aligned: 

.center {
  text-align: center;
  color: red;
}
Try it Yourself »

You can also specify that only specific HTML elements should be affected by a class.

Example

In this example only <p> elements with class="center" will be red and center-aligned: 

p.center {
  text-align: center;
  color: red;
}
Try it Yourself »

HTML elements can also refer to more than one class.

Example

In this example the <p> element will be styled according to class="center" and to class="large": 

<p class="center large">This paragraph refers to two classes.</p>
Try it Yourself »

Note: A class name cannot start with a number!


The CSS Universal Selector

The universal selector (*) selects all HTML elements on the page.

Example

The CSS rule below will affect every HTML element on the page: 

{
  text-align: center;
  color: blue;
}
Try it Yourself »

The CSS Grouping Selector

The grouping selector selects all the HTML elements with the same style definitions.

Look at the following CSS code (the h1, h2, and p elements have the same style definitions):

h1 {
  text-align: center;
  color: red;
}

h2 {
  text-align: center;
  color: red;
}

{
  text-align: center;
  color: red;
}

It will be better to group the selectors, to minimize the code.

To group selectors, separate each selector with a comma.

Example

In this example we have grouped the selectors from the code above: 

h1, h2, p {
  text-align: center;
  color: red;
}
Try it Yourself »
All CSS Simple Selectors
SelectorExampleExample description
#id#firstnameSelects the element with id="firstname"
.class.introSelects all elements with class="intro"
element.classp.introSelects only <p> elements with class="intro"
**Selects all elements
elementpSelects all <p> elements
element,element,..div, pSelects all <div> elements and all <p> elements

Comments

Popular posts from this blog

พยางค์

การที่เราเปล่งเสียงออกมาจากลำคอครั้งหนึ่ง ๆ นั้น เราเรียกเสียงที่เปล่งออกมาว่า “พยางค์” แม้ว่าเสียงที่เปล่งออกมาจะมีความหมายหรือไม่มีความหมายก็ตาม เช่น เราเปล่งเสียง “สุ” ถึงจะไม่ รู้ความหมาย หรือไม่รู้เรื่องเราก็เรียกว่า ๑ พยางค์ หากเราเปล่งเสียงออกมาอีกครั้งหนึ่งว่า “กร” จะ เป็น “สุกร” จึงจะมีความหมาย คำว่า “สุกร” ซึ่งเปล่งเสียง ๒ ครั้ง เราก็ถือว่ามี๒ พยางค์ เสียงที่เปล่ง ออกมาครั้งเดียวมีความหมาย เช่น นา หมายถึง ที่ปลูกข้าว เสียงที่เปล่งออกมาว่า “นา” นี้เป็น ๑ พยางค์ ลองดูตัวอย่างต่อไปนี้ ไร่ มี๑ พยางค์ ชาวไร่ มี๒ พยางค์ (ชาว-ไร่) สหกรณ์ มี๓ พยางค์ (สะ-หะ-กอน) โรงพยาบาล มี๔ พยางค์ (โรง-พะ-ยา-บาน) นักศึกษาผู้ใหญ่ มี๕ พยางค์ (นัก-สึก-สา-ผู้-ใหญ่) สหกรณ์การเกษตร มี๖ พยางค์ (สะ-หะ-กอน-การ-กะ-เสด) จากตัวอย่างข้างบนนี้สรุปได้ว่า พยางค์ คือ เสียงที่เปล่งออกมาครั้งหนึ่ง จะมีความหมายหรือไม่มีความหมายก็ตาม ถ้าเปล่ง เสียงออกมา ๑ ครั้ง ก็เรียก ๑ พยางค์ สองครั้งก็เรียก ๒ พยางค์ องค์ประกอบของพยางค์ พยางค์เกิดจากการเปล่งเสียงพยัญชนะ สระ และวรรณยุกต์ออกมาพร้อม ๆ กัน พยางค์ที่มี ความหมายอาจจะเป็นพยา...

How to Download and Install SQL Server

  Pre-Requisites Principally, MS SQL server requires: .Net Framework,1GB of recommended memory, and NTFS system. How to download SQL Server Setup Step 1)  Go to URL :   https://www.microsoft.com/en-in/sql-server/sql-server-downloads Microsoft provides  two specialized free editions  to work on MS SQL server: Developer  – It has all feature which MS SQL server offers but we cannot use it in production. From the learning perspective, is it an ideal candidate to start. Express : This is also a free version but with the limited set of features with no business intelligence applications. We will select the  Developer edition  for installation. Step 2)  Click on  "Download now" We will get set up as  'SQLServer2017-SSEI-Dev.exe'. How to Install SQL Server Step 1)  Double click on  "SQLServer2017-SSEI-Dev.exe".  Below screen will appear with three options: Basic, Custom and Download files. Step 2)  Choose the basic vers...

อักษรควบ

คำควบกล้ำ ( อักษรควบ ) หมายถึง พยัญชนะสองตัวเขียนเรียงกันอยู่ต้นพยางค์ และใช้สระเดียวกัน เวลาอ่านออกเสียงกล้ำเป็นพยางค์เดียวกัน เสียงวรรณยุกต์ของพยางค์นั้นจะผันเป็นไปตามเสียงพยัญชนะตัวหน้า คำควบกล้ำ ( อักษรควบ ) มี 2 ชนิด คือ คำควบแท้ ได้แก่ พยัญชนะ ร ล ว ควบกับพยัญชนะตัวหน้า ประสมสระตัวเดียวกัน เวลาอ่านออกเสียงพยัญชนะทั้งสองตัวพร้อมกัน เช่น พยัญชนะต้นควบกับ ร ได้แก่ ครู เพราะ ครัว กรน ปรวนแปร ขรุขระ พระ ตรง ครั้ง กราบ โปรด ปรักปรำ ครื้นเครง เคร่งครัด ครอบ ปรอย กรอง พยัญชนะต้นควบกับ ล ได้แก่ เปล่า ปลีก คลาน คลุก เคล้า เปลี่ยนแปลง กลบ กลม เพลิดเพลิน เกลี้ยกล่อม เกลียวคลื่น คล่องแคล่ว เกล้า พยัญชนะต้นควบกับ ว ได้แก่ กวาด ขวาน ควาย ขวิด แคว่งคว้าง แขวน ขวนขวาย คว่ำ ควาญ แกว่งไกว ความ แคว้น ขวัญ ควัน คำควบไม่แท้ ได้แก่ พยัญชนะ ร ควบกับพยัญชนะตัวหน้าประสมสระตัวเดียวกัน เวลาอ่านไม่ออกเสียง ร ออกเสียงเฉพาะตัวหน้าหรือมิฉะนั้นก็ออกเสียง เป็นเสียงอื่นไป คำควบไม่แท้ที่ออกเสียงเฉพาะพยัญชนะตัวหน้า ได้แก่พยัญชนะ จ ซ ศ ส ควบกับ ร เช่น จริง ไซร้ เศร้า ศรี ศรัทธา สร้าง เสริม สร้อย สระ สรง สร่าง คำควบไม...