Build Node.js Chat room web application: use Bootstrap chat room UI

Home > Sci-Tech

Build Node.js Chat room web application: use Bootstrap chat room UI

2022-05-14 18:07:47 17 ℃

Bootstrap is a popular HTML and CSS framework for building websites and web applications. It is the first project on Github. Bootstrap supports the response web design, allowing your page layout to adapt to the device (desktop, tablet, mobile device).

To add Bootstrap to our project, we must download the reduced CSS and JS files for Bootstrap. You can download Bootstrap from this link. After downloading bootstrap, unzip the file and copy the folder to the folder CSS in the project. jsfontspublic

You will notice some inconsistent with the structure of the existing folder. We will uniform style tables and JavaScript folders. CSS I prefer the Bootstrap naming method of Forshlesheets and JSFOR. JavaScript is shared with other third -party libraries because of it. Copy files to styleSheets to CSS and delete the JavaScript folder because it should be empty. Next, go to layout.jade and change the following:

Link (REL = 'STYLESHEET' Href = '/Stylesheets/Style.css')


Link (REL = 'STYLESHEET' Href = '/CSS/Style.css')

Next, we want to add the Bootstrap CSS file to the title and the appropriate meta marker Layout.jade of the HTML5 application in the file. Style.css you must add a deale before the line containing links.

Meta (Charset = "UTF-8") Meta (http-equiv = "x-ua-compatible" content = "ie = edge") link (rel = 'styleSheet' href = '/css/bootstrap.min .css') Link (REL = 'STYLESHEET' Href = '/CSS/BOOTSTRAP- TheME.MIN.CSS')

Next, we want to add the JavaScript file required for Bootstrap and the plug -in. Layout.jade at the end of the following travel:

Script (type = 'text/javascript' src = '/js/bootstrap.min.js') Doctype htmlhtmlHetmlHetti = titlemeta (charset = "utf-8") = "X-ua-compatible" content = "ie = edge") link (rel = 'styleSheet' href = '/css/bootstrap.min.css') link (rel = 'styleSheet'/css/bootstrap -Theme.min.css') link (rel = 'styleSheet' href = '/css/style.css') BodyBlock ContentScript (type =' text/javascript 'src ='/js/bootstrap.min.js') /code>

It's time to develop a chat user interface layout. First, you may want to know Bootstrap and check this long tutorial. All chat engines have a area used for recently received and a area for users to write and send messages. Historically, the layout is to add the editing area to the bottom and add the message to the top.

If you do not do some jobs, it is not easy to fix the elements on the HTML page to the bottom of the viewport. I will fix my foot to the bottom according to this example. We want to modify the index.jade file and delete all code lines under the content block.

First, we add the page area that will receive a message. Let's start wrap from adding a div. In jade, you just need to write a

. By using the indentation, we can send a signal to the Jade template engine, that is, more indentation elements will be included in the indentation In less elements. If you miss this jade tutorial in other tutorials, check it.

Next, we want to add another DIV class Container-Fluid to add fluid width to the page. Inside, I will create a H1 element with "Welcome to the Node Chat Room" and a DIV with IDMESSAGES and FinalDIV. At the bottom of the mouth. .wrap.container-Fluidh1 Welcome to the Node Chatroom#Messages.push

Next, we will develop a message editing area. We want to capture the text box and send buttons Container-Fluid in the call and div in the DIV. Footer div with the same shrinking into the Wrap Div.

Next, I will use the Bootstrap grid system (understand it here) to divide the message editing area into two. One column will occupy most of the space and will include a text box for writing messages. The second column will contain a button that contains Block-level to send messages. Paragraph please note how Jade allows us to use the attributes of the symbol specified element. The code will be shown below:

.footer.Container-fluid.Row.Col-XS-8.Col-SM-9INPut (type = "text" id = "message-box" class = "form-control input-lg" plalder = "write a message here ... "ROWS =" 3 "). COL-XS-4.COL-SM-3Button#Send-Message-BTN.BTN.BTN-LG.BTN-BLOCK Send Message Extends LayoutBlock Content.wrap.container-Fluidh1 Welcome to the Node Chatroom#Messages.push.footer.Containerow.Row-XS-SM-SM-9ine. "MESSAGE-BOX" class = "Form-Control input-Lg" Placeholder = "Write A Message Here ..." ROWS = "3"). Col-Xs-4.Col-SM-3Button#Send-Message-BTN .btn.btn-primary.btn-lg.btn-black send message

We hope to force the message editing area to the bottom of the viewport. We will hope to add some custom CSS rules on the Public/CSS/Style.styl page. This file uses the Stylus CSS preprocessor, but you can also paste the CSS with verbatim. These CSS will be re -copied to the generated CSS file.

First, we must ensure that the entire page occupies a height of 100%.

HTML, Bodyheigh: 100%

Secondly, we must ensure that the change area occupies the largest height, but leaves a 60px border for the foot and message editing area at the bottom.

.wrapmin -height: 100%Height: Auto! Importantheight: 100%Margin: 0 Auto -60px >

Third, we must ensure that this space in the editing area is respected and assigned it to the footer.

.push, .footerheight: 60px

Finally, for stylistic reasons, let us add a delicate background color to the footer.

.footerBackground-COLOR: **#F5F5F5 ** html, bodyheight: 100%.wrapmin-height: 100%Height: Importantheight: 100%MARGIN: 0 Auto -60 , .footerheight: 60px.footerBackground-COLOR: #F5F5F5