You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
6.8 KiB

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My Learning Website</title>
<link href="/styles/styles.css" rel="stylesheet" type="text/css">
<link href="styles/homepagestyles.css" rel="stylesheet">
<link href="/webdevelopment/styles/styles.css" rel="stylesheet" type="text/css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="banner">
<h1 class="courselink">Introduction to CSS</h1>
<h2 class="lecturer">LinkedIn Learning : Carrie Dils</h2>
<h2 class="episodetitle">Working with CSS</h2>
</div>
<article>
<h2 class="sectiontitle">Organizing CSS</h2>
<p>Although it is important to write CSS that is correct, it is also a good idea to keep it readable and there are a few ways to do this.</p>
<p>As with a programming language such as Java or C, it is important to include comments, especially when it is not immediately obvious why you are applying a rule. You should also ensure that you are naming things in a consistent manner. There is an interesting blog post on this on the webdevstudios.com site under the name of <a href="https://webdevstudios.com/2017/03/28/evolution-css-class-naming-methodologies/">Evolution of CSS: Class Naming Methodologies</a>, by Damon Cook (March 28 2017).</p>
<p>Consistently formatting your code is important as well, because it makes CSS much easier to read. The format that I prefer is to have the selector followed by a space and then the opening curly brace on one line. The rules associated with the selector follow on subsequent lines and are indented by one tab. The closing curly brace then goes on its own on the last line. This will look something like</p>
<pre class="inset">
.main_grid {
display: grid;
grid-template-columns: 25% 25% 25% 25%;
grid-template-rows: 25% 25% 25% 25%;
margin: 30px;
grid-gap: 10px;
padding: 10px;
height: 300px;
}</pre>
<p>Another useful trick, which is not one I have used myself, is to organise your CSS rules according to the page flow. That is, rules applying to the header go first, rules applying to the footer go last and so on, so the order of the rules is similar to the order of the elements in the HTML code. Personally, I prefer to group rules by selector type so all the rules applying to classes go together, all rules applying to ids go together and all rules applying to elements go together. I don't follow this religiously, but one practice I do try to be consistent with is to keep the more general rules at the top since these apply more widely and will probably be changed more often.</p>
<p>It may be worth noting that if you need to find a rule for a particular element or class, its easy enough to do that. On the other hand, if you need to find out what rules are being applied to a particular element, say a &lt;p&gr; element, it may be easier to find these if your CSS is well organised.</p>
<p>One practice that helps to keep your CSS organised that I do follow is to split up your CSS into different files. For example, I have one file to cover site rules, one to cover web development rules (rules applying to any web development pages) and so on. This is useful because having all of your code in one file can lead to a very large and messy file. Also, I mentioned before that I like to have different colour schemes for different topics, Web Development, Linux and so on and having a stylesheet just for these pages means that it is easier to apply styles on that basis. It also makes it easier to know, when there is a conflict between rules, which one is going to be applied. In general, I want to put some styles that apply to my whole site in one file and styles that only apply to Web Development pages in another file. In some cases, I may want to override a rule that I have in the site stylesheet so having different files can be useful here.</p>
<p>These are the stylesheets currently linked to this page.</p>
<p class="inset">&lt;link href="/styles/styles.css" rel="stylesheet" type="text/css"&gt;</p>
<p class="inset">&lt;link href="/webdevelopment/styles/styles.css" rel="stylesheet" type="text/css"&gt;</p>
<p>The first of these applies site wide and the second applies only to Web Development pages. Since it comes last in this short list, it means that where there is a conflict, it is the rule in the Web Development stylesheet that will be applied since it is the last sheet in this list.</p>
<h2 class="sectiontitle">Maintaining CSS with Version Control</h2>
<p>This course doesn't provide any help in terms of using version control. It really just mentions it in passing and points out that Git is the most popular version control system. It also mentions that there are some graphical tools for managing Git which I wasn't aware of but I do know that Dreamweaver can be integrated with it. I haven't really looked into doing this yet but it is definitely a useful tool and a worthwhile skill to have.</p>
<h2 class="sectiontitle">Using Browser Inspection Tools</h2>
<p>Again, the topic is just touched on briefly, but I am already quite familiar with these although I probably don't use them as often as I should. Including this section in the course, for me, just serves a reminder that this is a tool which can be very useful and is worth becoming more familiar with.</p>
<h2 class="sectiontitle">Validating CSS</h2>
<p>There are a number of online CSS Validators available, the most popular probably being the <a href="https://jigsaw.w3.org/css-validator/validator">W3C CSS Validation Service</a>. I don't use this very often. I will usually validate my CSS if there seems to be a problem with it that I can't trace. However, if you are writing CSS in a professional capacity, it is more important that you validate your CSS before releasing it.</p>
</article>
<div class="btngroup">
<button class="button" onclick="window.location.href='layouts.html';">
Previous Chapter - CSS Layouts
</button>
<button class="button" onclick="window.location.href='responsive.html';">
Next Chapter - Responsive CSS
</button>
<button class="button" onclick="window.location.href='introductiontocss.html'">
Course Contents
</button>
<button class="button" onclick="window.location.href='/webdevelopment/webdevelopment.html'">
Web Development Page
</button>
<button class="button" onclick="window.location.href='/index.html'">
Home
</button>
</div>
</body>
3 months ago
</html>