CSS Flashcards
Trying to create the dotted line that links between a menu item and a price (restaurant style website) - how would you make this dynamic?
Use a div with a dotted border to fill the gap between the description and the price
What will the * selector target?
- {
}
Everything in the document
It’s possibly not a good idea in production code though as it adds too much “weight” to the browser
What does the following selector target?
#container * { }
Any element within a parent element that has the ID container
(Again - not a great technique)
What does the following selector target, and why should you avoid it as much as possible?
#container { }
It’s an ID tag, and you should avoid it as it is too rigid, and doesn’t allow for reuse. Try using a tag or a class.
What does the following selector target?
.container {
}
A class named “container”
What does the following selector target?
li a {
}
Any anchor (link) within an li element
What does the following selector target?
a {
}
All anchor tags on a page
What does the following selectors target?
a: visited { }
a: link { }
The link pseudo class is used to select any anchor that has yet to be visited (i.e. it’s just a link).
The visited pseudo class is used to select any anchor that has been visited.
What does the following selectors target?
ul + p {
}
The + selector only targets the first adjacent element that matches. I.e. in the given example, only the first paragraph AFTER an unordered list will be affected. (i.e. this is at the same level as the first item - it’s not referring to a child element)
What does the following selector target?
div#container > ul {
}
The first DIRECT ul decendantS of a div with id container.
NOTE: It does select other UL’s at the top level, not just the first. Also note that colors and things that inherit will appear to not be working because of course if you set the parent colour, the child ones will also get it.
div id="content" ul --This one gets selected ul -- This one does not get selected /ul /ul ul -- This one DOES get selected /ul /div
What does the following selectors target?
ul ~ p {
}
Very similar to the + operator, the ~ operator will select any p that is adjacent to the ul. However, unlike +, it will select all of them, whereas the + operator will only select the first one. (note - only p’s that come AFTER the ul).
What does the following selectors target?
a[title] {
}
Known as an attributes selector, this will only select anchors with an attribute named “title”.
What does the following selectors target? Why would this specific example be useful?
a[href=”https://haikusnack.com”] {
}
Only selects anchor tags that have a href with a value of https://haikusnack.com
- This could be useful if you wanted links to your own site to have a different colour than all other links. Of course - this is not exclusive to a href - there are many uses, this is just one.
What does the following selectors target? Why would this specific example be useful?
a[href*=”https://haikusnack.com”] {
}
Only selects anchor tags that have a href attribute that contains SOMEWHERE the value of “haikusnack”.
This is probably more useful than simply using the straight equality operator - since it’s rare that you want to affect a specific url, rather a range - i.e. any link that contains haikusnack within it.
What does the following selectors target? Why would this specific example be useful?
a[href^=”http”] {
}
This will select all anchor tags with a href attribute that begins with the string “http”. This can be useful for putting an icon on a page before a URL that indicates the link is offsite.
But of course, this can be used to capture any attribute on any tag.
What does the following selectors target? Why would this specific example be useful?
a[href$=”.jpg”] {
}
This matches any anchor tag with an href attribute that ends with the string “.jpg”.
Could be useful in doing something special with links that are images. NOTE - this can of course be used to match any attribute that you need.
What does the following selectors target? Why would this specific example be useful?
a[data-*=””] {
}
This is a custom “data-“ attribute selector. You can set the data- to be anything you require. This is useful because the attribute selectors can’t do multiple selection, so rather than doing that - you can add your own custom data attribute and select that. For example - you want to capture .jpg and .png -
Add a data-filetype attribute to the img element. Then give it the value of “image”.
a[data-filetype=”image”] {
}
This can now be used to select any image file type.
What does the following selectors target?
a[data-filetype~=”image”] {
}
The tilde character can be used to select an attribute with a spaced list of values. For example:
data-filetype=”image external compressed”
[data-filetype~=”external”]
would select this attribute.
What does the following selectors target?
input[type=radio]:checked {
}
This will only select a radio type of button that has been checked.
What does the :before and :after selectors do?
They produce content before or after the selected element.
i.e.
p:after {
content: “stuff”;
}
This would put the word “stuff” after the content WITHIN the p tag. NOTE: It does not put it after the end p tag.
What does the following selectors target?
div:hover {
}
It selects any div element that the cursor is currently hovering over.
Which is better to use?
border-bottom: 1px solid black;
or
text-decoration: underline;
border-bottom - it looks much better
What does the following selectors target?
div:not(#container) {
}
Selects all div’s that do not have the id container
What does the following selectors target?
p::first-letter {
}
The first letter in a paragraph
NOTE: This is called a pseudo element selector