Μάθετε το Bootstrap 4 σε 30 λεπτά δημιουργώντας έναν ιστότοπο σελίδας προορισμού


Ένας οδηγός για αρχάριους
«Το Bootstrap είναι μια δωρεάν βιβλιοθήκη ανοιχτού κώδικα για σχεδιασμό ιστοσελίδων και εφαρμογών ιστού. Περιέχει πρότυπα σχεδίασης που βασίζονται σε HTML και CSS για τα πάντα, από τυπογραφία, φόρμες, κουμπιά, πλοήγηση και άλλα στοιχεία διεπαφής, καθώς και επεκτάσεις JavaScript. Σε αντίθεση με πολλά άλλα διαδικτυακά πλαίσια, το Bootstrap ασχολείται μόνο με την ανάπτυξη front-end. " - WikipediaHi, προτού ξεκινήσουμε να ρίξουμε μια ματιά στην πλήρη τάξη μου για να μάθω το Bootstrap 4, όπου θα μάθετε νέες δυνατότητες του bootstrap και πώς να τα χρησιμοποιήσετε για να δημιουργήσετε καλύτερες εμπειρίες χρηστών.Υπάρχουν πολλές εκδόσεις του Bootstrap με την έκδοση 4 να είναι η πιο πρόσφατη. Σε αυτό το άρθρο, πρόκειται να δημιουργήσουμε έναν ιστότοπο χρησιμοποιώντας το Bootstrap 4.
Προαπαιτούμενα
Πριν ξεκινήσετε, υπάρχουν μερικές δεξιότητες που πρέπει να γνωρίζετε για να μάθετε και να χρησιμοποιήσετε το πλαίσιο Bootstrap:
- Βασικές αρχές HTML
- βασικές γνώσεις του CSS
- και μερικά βασικά JQuery
Πίνακας περιεχομένων
Θα καλύψουμε τα παρακάτω θέματα κατά την κατασκευή του ιστότοπου:
- Λήψη και εγκατάσταση του Bootstrap 4
- Τα νέα χαρακτηριστικά του Bootstrap 4
- Σύστημα πλέγματος Bootstrap
- Navbar
- Επί κεφαλής
- Κουμπιά
- Σχετικά με το τμήμα
- Τμήμα χαρτοφυλακίου
- Ενότητα ιστολογίου
- Καρτέλλες
- Τμήμα ομάδας
- Φόρμα Επικοινωνίας
- Γραμματοσειρές
- Εφέ κύλισης
- Περίληψη και συμπέρασμα
Λήψη και εγκατάσταση του Bootstrap 4
Υπάρχουν τρεις τρόποι για να εγκαταστήσετε και να συμπεριλάβετε το Bootstrap 4 για το έργο σας:
- Χρησιμοποιήστε npm
Μπορείτε να εγκαταστήσετε το Bootstrap 4 εκτελώντας αυτήν την εντολή npm install bootstrap
2. Χρησιμοποιήστε ένα δίκτυο παράδοσης περιεχομένου (CDN)
Συμπεριλαμβάνοντας αυτόν τον σύνδεσμο στο έργο σας ανάμεσα στις επικεφαλίδες:
3. Κατεβάστε τη βιβλιοθήκη Bootstrap 4 και χρησιμοποιήστε την τοπικά.
Η δομή του έργου μας πρέπει να έχει την εξής μορφή:

Τα νέα χαρακτηριστικά του Bootstrap 4
Τι νέο υπάρχει στο Bootstrap 4; Και τι διαφέρει μεταξύ του Bootstrap 3 και του 4;
Το Bootstrap 4 έρχεται τώρα με μερικές εκπληκτικές δυνατότητες που δεν υπήρχαν στην τελευταία έκδοση:
- Το Bootstrap 4 γράφεται χρησιμοποιώντας το Flexbox Grid, ενώ το Bootstrap 3 γράφτηκε χρησιμοποιώντας τη μέθοδο float.
Εάν είστε νέοι στο Flexbox, ρίξτε μια ματιά σε αυτό το σεμινάριο.
- Το Bootstrap 4 χρησιμοποιεί
rem
μονάδες CSS ενώ το Bootstrap 3 χρησιμοποιείpx
.Δείτε πώς διαφέρουν αυτές οι δύο μονάδες.
- Τα πάνελ, οι μικρογραφίες και τα φρέατα έχουν πέσει εντελώς.
Μπορείτε να διαβάσετε αναλυτικά περισσότερα σχετικά με τις παγκόσμιες αλλαγές και τις καταργημένες δυνατότητες του Bootstrap 4 εδώ.
Χωρίς να πάμε πολύ βαθιά στη λεπτομέρεια εδώ, ας προχωρήσουμε σε κάποια άλλα σημαντικά πράγματα.
Το σύστημα Bootstrap Grid
The Bootstrap Grid system helps you to create your layout and easily build a responsive website. There have not been any changes in the class names, except the .xs
class, which no longer exists in Bootstrap 4.
The grid is divided into 12 columns, so your layout will be based on this.
To use the grid system you’ll have to add a .row
class to the main div.
col-lg-2 // class used for large devices like laptops col-md-2 // class used for medium devices like tablets col-sm-2// class used for small devices like mobile phones
Navbar

