Styling Our App

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 264:- Styling Our App

To style our app, we can add CSS to our HTML files. We can either write CSS directly in the HTML file or link an external CSS file. Linking an external CSS file is a more organized approach and makes it easier to make changes in the styling.

Here's how to link an external CSS file to our Express app:

  1. Create a new folder named public in our project directory. This is where we will keep all our static files, including CSS, images, and client-side JavaScript files.
  2. Inside the public folder, create another folder named css.
  3. Create a new file named style.css inside the css folder. This is where we will write our CSS code.
  4. Open the style.css file and add some CSS code. For example, we can set the background color of the body to blue:

cssCopy code

body {  background-color: blue; }

  1. In our Express app, add the following code after the app.use(express.urlencoded({ extended: true })) line:

javascriptCopy code

app.use(express.static(__dirname + '/public'));

This tells Express to serve static files from the public directory. The __dirname variable contains the absolute path of the current directory.

  1. In our HTML file, add the following code inside the <head> tag:

htmlCopy code

<link rel="stylesheet" type="text/css" href="/css/style.css">

This tells the browser to load the style.css file from the css folder inside the public folder.

  1. Save the changes and restart the server. The background color of the page should now be blue.

We can add more CSS rules to our style.css file to style other elements in our HTML file.

30. My First Express App - Continued

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?