tanszek:oktatas:techcomm:cascading_style_sheets
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tanszek:oktatas:techcomm:cascading_style_sheets [2024/10/01 09:06] – [4. CSS comments] kissa | tanszek:oktatas:techcomm:cascading_style_sheets [2024/10/01 10:32] (current) – [3. Defining CSS styles] kissa | ||
---|---|---|---|
Line 90: | Line 90: | ||
<code CSS> | <code CSS> | ||
+ | /* styles.css */ | ||
p { | p { | ||
color: blue; | color: blue; | ||
Line 109: | Line 110: | ||
</ | </ | ||
- | ==== 5. Element, ID, and class Selectors | + | ==== 5. Selecting elements, classes |
- | * **Element selector**: Applies to all specified elements. | + | CSS selectors are patterns used to select and style HTML elements. Three common types of selectors are **element**, **class**, and **ID** |
- | * **ID selector**: Targets a specific element based on its unique | + | |
- | * **Class selector**: Targets one or more elements with a specific class. | + | |
- | <code CSS> | + | An **element |
- | /* Element | + | |
- | p { | + | |
- | | + | |
- | } | + | |
- | /* ID selector, applies to the element with the specific ID " | + | <code XML> |
- | #header { | + | < |
- | font-size: | + | < |
- | } | + | < |
+ | | ||
+ | p { | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
- | /* Class selector, | + | A **class |
- | .button | + | |
- | background-color: | + | <code XML> |
- | } | + | < |
+ | < | ||
+ | < | ||
+ | < | ||
+ | .highlight | ||
+ | background-color: | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <p class=" | ||
+ | < | ||
+ | <div class=" | ||
+ | </ | ||
+ | </ | ||
</ | </ | ||
+ | |||
+ | An **ID selector** targets a single, unique HTML element by referencing its '' | ||
+ | |||
+ | <code XML> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | # | ||
+ | font-size: 24px; | ||
+ | text-align: center; | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | <h1 id=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | In summary, element selectors are used for broad styling, ID selectors offer targeted styling for unique elements, and class selectors provide versatility by enabling the styling of multiple elements at once. Understanding these selectors and how to use them together is key to writing efficient and maintainable CSS. | ||
+ | |||
+ | Element selectors are marked with the name of the member, class selectors are marked with a '' | ||
+ | |||
+ | ^ Selector type ^ HTML example | ||
+ | | Element selector | ||
+ | | Class selector | ||
+ | | ID selector | ||
==== 6. Cascading ==== | ==== 6. Cascading ==== | ||
- | When multiple rules target the same selector, the later rule will override the previous one. | + | By default, when multiple rules target the same selector, the later rule will override the previous one: |
<code XML> | <code XML> | ||
Line 153: | Line 205: | ||
</ | </ | ||
- | ==== 7. Role of '' | + | ==== 7. Role of span and div elements ==== |
- | * '' | + | The **span** and **div** elements are fundamental components in HTML used for grouping and organizing content. They serve as containers that can be styled using CSS. |
- | * '' | + | |
+ | The '' | ||
+ | |||
+ | <code XML> | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | The '' | ||
<code XML> | <code XML> | ||
- | < | + | <div style=" |
- | <div style=" | + | <h1>Section Title</h1> |
- | <p>This is bold text.</p> | + | <p>This paragraph |
- | <p>So is this.</ | + | |
- | < | + | |
</ | </ | ||
</ | </ | ||
Line 169: | Line 226: | ||
==== 8. Background styling ==== | ==== 8. Background styling ==== | ||
- | The '' | + | Background styling in CSS allows developers to customize |
<code CSS> | <code CSS> | ||
Line 183: | Line 240: | ||
==== 9. Margin, padding and border ==== | ==== 9. Margin, padding and border ==== | ||
- | The '' | + | The **box model** |
{{: | {{: | ||
- | < | + | The '' |
- | div { | + | |
- | margin: 10px; | + | The example below shows how to format a button. Try what happens when you change the button' |
- | padding: 20px; | + | |
- | border: 1px solid black; | + | < |
- | border-radius: | + | < |
- | } | + | < |
+ | < | ||
+ | | ||
+ | < | ||
+ | .styled-button { | ||
+ | color: green; | ||
+ | background-color: | ||
+ | | ||
+ | padding: 20px; | ||
+ | border: 1px solid red; | ||
+ | border-radius: | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | <button class=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
</ | </ | ||
Line 217: | Line 293: | ||
font-weight: | font-weight: | ||
font-style: italic; | font-style: italic; | ||
- | |||
text-decoration: | text-decoration: | ||
text-align: justify; | text-align: justify; | ||
} | } | ||
</ | </ | ||
+ | |||
+ | If you are interested, [[https:// | ||
==== 12. Exercise ==== | ==== 12. Exercise ==== | ||
- | Create the following webpage | + | Create the following webpage using HTML and CSS. Use embedded |
- | Feel free to use online resources (e.g. [[https:// | + | Feel free to use online resources (e.g. [[https:// |
{{: | {{: |
tanszek/oktatas/techcomm/cascading_style_sheets.1727773591.txt.gz · Last modified: 2024/10/01 09:06 by kissa