42
loading...
This website collects cookies to deliver better user experience
span
, input
,a
,button
div
,headings
,paragraphs
height
and width
CSS properties to determine the size of the content area.<p style="background: palegreen;">
Hi, I'm Paragraph
</p>
P
is block level element. So by default it takes the entire space by default as shown above.100px
of height and width. We can achieve by changing the height and width of particular element.<p style="height: 100px;width: 100px;background: palegreen;">
Hi, I'm Paragraph
</p>
100 * 100
which is nothing but width * height
. Before applying the styles, by default according to the screen layout these sizes are chosen.px
but we have lot of different units available. In order to know more about units, please refer this link<span style="height: 120px;width: 500px;background: palegreen;">
Hi, I'm Span
</span>
inline-block
elements.<span style="height: 120px;width: 500px;background: palegreen;display: inline-block;">
Hi, I'm Span
</span>
display:inline-block
style property to inline elements we are making them to behave as combination of both inline
and block
elements. (By default we don't want to mention the display property unless we want to change the height and width of inline elements).inline
as well as inline-block
. You can set height and width to change the size MDN.border: 1px solid red;
1px -> border-width
solid -> border-style
red -> border-color.
<span style="height: 120px;width: 500px;background: palegreen;display: inline-block;border: 10px solid red;">
Hi, I'm Span
</span>
10px
with red color has been applied to the element and if you look at the border in the box model it denotes 10 on each sides which represents 10px
width. we can apply different colors for the same border too.border-radius
property.10px
padding on all the sides starting from top(clockwise direction).padding: 10px;
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
padding: 10px 20px
padding: 5px 10px 7px
5px -> padding top.
10px -> padding left and padding right.
7px -> padding bottom.
10px
space between two boxes on a page. Same as padding, you can apply margin either on all four sides or one side. It follows the same clockwise direction. Difference between padding and margin is padding will occupy the space within content box and margin occurs outside the content box.body{
padding: 0
margin: 0
}
box-sizing:border-box
to layout elements to avoid the overflow of elements.div
elements will have different sizes because of padding applied to div2
. Since box-sizing
will set to content-box
by default (if not specified). Here, the height and width will be calculated by.border-box
value of box-sizing
to the rescue. This property allows us to include the padding and border in an element's total width and height.box-sizing: border-box
on an element, padding and border are included in the width and height.div2
has a property of box-sizing: border-box
. By setting this property, padding which you have applied earlier will be counted along with height and width of actual element. Here the height and width will be calculated by