Weekly Webtips
Published in

Weekly Webtips

Useful CSS Tips for Beginners

stylesheet
Photo by Pankaj Patel on Unsplash

Use a Reset

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>CSS Sandbox</title>
</head>
<body>
<div class="header">
<h1 class="title">Title</h1>
<p class="description">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tenetur repellendus debitis necessitatibus fuga natus ut eos, recusandae consequuntur suscipit saepe.</p>
</div>
</body>
</html>
“user agent stylesheet” simply means default
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

Targeting Elements

h1 {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 60px;
margin: 20px 0;
}
.title {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 60px;
margin: 20px 0;
}
.header .title {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 60px;
margin: 20px 0;
}
.header > .title {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 60px;
margin: 20px 0;
}

Set Variables

:root {
--primary-color: blue;
--secondary-color: orange;
}
.header .title {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 60px;
margin: 20px 0;
color: var(--primary-color);
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alex Mata

Alex Mata is a software developer located in Houston, Texas. He plays D&D and listens to vaporwave whenever he isn’t solving problems through coding.