CSS Margins: Margin - Individual Sides
CSS Margins: Margin - Individual Sides
The CSS margin properties are used to generate space around elements.
The margin properties set the size of the white space outside the border.
With CSS, you have full control over the margins. There are CSS properties for setting
the margin for each side of an element (top, right, bottom, and left).
• margin-top
• margin-right
• margin-bottom
• margin-left
The following example sets different margins for all four sides of a <p> element:
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
p {
margin: 100px 150px 100px 80px;
}
• margin: 25px;
o all four margins are 25px
AUTO MARGIN
You can set the margin property to auto to horizontally center the element within its
container.The element will then take up the specified width, and the remaining space will
be split equally between the left and right margins:
div {
width: 300px;
margin: auto;
border: 1px solid red;
}
INHERITED MARGIN
This example lets the left margin be inherited from the parent element:
div.container {
border: 1px solid red;
margin-left: 100px;
}
p.one {
margin-left: inherit;
}
Margin Collapse
Top and bottom margins of elements are sometimes collapsed into a single margin that is
equal to the largest of the two margins.
CSS Padding
The CSS padding properties are used to generate space around content.
The padding clears an area around the content (inside the border) of an element.
With CSS, you have full control over the padding. There are CSS properties for setting
the padding for each side of an element (top, right, bottom, and left).
• padding-top
• padding-right
• padding-bottom
• padding-left
The max-width can be specified in length values, like px, cm, etc., or in percent (%) of
the containing block, or set to none (this is default. Means that there is no maximum
width).
The problem with the <div> above occurs when the browser window is smaller than the
width of the element (500px). The browser then adds a horizontal scrollbar to the page.
Using max-width instead, in this situation, will improve the browser's handling of small
windows.
It's resizing!
• 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
Total element width = width + left padding + right padding + left border +
right border + left margin + right margin
Total element height = height + top padding + bottom padding + top border
+ bottom border + top margin + bottom margin
Outline Style
The outline-style property specifies the style of the outline.
p {
border: 1px solid black;
outline-color: red;
}
outline-offset Specifies the space between an outline and the edge or border of an
element
direction: rtl; (ltr left to right) Specifies the text direction/writing direction
unicode-bidi Used together with the direction property to set or return whether the text
should be overridden to support multiple languages in the same document
letter-spacing:3px;
FONTS
• generic family - a group of font families with a similar look (like "Serif" or
"Monospace")
• font family - a specific font family (like "Times New Roman" or "Arial")
body {
font-size: 100%;
}
h1 {
font-size: 2.5em;
}
h2 {
font-size: 1.875em;
}
p {
font-size: 0.875em;
}
To allow users to resize the text (in the browser menu), many developers use em instead of pixel
1em is equal to the current font size. The default text size in browsers is
16px. So, the default size of 1em is 16px.
h1 {
font-size: 2.5em; /* 40px/16=2.5em */
}
h2 {
font-size: 1.875em; /* 30px/16=1.875em */
}
p {
font-size: 0.875em; /* 14px/16=0.875em */
ICONS
Add the name of the specified icon class to any inline HTML element (like <i> or <span>).
BOOTSTRAP ICONS
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstra
p.min.css">
GOOGLE ICONS
<link rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons">
<i class="material-icons">cloud</i>
<i class="material-icons">favorite</i>
<i class="material-icons">attachment</i>
<i class="material-icons">computer</i>
<i class="material-icons">traffic</i>
Links
The four links states are:
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 14px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
CSS Tables
table {
border-collapse: collapse; Da se stope okviri tabela
}
table, th, td {
border: 1px solid black;
}
table {
border-collapse: collapse;
border: 1px solid black;
}
td {
height: 50px;
vertical-align: top;
text-align: center;
tr:hover {background-color: #f5f5f5}
tr:nth-child(even){background-color: #f23412}
za striped tabele