HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
<p>Prototype for a FAQ with a "live search" that hides content not related to your search term</p>
<input type="text" placeholder="Search" v-model="searchInput">
<div class="container">
<div class="left">
<div class="category" @click="toggleCategory(0)" :class="[categories[0] ? activeCategory : '']"><h3>Making a Purchase</h3></div>
<div class="category" @click="toggleCategory(1)" :class="[categories[1] ? activeCategory : '']"><h3>Buying Online</h3></div>
<div class="category" @click="toggleCategory(2)" :class="[categories[2] ? activeCategory : '']"><h3>Delivery/Pickup</h3></div>
</div>
<div class="right">
<div class="question-container" v-show="categories[0]">
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(0)">What does "Buyer's Best" mean?</h3>
<p class="answer" v-show="questions[0]">On select products, our buyers have used The Big's purchasing power to get you the best quality products for the best prices in Canada.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(1)">What does "Special Order" mean?</h3>
<p class="answer" v-show="questions[1]">Special Order products are items we don't stock in our warehouses as regular inventory.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(2)">What is the status of my order?</h3>
<p class="answer" v-show="questions[2]">Your order may be in one of several statuses.</p>
</div>
</div>
<div class="question-container" v-show="categories[1]">
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(0)">How do I know what items are in stock?</h3>
<p class="answer" v-show="questions[0]">On each product details page, you can see what's in stock by looking at the delivery and pick-up dates listed underneath the item name and price.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(1)">What payment methods can I use online?</h3>
<p class="answer" v-show="questions[1]">You can pay online using your Big Visa Des Card, AMEX, MasterCard or Visa.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(2)">Can I use my gift card for online purchases?</h3>
<p class="answer" v-show="questions[2]">Unfortunately, gift cards for The Big are not able to be redeemed or purchased online at this time. You can purchase Big gift cards at any Big Group store and use them in store for any furniture, electronic, appliance or mattress purchase(s).</p>
</div>
</div>
<div class="question-container" v-show="categories[2]">
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(0)">Where does The Big deliver?</h3>
<p class="answer" v-show="questions[0]">Our Premium Delivery Service is available in most areas.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(1)">Is Premium Delivery Service available in rural areas?</h3>
<p class="answer" v-show="questions[1]">Because of factors like time constraints and extended travel times, we can offer only our Basic Service in some smaller towns and rural areas.</p>
</div>
<div class="qa-pair">
<h3 class="question" @click="toggleAnswer(2)">Can I track my delivery?</h3>
<p class="answer" v-show="questions[2]">In most major markets, you can track your delivery status on the day of your delivery using Find My Delivery.</p>
</div>
</div>
</div>
</div>
</div>
@import url('https://fonts.googleapis.com/css?family=Lato&display=swap');
* {
font-family: "Lato", sans-serif;
margin: 0 auto;
padding: 0;
box-sizing: border-box;
overflow: visible;
}
#app {
padding: 1em;
height: 1000px;
input {
margin-bottom: 1em;
}
}
.container {
display: flex;
flex-wrap: wrap;
}
.left {
width: 35%;
.category {
padding: 1em;
border-bottom: 1px solid lightgray;
cursor: pointer;
&:hover {
background: #eee;
}
}
.activeCategory {
background: #e9292c;
h3 {
color: #fff;
}
&:hover {
background: #e9292c;
}
}
}
mark {
background: pink;
padding: 1px 0;
}
.right {
width: 65%;
padding-left: 1em;
padding-right: 1em;
.qa-pair {
margin-bottom: 1em;
h3 {
margin-bottom: .5em;
cursor: pointer;
position: relative;
padding-bottom: .5em;
&::before {
content: '';
position: absolute;
height: 1px;
width: 100%;
background: black;
bottom: 0;
}
&:hover::before {
height: 3px;
}
}
}
}
var app = new Vue({
el: '#app',
data: {
//values here represent the active category or active questions
categories: [
true, false, false, false, false, false, false
],
questions: [
false, false, false, false, false
],
searchInput: null,
activeCategory: 'activeCategory'
},
methods: {
toggleCategory: function(category) {
this.searchInput = ''
if (this.categories[category] == false) {
this.hideOtherCategories();
this.$set(this.categories, category, true);
this.hideAnswers();
}
},
toggleAnswer: function(question) {
if (this.questions[question] == false) {
this.$set(this.questions, question, true);
} else {
this.$set(this.questions, question, false);
}
},
hideAnswers: function() {
for (i=0;i<this.questions.length;i++) {
this.$set(this.questions, i, false);
}
},
hideOtherCategories: function() {
for (i=0;i<this.categories.length;i++) {
this.$set(this.categories, i, false);
}
},
showAllAnswers: function() {
for (i=0;i<this.questions.length;i++) {
this.$set(this.questions, i, true);
}
},
showAllTopics: function() {
for (i=0;i<this.categories.length;i++) {
this.$set(this.categories, i, true);
}
},
search: function(category) {
var input = this.searchInput.toUpperCase();
input = input.normalize("NFD").replace(/[\u0300-\u036f]/g, "") //does not work with IE 11
var allQuestions = this.$el.querySelectorAll('.question');
var allAnswers = this.$el.querySelectorAll('.answer');
var qaPairs = this.$el.querySelectorAll('.qa-pair');
this.showAllAnswers();
this.showAllTopics();
this.activeCategory = ''
//Mark.js instance which allows search words to be highlighted
var container = document.querySelector('.right')
var instance = new Mark(container)
instance.unmark();
instance.mark(input, { "separateWordSearch": false }) //allows words with spaces to be found
if (input) {
for (i = 0; i < qaPairs.length; i++) {
var answers = allAnswers[i].innerHTML.toUpperCase().indexOf(input)
var questions = allQuestions[i].innerHTML.toUpperCase().indexOf(input)
if (answers == -1 && questions == -1) {
qaPairs[i].style.display = 'none';
} else {
qaPairs[i].style.display = 'block';
}
}
} else {
for (i = 0; i < qaPairs.length; i++) {
qaPairs[i].style.display = 'block';
}
this.hideAnswers();
this.hideOtherCategories();
this.$set(this.categories, 0, true);
this.activeCategory = 'activeCategory'
}
}
},
watch: {
searchInput: function() {
this.search();
}
}
})
Also see: Tab Triggers