CSS Lab
CSS Lab
p{
margin-left: inherit;
}
</style>
Define a paragraph (<p>) inside the <div> and comment on the effect of
inherit margin.
20) Consider the following style sheet
<style>
div {
border: 1px solid red;
margin-left: 100px;
}
</style>
Consider the following nested <div>
<div>
This is divTop
<div>
This is div2
</div>
<div>
This is div3
</div>
Provide the following style to divTop, div2 and div3
i. divTop left margin is 100 pixel
ii. div2 left margin is 300 pixel
iii. div3 should inherit the left margin of divTop
Exercise: CSS Table
21) Consider the following HTML code for table:
<TABLE>
<TR id="row1">
<TH>Header 1 <TD>Cell 1 <TD>Cell 2
<TR id="row2">
<TH>Header 2 <TD>Cell 3 <TD>Cell 4
<TR id="row3">
<TH>Header 3 <TD>Cell 5 <TD>Cell 6
</TABLE>
Write CSS style so that the top row will be surrounded by a 3px solid blue
border, the second row will be surrounded by a 1px solid black border and
the last row will be surrounded by a 1px dashed black border.
The borders around the rows overlap where the rows meet. What color
(black or blue) and thickness (1px or 3px) will the border between row1 and
row2 be? Discuss how CSS resolves this conflict.
22) Consider the following HTML code:
<table>
<tr><td>1 </td><td rowspan="2">2 </td><td>3 </td><td>4 </td></tr>
<tr><td colspan="2">5 </td></tr>
</table>
Discuss what this code does. Write CSS for the same task.
23) Write CSS style to color each row of a table in different color.
Exercise: Combinators, Pseudo-classes, Pseudo-elements
24) Use CSS combinator to design a style sheet which provides a red background
to every item in an unordered list.
25) Write a CSS style so that every paragraph immediately after a <h1> heading
is on yellow background and the text color is red.
26) Write a CSS style so that every ordered list after a <div> is on yellow
background and the text color is red.
27) Write a CSS style so that every ordered list after a <div> is on yellow
background and the text color is red. These styles are applicable only when
you hover over the lists.
28) Write a CSS style to change the text color of the first element in an
unordered list. The text color should be blue.
29) Write a CSS style to apply blue background for all even rows and yellow
background for all odd rows of a table.
30) Write a CSS style such that the first letter of the first three items in an
unordered list will be in red color. Do not use three separate codes for three
items.
31) Write a single CSS style to perform the following:
a) Only the first paragraph of every <div> is surrounded by < and >. This
style is applicable to any other html elements.
b) Only the first paragraph of every <div> has background color
rgb(0,200,100), font size 20 px and max-width as half the width of the
parent.
Exercise: Id Selector, Class Selectors and CSS Variables
32) Write a CSS style so that every element in an ordered list is on yellow
background and the text color is red. These styles are applicable only when
you hover over the lists. Perform this exercise using CSS variable for define
background and text color.
33) Do necessary changes in Exercise 32 and create a four element ordered list
where the four elements have background color as: yellow, purple, green
and coral respectively. Perform this exercise using CSS variable for
background color.
34) Consider the following style sheet
:root{
--test1: 30px;
--test2: 10pt;
}
.one {
font-size: var(--test1);
}
.three {
font-size: var(--test2);
}
Consider the HTML associated with this CSS
<div class="one">
This is 1
<div class="two">
This is 2
<div class="three">This is 3 </div>
<div class="four">This is 4 </div>
</div>
</div>