Full Stack Web Devlopar - Part 005 _CSS-EP2

Full Stack Web Devlopar - Part 005 _CSS-EP2

By DR-9 | How To Start Making Websites | 22 Mar 2020


Styling your first web page!

 

Creating directory

At first we should create a file,

where we are going to store our website

and then, put our index.html file in there.

Then, in that folder create file called style.css

So this should now be content of our folder:

351665157-98b8876e007cdace7d6b9c6e6dad2b643b799c39bd4a3cec5f734b2122da9832.png351665157-d40b98c99b2b7bed31781f88724275a053b60f3cd5598ef2e1faf543e1479078.png

 

Opening our website folder in VSC

Open VSC,

then go to File > Open Folder.

Or simply do CTRL + O + K.

And select your folder.

Now that it's opened you will see something like this.

351665157-56fd80b31fff1fd719eaa3561ea517c22c3b5ad77be69ac319c1e413d3910309.png

On the left you see the folder directory.

Click on index.html and it will open the file.

 

Then add this line like this:

351665157-28c7d5eab236db6787f677813c7ac5b8617dc0f396572baee1102b2c548f8ec2.png

You have now successfully linked your styles to your website.

The tag link means we are linking something, rel="stylesheet" tells HTML it's a styles file.

And href is linking to directory of file.

If the file was stored in styles directory called css,

the link would look like this href="css/style.css".

Now let's open the style.css file.

 

Getting our hands dirty!

Okay now.

We target HTML elements in CSS by writing their name in file.

In HTML document we have a heading of level 1 saying Hello World?

To target it in CSS we then write the name

of the element followed by curly brackets.

Like this:

351665157-3ca6ed4bb7c26cc77fa8188b29625e88807d94ff0bf438ddb3d307a211b239f1.png

 

Inside the curly brackets we type:

351665157-e012c12c43c9cf690d57333274b25fd2905c7519f0c6c561d1bf8dda6e8678d3.png

which changes color of our text to yellow

and size of the font to 100px.

For colors you can use rgb(0, 0, 0) values or hex code #151e27.

And instead of pixels for text size you can use percentage, em, rem.

These make the text kinda responsive as we resize the window of browser.

 

Seeing the result

Now we open our index.html file in our browser.

Or if you already have it opened just refresh the page.

You need to refresh every time you want to see a change you made in HTML or CSS.

So our website looks like this now:

351665157-260970966b145101337037e38195c46b64d4bdf90e4c23b8bdb1b19c2db1fb35.png

 

Now, what if you don't like it?

Well change it..

Let's change color of the background.

To target background we use the body tag

because the actual content is inside it.

Meaning body is outside and background is indeed outside the content.

Think of this as layers.

Then we just type - background-color: black;

It is important to finish every styling element with ;

 

My CSS looks like this:

351665157-0019f94b6cc5e9bdb5a10ec871b2a07071ff7eeb69efa9d38e09bd48c2caf4bf.png

I also added color values differently.

Hex code in BG color and RGB in h2 tag.

Then I used text-align to center text.

You can also use it to align text to left, or right.

 

My html now looks like this:

351665157-d41e14c4b6a93761949726ea1f4c9fe25c116dd4bef1d31d9360d0ea3517ddd1.png

I added heading of second level.

Which is a bit smaller than h1.

 

So final website now looks like this

when opened in browser:

351665157-5fd6cdf2a3479d67853841fa7afff5c8ac575065f4b377b1cbb5b497c1079449.png

 

In next lesson we will add some blocks

with paragraphs of text and some images.

 

Until then,

I'm out, peace!

How do you rate this article?

1


DR-9
DR-9

Hi all. My name is Daniel.


How To Start Making Websites
How To Start Making Websites

So you decided to create websites... I will tell you where to start, what documentation / resources helped me personally and a lot more.

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.