subject of css
subject of css
Selectors
- CSS Selectors
CSS selectors are used to “find” (or select) the HTML elements you want to style.
We can divide CSS selectors into five categories:
- Simple selectors (select elements based on name, id, class)Complex selectors (select elements based on a combination of different simple selectors)Pseudo-classes (select elements based on a certain state)Pseudo-elements (select and style a part of an element)Attribute selectors (select elements based on an attribute or attribute value).
Text
Oops! Click Regenerate Content below to try generating this section again.
background
It was looking pretty good right up until this point—until I messed up. I had copied the lines of code exactly as they were, but it wasn’t moving. I double-checked that the lines were present, and then checked to see if my CSS programs read them properly, but nothing changed! The question is: what went wrong?
It turns out that this is common among CSS beginners: they get frustrated when things don’t work exactly as they expect it should, which leads to unrealistic expectations on their part. When you use the same code for an element or text repeatedly, or at all for that matter, you need to remember that the computer is reading only your source code (the text), not the entire webpage. So if you have a line of code like “background-color:” 10px 20px #000;” , your browser will parse these lines from top to bottom: change “#000” into 10px 20px #000 .
In addition to letting you specify colors in HTML and CSS itself, one of these attributes also lets you define pixels or percentages for your background colors. You can set a color like the example above with six different values: 0%, 50%, 100%, 150%, 200%, and 300%.
color
background-color: #c8e2f4
border-color: #555
outline-color: #ccc
font
- font-style
- font-variant
- font-weight
- font-size/line-height
- font-family
- caption/icon/menu/message-box/small-caption/status-bar
link
The following code is an example of how the link tag in CSS can format a link to be different when it is visited, active, and hovered over.
list
Now that you know how to apply a style to an unordered list, let’s discuss how to style ordered lists. The same properties apply for ordered list and unordered list such as the color, font, line height and background color. But some of the other properties are different for example:
- list-style-type
- list-style-image
- list-style-position
table
- table – the container of a table
- tr – the container of a row
- th – each cell that is to be a header within a table
- td – each cell that is to be just an ordinary data cell within a table
- caption – the title or explanation of your table, usually at the top. You can omit this if you don’t have any need for it.
- col – defines one column within your table (you use this when you want to define attributes for whole columns)
- colgroup – defines a collection of columns within your table (like when you want to define attributes for more than one column.)
- tbody – used with larger tables where there may be multiple body sections. It allows styling and scripting to be applied differently to different sections of the document. It is not necessary, but can make things easier in some circumstances.
- thead – used with larger tables where there may be multiple headings at different places in the document. It allows styling and scripting to be applied differently to different sections of the document and defines what information should appear at the top for scrolling purposes. It is not necessary, but can make things easier in some circumstances.
- tfoot — used with larger tables where there may need to be multiple footers at different places in the document and defines what information should appear at the bottom for scrolling purposes. It is not necessary, but can make things easier in some circumstances.
border
The border property is a shorthand for setting the width, style, and color of an element’s border.
margin&padding
Margin and padding are the two most commonly used properties for spacing-out elements. They both function very similarly, and can be a bit confusing at first. In this section we will go over the difference between the two properties, and some techniques for using them.
We’ll begin with an example of how to use margin. Margin is used to create space around elements, outside of any defined borders. An element’s margin is transparent, letting whatever is behind it show through:
subject of css
Oops! Click Regenerate Content below to try generating this section again.