Student Summer Sprint
  • Welcome to Hackathons for Schools Student Summer Sprint!
  • Event Information
  • What is the Student Summer Sprint?
  • Useful Event Information and Links
  • Schedule
  • Our Organisers, Panelists and Mentors
    • Organisers
    • Panelists and Speakers
    • Mentors
  • Project Details
    • Themes
    • Judging Criteria and Winning Teams
    • Presentation Advice
    • Submission Checklist and FAQs
  • Coding Platform and GitLab
  • Technical Workshops
    • How to Use Git
      • Git and the Terminal
      • How to use Git - The Basics
      • Branching, Merging and Other Useful Commands
      • How to use Git - Further Resources
    • Web Development
      • HTML
      • CSS
      • JavaScript
      • Web Development - Resources
    • Introduction to Python
      • Variables
      • Data Types and String Formatting
      • Input and Output
      • Conditional Statements
      • Functions
      • Libraries
      • CHALLENGES
        • Solutions
      • Learning Python - Resources
    • Discord Bots in Python
      • Discord Bots - Resources
    • Web Scraping in Python
  • Careers Advice and Opportunities
    • University Advice
      • University Advice - Further Resources
    • CV, Applications and Interviews
      • Creating a Great CV
      • UCAS Personal Statement Advice
      • Interview Hints and Tips
      • Ultimate LinkedIn Guide
      • Applications - Further Resources
    • Different routes into a tech career
      • Different Routes into Tech - Further Resources
    • What Now?
      • More Opportunities!
Powered by GitBook
On this page
  • How do I write CSS?
  • CSS Selectors

Was this helpful?

  1. Technical Workshops
  2. Web Development

CSS

CSS is a language that describes the style of an HTML document, used to define styles for your web pages: the design, layout and variations in display for different devices and screen sizes.

PreviousHTMLNextJavaScript

Last updated 4 years ago

Was this helpful?

How do I write CSS?

Writing CSS consists of a selector and a declaration box. We structure this by writing the selector and then putting the declaration block in curly brackets, as you can see in the example above. The selector is pointing to the HTML element that you want to style. These HTML elements are usually recognised by their tag name. In this example, it’s the heading, h1. The declaration block contains one or more declarations that are separated by semicolons. It’s good practice to have one declaration per line as shown above. Each declaration includes a CSS property name and value, separated by a colon.

It's good practice to keep your CSS in a separate file to your HTML. This means you can change the styling of your webpage without changing the HTML, all in one document. It makes your code much easier to read too, because you don’t have everything in the HTML file. You can link your HTML to your CSS one(s) by adding a link to the file in the <head> of each HTML file. There's an example below:

<head>
  <link rel="stylesheet" href="styles.css">
</head>

CSS Selectors

The CSS element Selector

The element selector selects HTML elements based on the element name. For example:

p {
 color: red;
}

The CSS id Selector

The id selector uses the id attribute of a HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element. For example:

#header1 {
 color: green;
}

The CSS class Selector

The class selector selects HTML elements with a specific class attribute. To select elements with a specific class, write a period (.) character, followed by the class name.

.header2 { color: blue; }

To learn more about CSS

https://www.w3schools.com/css/default.asp
CSS consists of a selector and a declaration box