The navbar wrapper is pretty cool in Bootstrap 4. It’s so helpful when it comes to building a responsive navbar.
To get it, we are going to add the navbar
class to our index.html
file:
Home
- About
- Portfolio
- Blog
- Team
- Contact
Create and include a main.css
file so that you can customize the CSS style.
Put this within the head
tag in your index.html
file:
Let’s add some colors to our navbar:
.navbar{ background:#F97300;} .nav-link , .navbar-brand{ color: #f4f4f4; cursor: pointer;} .nav-link{ margin-right: 1em !important;} .nav-link:hover{ background: #f4f4f4; color: #f97300; } .navbar-collapse{ justify-content: flex-end;} .navbar-toggler{ background:#fff !important;}
The new Bootstrap Grid is built with the Flexbox system, so for alignment, you have to use a Flexbox property. For example, to place the navbar menu on the right we need to add a justify-content
property and set it to flex-end
.
.navbar-collapse{ justify-content: flex-end; }
Add the .fixed-top
class to the navbar to give it a fixed position.
To make the navbar background color light, add .bg-light
. For a dark background, add .bg-dark
, and for a light blue background, add
.bg-primary
.
Here’s how that should look:
.bg-dark{ background-color:#343a40!important } .bg-primary{ background-color:#007bff!important }
Header
Let’s try and create a layout for the header.
Here, we want to make sure the header takes up the window’s height so we are going to use a little JQuery
code.
First, create a file named main.js
and include it in the index.html
filebefore the closing body
tag:
In the main.js
file insert this a little code of JQuery:
$(document).ready(function(){ $('.header').height($(window).height()); })
It’d be pretty cool if we set a nice background image to the header:
/*header style*/ .header{ background-image: url('../images/headerback.jpg'); background-attachment: fixed; background-size: cover; background-position: center; }

Let’s add an overlay to make the header look a bit more professional:
Add this to your index.html
file:
Then, add this to your main.css
file:
.overlay{ position: absolute; min-height: 100%; min-width: 100%; left: 0; top: 0; background: rgba(244, 244, 244, 0.79); }
Now we have to add a description inside the header.
To wrap our description we’re first going to create a div
and give it a class .container
.
.container
is a Bootstrap class that will help you to wrap your content and make your layout more responsive:
Then, add another div
which will contain the description.
Hello ,Welcome To My official Website
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
See more
We’ll give it a class of .description
and add the .text-center
class to make sure the content is placed in the center of the page.
Buttons
Add the class .btn btn-outline-secondary
to the button
element. there are many other Bootstrap classes for buttons.
Check some examples:
CodePen Embed — buttons in Bootstrap 4
Buttons Button primary Button default Button danger Button info Button warning Button dark Button success Buttons…codepen.io
Here’s how the styling for the .description
looks in the main.css
file:
.description{ position: absolute; top: 30%; margin: auto; padding: 2em; } .description h1{ color:#F97300 ; } .description p{ color:#666; font-size: 20px; width: 50%; line-height: 1.5; } .description button{ border:1px solid #F97300; background:#F97300; color:#fff; }
After all of that, our header will look like this:

Cool isn’t :).
About Section

In this section, we will use some Bootstrap Grid to divide the section into two parts.
To start our grid, we have to assign the.row
class to the parent div
.
The first section will be on the left and will contain a picture, the second section will be on the right and contain a description.
Each div
will take up 6 columns — that means half of the section. Remember that a grid is divided into 12 columns.
In the first div
on the left side:
// left side S.Web Developer
After adding the the HTML elements on the right-side, the structure of the code will look like this:
S.Web Developer D.John
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Here’s how I’ve made it look:
.about{ margin: 4em 0; padding: 1em; position: relative; } .about h1{ color:#F97300; margin: 2em; } .about img{ height: 100%; width: 100%; border-radius: 50% } .about span{ display: block; color: #888; position: absolute; left: 115px; } .about .desc{ padding: 2em; border-left:4px solid #10828C; } .about .desc h3{ color: #10828C; } .about .desc p{ line-height:2; color:#888; }
Portfolio Section
Now, let’s move onto the next bit and make a portfolio section that will contain a gallery.

The structure of our HTML code for the Portfolio section looks like this:
Portfolio
Adding .img-fluid
to each image to makes it responsive.
Each item in our gallery will take up 4 columns (remember, col-md-4
for medium devices, col-lg-4
for large devices). That’s equal to 33.33333%on large devices such desktops and large tablets, and 12 columns on a small device (like iPhone, mobile devices) will take up 100% of the container.
Let’s add some styling to our Gallery:
/*Portfolio*/ .portfolio{ margin: 4em 0; position: relative; } .portfolio h1{ color:#F97300; margin: 2em; } .portfolio img{ height: 15rem; width: 100%; margin: 1em; }
Blog Section

Cards
Cards in Bootstrap 4 make blog design so much easier. The cards are appropriate for articles and posts.
To create a card, we use the class .card
and assign it to a div element,
The card class contains many features:
.card-header
: define the card header.card-body
:for the card body.card-title
: the title of the cardcard-footer
:define the footer of the card..card-image
: for the card’s image
So, our website’s HTML should now look something like this:
Blog
Post Title
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Read more Post Title
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Read more Post Title
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Read more
We need to add some CSS style to the cards:
.blog{ margin: 4em 0; position: relative; } .blog h1{ color:#F97300; margin: 2em; } .blog .card{ box-shadow: 0 0 20px #ccc; } .blog .card img{ width: 100%; height: 12em; } .blog .card-title{ color:#F97300; } .blog .card-body{ padding: 1em; }
After adding the Blog section to our website, the design should now look something like this:

Cool isn’t it? ?
Team Section

In this section we will use the grid system to distribute even space between images. Each image takes up 3 columns (.col-md-3
) of the container — that equals 25% of the total space.
Our HTML structure:
Our Team
Sara Manager Chris S.enginner Layla Front End Developer J.Jirard Team Manger
And let’s add some style:
.team{ margin: 4em 0; position: relative; } .team h1{ color:#F97300; margin: 2em; } .team .item{ position: relative; } .team .des{ background: #F97300; color: #fff; text-align: center; border-bottom-left-radius: 93%; transition:.3s ease-in-out; }
Adding an overlay to the image on-hover using animation would be nice ?.

To make this effect , add the styles below to main.css
file:
.team .item:hover .des{ height: 100%; background:#f973007d; position: absolute; width: 89%; padding: 5em; top: 0; border-bottom-left-radius: 0; }
Super cool! ?
Contact Form

The Contact Form is the last section to add, then we are done ?.
The Contact Form section will contain a form through which visitors can send an email or give feedback. We will use some Bootstrap classes to make the design beautiful and responsive.
Like Bootstrap 3, Bootstrap 4 also uses the .form-control
class for input fields, but there are some new features added — like switching from .input-group-addon
(deprecated) to .input-group-prepend
(to use icons as labels ).
See Bootstrap 4 document for more information. In our Contact form we will wrap each input between a div
that has the class.form-group
.
The index.html
file now looks something like this:
Get in Touch
Contact section’styles :
main.css
.contact-form{ margin: 6em 0; position: relative; } .contact-form h1{ padding:2em 1px; color: #F97300; } .contact-form .right{ max-width: 600px; } .contact-form .right .btn-secondary{ background: #F97300; color: #fff; border:0; } .contact-form .right .form-control::placeholder{ color: #888; font-size: 16px; }
Fonts
I think default fonts are ugly so we are going to use the Google Font API, and we’ll choose Raleway which is a nice font and appropriate to our template.
Add this link into your main.css
file:
@import url('//fonts.googleapis.com/css?family=Raleway');
and set the global style to HTML and heading tags:
html,h1,h2,h3,h4,h5,h6,a{ font-family: "Raleway"; }
Scroll Effect

The last thing missing is scroll effect. Here, we’ll have to use some JQuery. Don’t worry️ if you are not familiar with it, just add this code into yourmain.js
file:
$(".navbar a").click(function(){ $("body,html").animate({ scrollTop:$("#" + $(this).data('value')).offset().top },1000) })
and add a data-value
attribute to each navbar link:
About Portfolio Blog Team Contact
Set an id
attribute to each section.
Σημείωση : Πρέπει id
να είναι πανομοιότυπο με το data-value
χαρακτηριστικό στο σύνδεσμο navbar για να λειτουργεί η κύλιση:
Περίληψη και συμπέρασμα
Το Bootstrap 4 είναι μια εξαιρετική επιλογή για τη δημιουργία της διαδικτυακής σας εφαρμογής. Παρέχει υψηλής ποιότητας στοιχεία UI και είναι εύκολο να προσαρμόσετε, να ενσωματώσετε και να χρησιμοποιήσετε. Θα σας βοηθήσει επίσης να συμπεριλάβετε την ανταπόκριση στον ιστότοπό σας, παρέχοντας έτσι μια εξαιρετική εμπειρία χρήστη στους χρήστες σας.
Θα βρείτε τα αρχεία του έργου στο GitHub.
Εάν χρειάζεστε κάποια θέματα και πρότυπα Bootstrap, μπορείτε να δείτε το BootstrapBay, έχουν μερικά υπέροχα προϊόνταΡίξτε μια ματιά στην τάξη Bootstrap για να μάθετε το Bootstrap 4:
Bootstrap 4 crash course: βασικό για να προχωρήσει | Είπε ο Χάνι | Κοινή χρήση δεξιοτήτων
Σε αυτήν την τάξη θα μάθετε την έκδοση 4 bootstrap, το πλαίσιο CSS για τη δημιουργία ευέλικτων προτύπων και… skl.sh