Lab03 CSS LabManual
Lab03 CSS LabManual
• CSS Grouping
When we apply generic CSS to a tag, that tag has the properties given wherever it is used.
1
Thanks to the Style Template selectors, we can apply different styles to the same tag in different
places.
In other words, we can apply the CSS selector we created to a tag wherever we want and not apply it
where we don't want it. We can even apply different formatting to the same label in different places.
Step 1 - ID Selectors:
2
Step 2 – Class Selectors:
3
PROCEDURE 2 – CSS Grouping
We can group while selecting tags with the same style values. For example;
Here 3 tags have the same style. Then we can write it in one line, separated by commas. **
Execute the code and review the results.
Note: You can use not only tags but also id and class.
4
We can make combined selections using different options over the label names.
*{ Selects all tags
p{ Selects all p tags. It can be used in other tags as well.
div p { Selects all p tags contained within div tags.
div , p { Selects all div and all p tags.
div > p { Selects all p tags whose parent tag is div.
Selects all div tags at the same level after p. To see the same level, you can
p ~ div {
look at the tab level in the editors.
p + div { Selects the first div tag of the same level after p.
Selects the p paragraphs with the label whose class name is box inside the
div.box , p {
div.
The CSS box model is a box model of rectangles that wrap around each HTML element. The box
model allows us to add a border around elements and define spacing between elements. It consists
of: margins, borders, padding, and actual content.
Content - The main content of the box in which text and images appear.
Padding - The space around the content. The fill is transparent so no color can be assigned. It can be
called inner space.
Border – The border that surrounds the outer part of the padding. Color and line-type can be
assigned to it.
Margins – The transparent space outside the border of the frame. Color cannot be given. It can be
called the outer space.
5
Step 1 - Width and Height of an Element. First, we create a new file named firstLayer.html to write
the HTML codes.
Step 2 – We are creating a <div> element whose id is firstLayer. Next, we prepare content using the
h1 and p tags.
Step 3 – Secondly, we create a css file named firstLayer.css. And we add which style properties to
which layer we will apply to this file.
Step 4 - We are designing a box model with a yellow background color, a width of 300px, a border
size of 15px and a color of red, 50px between content and border, and 20px outside space (margin).
Step 5 - We embed the firstLayer.css file in the html document using the <link> tag.
6
PROCEDURE 4 – Example Web Page Design with “div”
7
T.A. Merve GÜN