The CSS for this box is:
selector{
width: 500px;
height: auto;
border-style: solid;
border-color:#F60;
border-width: 2px;
padding: 20px;
}
Individual sides can be written for top, right,bottom, left:
border-left-style: solid;
BORDER: The border is the red outline around this box. The border style is solid which creates a single line around the box.
PADDING:
The padding is the space between the text (or other content) and the border.
WIDTH:
The original width of the box was 500px but once borders and padding are added the box gets wider:
500 width
004 borders left and right
040 padding left and right
_______
544 total width of the box
In IE6 (I know why bother) the width remains 500px and the content area is reduced in size as you include borders and padding.
HEIGHT: The height is set to auto and it will expand depending upon the content.
f you wish the height to be a 100% you would also need to attribute100% to both the body and the html:
The following box has a left margin. Margins are between elements and do not effect the size of the box.
margin-left: 20px;
border-style: double;
border-style: dashed;
The appearance of the following borders does not work well in most designs and can be displayed differently in some browsers.
They also look rather tacky.
border-style: groove;
border-style: ridge;
border-style: inset
border-style: outset;
Collapsing Margins
Two touching margins with positive values
When there are two vertical elements with touching margins then the margins collapse (combine to form a single margin) and take on the size of the larger margin
.
Two touching margins with negative values
Take on the margin with the highest value
Two touching margins, one with a positive value and another with a negative value: margins are added together to get the final value
Collasping margins do not apply to the following:
- absolutely positioned elements
- floated elements
- inline-block elements
Outlines
You cannot define a side (left, right, top, bottom) for an outline. An outline is always on all sides
Outlines do not increase the size of the box or really take up any space.
Both of the boxes below have a margin-left of 20px. The outline is actually in part of the margin area.
If I only include one break below this text the outline will cover part of the text.
The blue area is the outline
margin-left: 20px;
Without outline
margin-left: 20px;
Visibility
When using the box as a main layout element how do you get your text to stay in the box. the easist way to do this is to just give to this:
selector{
height: auto;
}
Overflow Property
The values for the overflow propertiy are: visible, hidden, scroll, auto
selector{
overflow: visible;
}
visible
If give your box a height this value insures that all of the content will show even if it is more than the height of the box. The content will overlap beyond the box.
selector{
overflow: visible;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempus tempor sem, in pulvinar massa eleifend ornare. Sed sit amet feugiat est. Quisque suscipit purus vitae augue viverra ornare.
hidden
Any additional content that takes up more space than the boxes height is cut off
selector{
overflow: hidden;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempus tempor sem, in pulvinar massa eleifend ornare. Sed sit amet feugiat est. Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac augue turpis, id laoreet nulla. Aliquam erat volutpat. Vestibulum nec tortor augue. Vivamus euismod tincidunt pellentesque. Nulla id nunc id elit blandit varius vel sit amet tellus.
Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula.
scroll
This value allows the content to scroll
auto
This value is browser dependent and could cause the content to scroll
selector{
overflow: auto;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempus tempor sem, in pulvinar massa eleifend ornare. Sed sit amet feugiat est. Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac augue turpis, id laoreet nulla. Aliquam erat volutpat. Vestibulum nec tortor augue. Vivamus euismod tincidunt pellentesque. Nulla id nunc id elit blandit varius vel sit amet tellus.
Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula.
height auto - do not include the overflow property
If you just want the box to get bigger to accommodate the content then do not
include the overflow property in the styles and place the height of the box at auto
selector {
height: auto;
}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur tempus tempor sem, in pulvinar massa eleifend ornare. Sed sit amet feugiat est. Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac augue turpis, id laoreet nulla. Aliquam erat volutpat. Vestibulum nec tortor augue. Vivamus euismod tincidunt pellentesque. Nulla id nunc id elit blandit varius vel sit amet tellus.
Quisque suscipit purus vitae augue viverra ornare. Praesent magna est, ultricies eu commodo facilisis, facilisis sit amet ligula.