CSS Flashcards
What are the three types of CSS
Inline CSS
Inline CSS contains the CSS property in the body section attached with element is known as inline CSS. This kind of style is specified within an HTML tag using style attribute.
Internal or Embedded CSS
This can be used when a single HTML document must be styled uniquely. The CSS rule set should be within the HTML file in the head section i.e the CSS is embedded within the HTML file.
External CSS
External CSS contains separate CSS files which contains only style property with the help of tag attributes (For example class, id, heading, … etc). CSS properties written in a separate file with .css extension and should be linked to the HTML document using link tag. This means that for each element, style can be set only once and that will be applied across web pages.
This can be achieved by using <link></link> tag. The <link></link> element has rel and href attributes. The rel specifices the relationship between the current document and the linked document.
<head>
<link></link>
</head>
If an inline style conflicts with a style from an external stylesheet, the style from the stylesheet will be used
False
The inline style trumps
Describe the CSS box model
The CSS box model used to determine how our web page is rendered by browser. It considers each element on the page as a box, CSS allows you to apply different properties that define where and how that element appears. Web pages are made up of rectangular boxes arranged and related to each other.
what are the 4 parts ?
very box has 4 parts - margin, border, padding and content. The margin is the outermost box, then the border, then padding, then finally content is innermost. All box sizes/formatting can be styled with CSS.
Margin - It is outermost. It is useful to separate the element from its neighbors. The dimensions are given by the margin-box width and the margin-box height.
Border - It is the area between the box’s padding and margin. Its dimensions are given by the width and height of the border.
Padding - It is a space around the content area and within the border-box. Its dimensions are given by the width of the padding-box and the height of the padding-box.
Content - It consists of content like text, image, or other media content. It is bounded by the content edge and its dimensions are given by content-box width and height.
CSS Border Property
The CSS border property allows to style the border area of a box. The properites and corresponding vlaues with examples covered under the CSS border are tabulated below
border-width medium, thin, thick, length
border-style none, hidden, dashed, dotted, double, groove, inset, outset, ridge and solid
border-color hex-value for colors
CSS Margin Property
The CSS margin property is similar to the CSS border property, but it sets the margins around the sides of an element’s box instead of the border. It also takes one, two, three, or four values separated by white spaces. The shorthand properties are margin-top, margin-right, margin-bottom, and margin-left to set a margin on respective sides.
p {
margin-left: 10px;
margin-right: 30px;
}
h1{
margin: 25px 50px;
}
CSS Position Property
The position property defines how an element will be arranged on a page. The Syntax for the position property is selector {position: value}. The property values are static, relative, absolute, fixed, or inherit.
static - The element’s box is arranged automatically consistent with the normal flow.
relative - The element’s box position is relative to its normal flow position. You can adjust the normal flow position by using the top, bottom, left and right properties.
absolute - The element’s box arranged to an absolute position with reference to its containing block. Its containing block is that the nearest ancestor element that has its position property set to relative, absolute, or fixed. The top, right, bottom, and left properties are used to set the offset of the element’s box with reference to its containing block.
fixed - The element’s box position is offset from its browser window by using the top, right, bottom, and left properties. The element’s box won’t move when the browser window is scrolled.
inherit - The inherit keyword is employed to specify that the value for this property should be taken from the parent element. If inherit is used with the root element, then the initial value for this property is going to be used.
CSS Color property
The color property is used to specify the foreground color of text.The color properties are set using 5 different color notation types which is listed below:
a {color: red;}
div {color: #3c5;}
h1 {color: #ffa500;}
div {color: rgb(100,20,255);}
#id1 {color: rgb(30%,50%,70%);}
CSS text-align property
The text-align property is used to align the content inside the element. The text inside the element can be aligned in 4 ways - left, right, center and justify.
What is a responsive web design
Responsive Web design is the approach that allows websites and pages to render (or display) on all devices and screen sizes by automatically adapting to the screen, whether it’s a desktop, laptop, tablet, or smartphone. Responsive web design works through CSS, using various settings to serve different style properties depending on the screen size, orientation, resolution, color capability, and other characteristics of the user’s device. It is a combination of flexible grids, flex boxes, flexible images, and media queries.
Class Selector
In CSS, the class selector is a name preceded by a period (“.”). It uses the class attribute of an HTML element to match the specific HTML element. We can have a Class selector specific to an HTML element
ID Selector
The ID selector is a name preceded by a hash character (“#”). It uses the id attribute of an HTML element to match the specific HTML element. The id of an element should be unique within a page, so the id selector is used to select one unique element.
What is the adjacent sibling selector
An adjacent sibling combinator selector allows you to select an element that is directly after another specific element.
What is the general sibling selector
The general sibling combinator selector is very similar to the adjacent sibling combinator. The difference is that that the element being selected doesn’t need to immediately succeed the first element, but can appear anywhere after it.
Element Selector
The element selector selects HTML elements by their name / tag name like a, h1, div, p etc.
The element selector is a way to select all the elements with a given tag name in a document, and apply the same styles to each element with the tag name.
Note that you should only write the tag name, and not write brackets around the tag name — h1,
p {
text-align: center;
color: blue;
}