unit 2 web tech
unit 2 web tech
SS (Cascading Style Sheets) is a stylesheet language used for describing the presentation of a
C
document written in HTML or XML. It defines how elements should be displayed on the screen,
paper, or in other media. CSS separates content from design, making it easier to maintain and
manage the look and feel of a website or application.
Types of CSS
<head>
<style>
h1 {
color: green;
font-size: 30px;
}
</style>
</head>
<body>
<h1>Welcome to CSS</h1>
</body>
<head>
</head>
h1 {
color: purple;
font-size: 32px;
}
CSS Properties:
SS provides a wide variety of properties for styling different aspects of HTML elements. Some
C
key categories and properties include:
Text Styling:
● c olor: Sets the text color.
● font-family: Specifies the font to use.
● font-size: Defines the size of the font.
● font-weight: Controls the boldness of the text.
● line-height: Controls the spacing between lines oftext.
● text-align: Aligns the text (e.g., left, right, center).
Box Model
TheCSS box modeldefines how the dimensions of anelement are calculated, including
margins, borders, padding, and the actual content area.
● idth: Sets the width of an element.
w
● height: Sets the height of an element.
● margin: Adds space outside the element.
● padding: Adds space inside the element, around thecontent.
● border: Defines a border around an element.
div {
width: 200px;
height: 100px;
padding: 20px;
margin: 10px;
}
Background Styling
● b ackground-color: Sets the background color of anelement.
● background-image: Sets an image as the background.
● background-size: Controls the size of the backgroundimage.
● background-position: Sets the position of the backgroundimage.
Layout
EXAMPLE:
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
hen working with block elements and objects in CSS, it's important to understand how
W
block-level elements are displayed, how they interact with other elements, and how to manage
the layout effectively using properties and techniques.
lock-level elements in HTML take up the full width of their container by default and start on a
B
new line. They typically stack vertically, meaning each block element pushes the next one below
it.
● div>
<
● <p>
● <h1>,<h2>,<h3>, etc.
● <ul>,<ol>,<li>
● <section>
● <article>
● <footer>
ou can control the layout, positioning, and appearance of block elements using CSS. Here are
Y
some key properties and techniques for managing block elements:
y default, block elements take up the full width of their parent container. However, you can
B
control their width and height with thewidthandheightproperties.
div {
height: 200px;
}
● B lock elements will automatically extend to the full width of their parent unless explicitly
given a width.
● You can set a fixed or percentage-based width.
● You can also use min-width max-width
, min-height
, max-heightto
,and
control the dimensions.
argins are used to create space around elements, while padding creates space inside an
M
element.
div {
}
div {
display: block; /* Block-level element */
}
span {
display: inline;
}
● inline-block: This combines some of the behavior of both block and inline. The element
behaves like a block-level element but doesn’t break onto a new line.
div {
}
d. Positioning
● s tatic (default) – No positioning, it follows the normal document flow.
● relative – Positioned relative to its normal position.
● absolute – Positioned relative to the nearest positioned ancestor.
● fixed – Positioned relative to the viewport (remains in the same position even when
scrolling).
sticky – Switches between relative and fixed, depending on the scroll position.
●
div {
position: relative;
top: 20px;
left: 30px;
}
e. Overflow
y default, if content exceeds the size of a block element, it will overflow outside. You can
B
control this with theoverflowproperty.
div {
width: 300px;
height: 150px;
}
Possible values:
● v isible(default): Content can overflow.
● hidden: Content is clipped and not visible.
● scroll: Always shows scrollbars, even if the contentfits.
● auto: Only shows scrollbars when needed.
lexbox is a powerful layout tool that can be used in conjunction with block-level elements to
F
align and distribute space within containers.
.container {
display: flex;
}
.item {
}
CSS Grid Layout is another powerful method for creating complex, two-dimensional layouts.
.container {
display: grid;
}
.item {
background-color: lightgray;
padding: 10px;
}
<!DOCTYPE html>
<style>
.container {
display: flex;
justify-content: space-between;
gap: 10px;
}
.item {
width: 30%;
padding: 20px;
background-color: lightblue;
text-align: center;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="container">
</div>
</body>
</html>
I n CSS, objects can refer to elements such as images, videos, or other media. You can style these
objects similarly to block elements but need to take extra care for certain properties.
● I mages: Usedisplay: blockto remove inline behaviorand ensure that images behave like
block elements.
img {
display: block;
width: 100%;
height: auto;
}
● V
ideos: Similarly, you might want to style video elements as block-level to control
their layout.
video {
display: block;
width: 100%;
}