Box Model, Css Color: Submitted by
Box Model, Css Color: Submitted by
Box Model, Css Color: Submitted by
IN
SUBMITTED BY:
SUBMITTED TO:
Assignment
BOX MODEL,CSS COLOR
The CSS Box Model
In CSS, the term "box model" is used when talking about design and
layout.
The CSS box model is essentially a box that wraps around every HTML
element. It consists of: margins, borders, padding, and the actual
content. The image below illustrates the box model:
Explanation of the different parts:
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is
transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is
transparent
Example
Demonstration of the box model:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
</style>
</head>
<body>
<p>The CSS box model is essentially a box that wraps around every HTML
element. It consists of: borders, padding, margins, and the actual content.</p>
<div>This text is the content of the box. We have added a 50px padding, 20px
margin and a 15px green border. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.</div>
</body>
</html>
CSS Colors
The color property in CSS is used to set the color of HTML elements.
Typically, this property is used to set the background color or the font
color of an element.
In CSS, we use color values for specifying the color. We can also use this
property for the border-color and other decorative effects.
We can define the color of an element by using the following ways:
RGB format.
RGBA format.
Hexadecimal notation.
HSL.
HSLA.
Built-in color.
RGB Format
RGB format is the short form of 'RED GREEN and BLUE' that is used for
defining the color of an HTML element simply by specifying the values
of R, G, B that are in the range of 0 to 255.
The color values in this format are specified by using the rgb() property.
This property allows three values that can either be in percentage or
integer (range from 0 to 255).
This property is not supported in all browsers; that's why it is not
recommended to use it.
Syntax
color: rgb(R, G, B);
RGBA Format
It is almost similar to RGB format except
that RGBA contains A (Alpha) that specifies the element's
transparency. The value of alpha is in the range 0.0 to 1.0, in
which 0.0 is for fully transparent, and 1.0 is for not
transparent.
Syntax
color:rgba(R, G, B, A);
Hexadecimal notation
Hexadecimal can be defined as a six-digit color representation.
This notation starts with the # symbol followed by six
characters ranges from 0 to F. In hexadecimal notation, the first
two digits represent the red (RR) color value, the next two
digits represent the green (GG) color value, and the last two
digits represent the blue (BB) color value.
The black color notation in hexadecimal is #000000, and the
white color notation in hexadecimal is #FFFFFF. Some of the
codes in hexadecimal notation are #FF0000, #00FF00, #0000FF,
#FFFF00, and many more.
Syntax
color:#(0-F)(0-F)(0-F)(0-F)(0-F)(0-F);
HSLA
It is entirely similar to HSL property, except that it contains A
(alpha) that specifies the element's transparency. The value of
alpha is in the range 0.0 to 1.0, in which 0.0 indicates fully
transparent, and 1.0 indicates not transparent.
Syntax
color:hsla(H, S, L, A);
Built-in Color
As its name implies, built-in color means the collection of
previously defined colors that are used by using a name such as
red, blue, green, etc.
Syntax
color: color-name;