vacant's profile picture

Published by

published
updated

Category: Web, HTML, Tech

Comprehensive Guide to Layout Building #1 [ Setting up developer environment & understanding specificity ]

Since the layout section has been closed indefinitely, I have taken it upon myself to start a blog on how to construct your own layouts. This first entry will cover the following topics for people in between a beginner and an intermediate to understand:

  1. How to set up an IDE and the benefits of it.
  2. Using browser developer tools to expedite development.
  3. Understanding CSS specificity.

Once you understand all of these concepts, you will be able to use commonly referred-to resources like MDN Web Documents or W3Schools much more effectively. 

Setting Up Your Developer Environment


To start this section off, I must clarify that the SpaceHey edit page is not an IDE; it has no syntax highlighting, doesn't give you any error warnings, and is all-around horrible to work with. To remedy this, I will discuss how to set up an integrated developer environment for developing SpaceHey layouts.

Replit - Browser based IDE

If you don't want to go through the hassle of installing Node and Visual Studio Code, then you can try Replit. You can get it set up really fast on your web browser; just follow these steps:

  1. Go to replit.com.
  2. Login or Create an account.
  3. Start a new project with this template:Screenshot-2024-07-18-6-21-07-PM
  4. Go to your profile and do this:
    1. Press CTRL + S 
    2. When your file explorer opens, choose this option on the operating system you're using. (Save as Web page, HTML only)Screenshot-2024-07-18-6-33-14-PM
  5. Now go to your project and do this
    1. Click your project file explorer's drop-down and upload the HTML file.image  
    2. Delete index.html and rename the file you just uploaded index.html.
  6. Once you're done doing this, your workspace should look like this:Screenshot-2024-07-18-6-36-10-PM
  7. Add <link src="style.css"> inside of the <head> tag in index.html.image

Once you're done setting up your workspace, any edit to your CSS file should update your viewport on refresh.

Visual Studio Code - Dedicated IDE

Visual Studio Code takes a little more effort, but it allows for offline editing and the use of extensions to improve the developer experience. To set it up, do the following:

  1. Download VSC. (Obviously)
  2. Make a new directory as your workspace.
  3. Get the live server extension.
  4. Do step number 4 for the Replit guide and put the HTML file in your workspace.
  5. Create style.css.
  6. CTRL + SHIFT + P while focused on your HTML file, and type in "Open with live server" into the command palette.
  7. It should open your web browser with your page rendered automatically.
  8. Do step number 7 for the Replit guide in your HTML file.

Remember that you need to CTRL + S to save your changes in your CSS file.

Devtools


Another way to improve your experience is to use embedded tools in your browser to help expedite your layout's development. This developer console can be opened via CTRL + SHIFT + C or CMD + OPT + C.

Using this can help with finding methods of referencing certain elements you want to target. The contents of this section will consist of tips on how to live-edit elements and find CSS selectors for the element you want to edit.

Editing CSS Rule Parameters & Error Detection

If you want to find out what's wrong with your targeted element or adjust values on the fly, then you can use the styles subsection of your devtools to do this.

  1. Select the element you want to adjust.Screenshot-2024-07-19-5-29-01-AM
  2. Press this to get your selector & live edit ability.Screenshot-2024-07-19-5-29-53-AM
  3. Check for errors or get creative before putting something down.Screenshot-2024-07-19-5-33-41-AM

Super short section, there's a little more to the inspector but you don't need to worry about it.

CSS Specificity


The basis for doing anything with CSS is understanding how selectors work and how to use them to target elements. The first thing you need to understand is specificity and how to increase it.

When you're making a layout for SpaceHey, you need to understand that you are actively fighting the pre-existing style rules to change how your profile looks. When you're doing this, you will need to override the already existing rules using specificity to clash over the element's style rules.

image

In your IDE and devtools, this tooltip can be seen when hovering over style rules. This is your element's specificity; each number displayed is there to indicate what your style rule's specificity scores. The following is what each value indicates:

(ID SCORE, CLASS SCORE, TYPE SCORE)

In the above example, the rule I'm using is just html. Since this consists of only one type, it scores 0-0-1. What this means is that if anything has a better score for this element (i.e., 1-0-1/0-0-2), then it will take rendering priority.

image

So for an example, the contact box is tricky to fully style due to it having a decently high specificity and !important declarations. image

If you wanted to change the opacity or display property of this element, then you would need to match it's specificity by using the same  .profile .contact  selector shown above. 

image

Now the contact section has a display of flex instead of inherit.


Alright that's all I can muster for now, expect another blog soon where I dive into display and position properties and how they can be used for complex layouts. Hopefully I'll have it done by either Monday or Tuesday.


52 Kudos

Comments

Displaying 5 of 5 comments ( View all | Add Comment )

vacant

vacant's profile picture
Pinned

New entry:

https://blog.spacehey.com/entry?id=1223906


Report Comment

pocono

pocono's profile picture

tysm for making this !!!


Report Comment

Cosmic Lush

Cosmic Lush's profile picture

Amazing guide. I was fighting with this for a minute giving up because the normal code I was using wasn't working. Thankfully, now I know. Thank you a lot I appreciate it


Report Comment

Hydras Bloom

Hydras Bloom's profile picture

instant Kudos to you, i loved it, esp about IDE of editing your page, no more will i have to go into the editior, do someting, save it and then look at the page and see that somethings up and then have to do it all over again.

i cant wait for your second entry bub :D


Report Comment

not_ian

not_ian's profile picture

this must be taking so much time for you to make, thank you SO MUCH.


Report Comment



I would say no problem but I HATED uploading every image and pasting it in lol

by vacant; ; Report

the dark side of frontend development lololol

by not_ian; ; Report