Lorem ipsum dolor, sit amet consectetur adipisicing elit. Velit saepe sequi, illum facere
necessitatibus cum aliquam id illo omnis maxime, totam soluta voluptate amet ut sit ipsum
aperiam.
Perspiciatis, porro!
Why do you need an FAQ page?
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Velit saepe sequi, illum facere
necessitatibus cum aliquam id illo omnis maxime, totam soluta voluptate amet ut sit ipsum
aperiam.
Perspiciatis, porro!
Does it improves the user experience of a website?
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Velit saepe sequi, illum facere
necessitatibus cum aliquam id illo omnis maxime, totam soluta voluptate amet ut sit ipsum
aperiam.
Perspiciatis, porro!
Step Two: Positioning our layouts and styling
CSS Code: This section contains the positioning of our FAQ page, the font size, and the styling of the elements.
Create layout columns,
For our content to be readable, we must use a good font. Check out this link for the font used in the project google font.
Center page in the middle of the window
body{
font-family: 'Work Sans', sans-serif;
}
.faq-heading{
border-bottom: #777;
padding: 20px 60px;
}
.faq-container{
display: flex;
justify-content: center;
flex-direction: column;
}
.hr-line{
width: 60%;
margin: auto;
}
/* Style the buttons that are used to open and close the faq-page body */
.faq-page {
/* background-color: #eee; */
color: #444;
cursor: pointer;
padding: 30px 20px;
width: 60%;
border: none;
outline: none;
transition: 0.4s;
margin: auto;
}
.faq-body{
margin: auto;
/* text-align: center; */
width: 50%;
padding: auto;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active,
.faq-page:hover {
background-color: #F9F9F9;
}
/* Style the faq-page panel. Note: hidden by default */
.faq-body {
padding: 0 18px;
background-color: white;
display: none;
overflow: hidden;
}
.faq-page:after {
content: '\02795';
/* Unicode character for "plus" sign (+) */
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2796";
/* Unicode character for "minus" sign (-) */
}
Step Three: Adding functionalities
JavaScript Code: This section contains the part of the code that controls the functionalities of the FAQ page: the event handling.
Now we are going to add javascript to make our FAQ page functional. Currently, our page looks beautiful but doesn’t work well because we haven’t included our javascript, but we can make it so much better.
main.js file
var faq = document.getElementsByClassName("faq-page");
var i;
for (i = 0; i < faq.length; i++) {
faq[i].addEventListener("click", function () {
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this.classList.toggle("active");
/* Toggle between hiding and showing the active panel */
var body = this.nextElementSibling;
if (body.style.display === "block") {
body.style.display = "none";
} else {
body.style.display = "block";
}
});
}
Output
Conclusion
Having an FAQ page is essential and can serve as a better experience for your end-users that brings real value to your website. I hope this article has given you reasons for having an FAQ page on your website and how to build it.
You can check out the code here on my Github page
EZEKIEL LAWSON ›
I am a software developer with development experience in frontend building responsive website sites using these web technologies like Javascript, VueJs, HTML and CSS, Bootstrap Tailwind CSS. I specialize in converting designs to Code, and I love teaching and sharing my technical ideas through an article.
Previous Article
5 Security Automation Examples for Non-Developers
Next Article
Build an Automation-First Security Culture
DISCUSSION
Click on a tab to select how you'd like to leave your comment
MORE SWEETNESS…
2 months ago
Build a CRUD SPA with Vuejs, Apollo Client and GraphQL
5 months ago
Use Java Streams to Write Clean Java Code
9 months ago
Java Versus Python: Key Programming Differences In 2021
SWEET VIDEOS
body{
font-family: 'Work Sans', sans-serif;
}
.faq-heading{
border-bottom: #777;
padding: 20px 60px;
}
.faq-container{
display: flex;
justify-content: center;
flex-direction: column;
}
.hr-line{
width: 60%;
margin: auto;
}
/* Style the buttons that are used to open and close the faq-page body */
.faq-page {
/* background-color: #eee; */
color: #444;
cursor: pointer;
padding: 30px 20px;
width: 60%;
border: none;
outline: none;
transition: 0.4s;
margin: auto;
}
.faq-body{
margin: auto;
/* text-align: center; */
width: 50%;
padding: auto;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active,
.faq-page:hover {
background-color: #F9F9F9;
}
/* Style the faq-page panel. Note: hidden by default */
.faq-body {
padding: 0 18px;
background-color: white;
display: none;
overflow: hidden;
}
.faq-page:after {
content: '\02795';
/* Unicode character for "plus" sign (+) */
font-size: 13px;
color: #777;
float: right;
margin-left: 5px;
}
.active:after {
content: "\2796";
/* Unicode character for "minus" sign (-) */
}
Step Three: Adding functionalities
JavaScript Code: This section contains the part of the code that controls the functionalities of the FAQ page: the event handling.
Now we are going to add javascript to make our FAQ page functional. Currently, our page looks beautiful but doesn’t work well because we haven’t included our javascript, but we can make it so much better.
main.js file
var faq = document.getElementsByClassName("faq-page");
var i;
for (i = 0; i < faq.length; i++) {
faq[i].addEventListener("click", function () {
/* Toggle between adding and removing the "active" class,
to highlight the button that controls the panel */
this.classList.toggle("active");
/* Toggle between hiding and showing the active panel */
var body = this.nextElementSibling;
if (body.style.display === "block") {
body.style.display = "none";
} else {
body.style.display = "block";
}
});
}
Output
Conclusion
Having an FAQ page is essential and can serve as a better experience for your end-users that brings real value to your website. I hope this article has given you reasons for having an FAQ page on your website and how to build it.
You can check out the code here on my Github page
EZEKIEL LAWSON ›
I am a software developer with development experience in frontend building responsive website sites using these web technologies like Javascript, VueJs, HTML and CSS, Bootstrap Tailwind CSS. I specialize in converting designs to Code, and I love teaching and sharing my technical ideas through an article.
Previous Article
5 Security Automation Examples for Non-Developers
Next Article
Build an Automation-First Security Culture
DISCUSSION
Click on a tab to select how you'd like to leave your comment
MORE SWEETNESS…
2 months ago
Build a CRUD SPA with Vuejs, Apollo Client and GraphQL
5 months ago
Use Java Streams to Write Clean Java Code
9 months ago
Java Versus Python: Key Programming Differences In 2021
SWEET VIDEOS
VISIT CHANNEL
VISIT CHANNEL
Get link
Facebook
X
Pinterest
Email
Other Apps
Comments
Popular posts from this blog
GeeksforGeeks Where is Taj Mahal located? Taj Mahal is located in Agra, Uttar Pradesh. How many planets are there in solar system? There are eight planets in solar system. Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune. FAQ GeeksforGeeks Where is Taj Mahal located? Taj Mahal is located in Agra, Uttar Pradesh. How many planets are there in solar system? There are eight planets in solar system. Mercu...
Word Counter Word Count: 0 Our markup is quite simple. We have a counter that will be updated with Javascript. Then a textarea to enable users to enter some text. We’ve also included an id for both the counter and the textarea so we can create a reference to them from our script. Lastly, we import a JavaScript file we haven’t created yet. If you run the code in your browser using any web server, you’ll see something similar to this. Go ahead and create a new file main.js in the same folder. Let’s add some code. var count = document.getElementById('count'); var input = document.getElementById('input'); The counter will update as the user enters texts so we grab a reference to the id of both the textarea and the count to be updated. So far so good. What we need to do now is listen to changes to our text input and count the words. The keyup event is fired when the user’s hands have left a previously pressed key so we’ll use t...
Comments
Post a Comment