Build a Basic M.E.N. Site - 4 - Make It Looks Better
Serve CSS With NodeJS/Express
Create a
public/
folder inside the project’s main folder, and put a CSS file inside:mkdir ./public
vim ./public/styls.cssAdd a middleware in the
server.js
file:
EJS can not directly get the CSS file when rendering, so we need to add a middleware in the server file:app.use(express.static(__dirname +"/public"))
Link the CSS file in
index.ejs
file<link href="/style.css" rel="stylesheet" type="text/css">
The STYLE
Some notes about the CSS:
Only one font setting :
font-family: "Source Han Sans", "Microsoft JhengHei", sans-serif;
Transparent input segment. Use
input::placeholder
to style the placeholder text. Andinput:focus::placeholder
to set the style when selected(focus).Button:
border-radius
to set a rounded button.cursor: pointer
to change the cursor style.The
<div>
holding the list.vertical-align: top
to set it to the top.
Here it is! A very simple MEN stack web site. What I will like to do latter:
- Add a pie chart to show the percentage of each choice using CSS or SVG+JavaScript and Use
Math.floor(X *100)/100
to find the percentage. Reference - Use
express-rate-limit
to block an ip with too much connections. Also improve the site’s security.Reference - Add UPDATE functionality to let user update/change their choice.REference
- Auto generate a page every day.