1.6 CSS Selectors Flashcards
What’s the purpose of CSS selectors?
CSS selectors let’s us target HTML
by any of its attributes or values.
What are 3 types of CSS attributes?
FIT
- For
- ID
- Type
What 3 characteristics of attributes?
Attributes follow elements
Attributes add specificity
Attributes provide supplemental information
How do you target a class?
Use brackets on the selector
When you target by class, is it changing
attributes inside or outside of the class?
When you target by class, it only changes
those attributes with a class
How do you target a specific class?
specify the class by name
“form-contact” is a specific class within the CSS
Only this class is being targeted
How do you target by ID?
Use ID
Write specific ID name
How do you target by text?
What does the CSS rule do in this example?
Only input fields with values of text that receive the background color
How do you target a placeholder?
Specify placeholder
What is this CSS doing to the placeholder its targeting?
Only input fields with values of placeholder
that receive the background color
How do you target email field?
Specify email
What does the CSS rules do in this scenario?
Only input fields with value of email
that receive the background color
How do you target buttons with CSS attribute selectors?
Specify buttons
How do you target links?
use the a anchors
What is DRY CSS?
Dry stands for
Don’t repeat yourself
Why should you not repeat code?
It makes maintenance difficult
Increase style sheet,
browser works hard
Only define once
How to write more flexible, efficient code?
Create reusable attributes that can be
reapplied in needed areas without duplication
Why shouldn’t you use attribtue selectors?
Slower to interpret by developers
Slower to interpret by browsers
Why are reusable elements useful? Example?
It prevents duplication of identical code.
Example: border radius: adding a curve to border edges
How do you use reusable CSS snippets?
Create reusable class attributes
Add the classes to the HTML
Apply the class to any element that needs that style
In the following example, why do we have
the button attributes both joined and separated in the CSS?
Joined btn class: shared properties
Separated classes: unique properties of buttons
How do you create inline buttons on smaller devices?
Steps
- Add Media Query
- Add CSS
What does this code snippet do on smaller devices?
It makes the buttons appear below each other,
vertically, because of the block display method.
When it comes to combinators, what type
of children does the > combine?
The > combinator targets a direct child of an element
What element does the + combinator target?
The + combinator targets an element’s immediate sibling
What sibling is targeted with the ~ symbol in CSS selectors?
The ~ combinator targets all the specified siblings that follow an element
Given the use of the > symbol,
What type of combinator is this example?
Direct child combinator
What does this direct combinator do to anchor links?
Changes the font size to 14px
What symbol do you use to reach an immediate sibling?
The + combinator targets an element’s immediate sibling
What symbol do you use to reach all specified siblings?
The ~ combinator targets all the specified
siblings that follow an element
In this code snippet, what is happening in this adjacent combination? Scenario: two buttons are too close to each other
Leaving first button flush with content and the second and subsequent buttons have proper padding
How much margin is being applied through this adjacent combinator?
First button left aligned
Second button gets the left margin of 20px.
What does this sibling combinator do within the CSS?
What this does is it targets labels, under an H1 tag; it gives them the defined CSS style specified above
What is first element styling within CSS?
It’s applying CSS style, to the first item or element in a group.
Let’s say you have a list of 10 items.
You only want to style the 1st of the 10 items.
What property do you use with first child styling?
first-child
What symbol do you use to separate the HTML element from the first-child element?
: symbol separates both
In the CSS example, how is the first-element being styled?
background color is being set to a hexadecimal color
the font color is being set to white;
What does the last-child element styling do as a CSS attribute?
If you have a group of elements together, and you only want a special style applied to the very last item of the group, the last-child attribute helps you do just that
What separates the last-child element from the HTML element?
: symbol
Is there a space between parent and child attributes?
No.
No spaces between parent/child attributes
What does an only-child pseudo-class achieve?
The :only-child CSS pseudo-class represents an element without any siblings.
Why would you use an :empty element?
Prompt user to inform there isn’t anything there
In what 3 scenarios would it make sense
to use a :empty element?
A form field or order form or login screen
where the user forgot to input information.
How does this :empty element benefit end user?
Alerts them with a red color to a field they missed filling out, giving the end user form feedback
What is substrings?
Substrings= pieces
What does the begins with selector do?
Begins with Selector matches value
How do you summon the begins with? (symbol)
^ starts the begins with element
In this begins with example, what is being matched?
The http:// is signalling what it begins with, that’s what it’s matching content for
What 3 things happening in this specification value?
In the example, it’s
- targeting IMAGES
- with the TITLE
- that BEGINS WITH “product-”
When it comes to begins with or specifications,
do you use spaces in the syntax?
No
No spaces used
How is the ends with selector helpful?
It helps you style things by file extensions
Can you name 3 extensions that would be perfect targeting options for the ends with selector?
.jpg
.svg
What symbol is used to launch the ends with selector?
$ symbol starts with ends with selector
In this ends-with example, what is being selected?
images ending with .pdf
Based on this CSS snippet, what’s happening with the ends with selector?
It’s scanning for files that end with .pdf to give them an image to represent the file format of PDF.
What does the contain selector do?
It looks for the content that may contain at least one aspect of what you’re selecting for.
Why would you want to use the contains selector?
When you know the keyword or category of item you want to select specifically for styling.
In this example with contains selector,
what is the CSS styling doing?
- background-repeat: no-repeat;
- background-size: 18px 18px;
- padding-left: 25px;
What symbol do you use to initiate the contains selector?
* defines the contains selector
In this contains example, what element is being styled?
Image files with thumb in the file path received styling
What keyword is being styled with this contains selector?
files with lake are being styled
When should you use special selectors?
Use when you don’t have control over HTML because
of CMS limitations to access code