Revamped the CSS for the blog

Published: 2020-07-06 | Last Updated: 2021-02-02 | ~7 Minute Read

Reason

Lately I have been working on several web projects as practice for programming / web development. As part of those projects I have been looking for a way to write the CSS for them following the KISS principles.

I know that there are amazing and fully fledged CSS frameworks like Bootstrap or Bulma but since I consider myself still a learner and not a full fledged developer, I try to stay away from them. I feel like learning how to use the frameworks won’t help me learning CSS itself.

Initial struggles

One thing I had been having issues with was coming to terms with some sort of standard to use for the CSS in my projects. It was kind of hard to determine what should go first, what second, etc. I had tried to come up with different methods of my own as far as convention and syntax, but it was hard to remember from project to project.

The alternative

A friend with whom I was working with on my last project shared an interesting CSS project, Basic.css. I took a look and immediately thought it was a perfect way to do CSS for all of my projects.

I really like the simplicity and usage of variables in CSS, I did not know vanilla CSS could do that, I’m guessing the SASS folks didn’t either? :P

Using the Basic.css core and then making my own tweaks to it, I came up with my own base CSS style file. In the future all I have to do is write minimal CSS for specific parts of whatever project i get to work on, and I’ll have consistent and KISS compliant CSS.

I feel like the flexibility is amazing, and I’ll only write CSS that is actually used, instead of having 95% of a framework’s features unused and their code taking up space unnecessarily.

Updating the CSS for this blog

I decided that as part of adopting the Basic.css project’s methodology / base, I could not go one more day without updating the CSS that I had written for this blog.

When first creating the blog I had every intent to revisit the CSS I had written and polishing it up a bit, however I never did. While doing it now, I noticed just how much repetitive and unnecessary CSS I had laying around. I’m definitely glad that I got around to doing this.

Positioning in the blog

I didn’t have any type of layout on the blog, so I decided to use CSS Grid since I really like it’s simplicity. I had manually set the positioning for each element previously which was far from ideal, so this way the CSS is cleaner and easier to manage.

The lines that I ended up adding to the CSS for the Grid layout are the following:

/*===========================================
=============    GRID LAYOUT  ============
===========================================*/
body {
    display:                            grid;
    grid-template-columns:              1fr 50% 1fr;
}
header {
    grid-column:                        1 / 4;
    grid-row:                           1;
}
nav {
    grid-column:                        1 / 4;
    grid-row:                           2;
}
main {
    grid-column:                        2;
    grid-row:                           3;
}
footer {
    grid-column:                        2;
    grid-row:                           4;
}

With that and the addition of semantic HTML, I was able to achieve the same result as before in regards to layout (no classes or IDs used).

Using CSS Variables

After that was set up, I went on to setting up the :root CSS pseudo-class variables, thank you Basic.css for introducing me to this. This is the end result:

:root {
--sans:                             1em/1.6 system-ui, "Signika Negative Regular", -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Droid Sans, Helvetica Neue, Fira Sa
sans-serif;
--mono:                             'Courier New', Courier, 'Ubuntu Mono', 'Liberation Mono', monospace;
--main-font-color:                  #676767;
--heading-color:                    #333;
--pre-back-color:                   #f5f7f9;
--pre-font-color:                   #4c4c4c;
--pre-left-border-color:            #69c;
--pre-top-bottom-border-color:      #d8dee9;
--code-font-color:                  #518DAA;
--link-color:                       #6262ff;
--link-hover-color:                 #00b200;
--dark-color:                       #444;
--black-color:                      #000; 
--light-gray-color:                 #eee;
--white-color:                      #fff;
--h5-color:                         #a7a7a7; 
--rc:                               8px; 
}

Now if I want to make general color changes to the site, I can do so from a central place instead of having specific color hex codes throughout the CSS file, this makes it easier to maintain.

Adding Responsiveness

This is something that I had initially not done, however the use of CSS Grid makes it really simple to accomplish.

With the following lines of CSS I added very general support for smaller screens to the blog:

/*===========================================
=============   MEDIA  QUERIES  ============
===========================================*/
/* Tablet Sized Screens */
/* Grid Layout */
@media (max-width: 1200px) {
body {
    display:                grid;
    grid-template-columns:          1fr 70% 1fr;
}

/* Navigation Bar */
nav ul {
    padding-left:               11%;
}
}

/* Mobile Sized Screens */
/* Grid Layout */
@media (max-width: 599px) {
body {
    display:                grid;
    grid-template-columns:          1fr 90% 1fr;
}

/* Navigation Bar */
nav ul {
    padding-left:               0;
}
nav ul li a {
    padding:                .7em .5em;
}

Admittedly I need to work on the navigation bar of the site for better integration with the CSS Grid layout, I’ll be doing that soon. Once I have that implemented only CSS layout code will be added to the media queries section of the style.css file.

Conclusion

With these simple updates I have now written a CSS file that I’m happy with and can continue to use until the next update comes around.

Have a comment on one of my posts? Start a discussion in my public inbox by sending an email to ~grokkingnix/blog@lists.sr.ht [mailing list etiquette] [mailing list archive]


Posts from blogs I follow:

Introducing a Falkon extension RSS Finder

This weekend I decided to semi automate the process of searching for RSS feeds on websites while using Falkon web brosers. Many websites provide RSS feeds but do not provide any visible link or icon to access them (eg. many Wordpress based sites) and I ha…

via My land January 23, 2022
Help Chile write free software values, privacy, and digital sovereignty into their constitution

For those out of the loop, a group which included myself up until recently,1 Chile is in the midst of a revolution. They’re fighting against the increased cost of living, privatization of essential services, and worsening inequality — problems facing everyon…

via Drew DeVault's blog January 19, 2022
A warning to business owners and managers, you are a big part of the problem!

In my last couple of articles, mainly So-called modern web developers are the culprits and Is the madness ever going to end? I have written about some of the major problems with so-called modern web development and I have addressed the issues to the devel…

via unixsheikh.com January 13, 2022

Generated by openring