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.
<main>
<section class="card">
<!-- cube img -->
<img src="https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/illustration-box-desktop.svg" alt="Box" class="card__box" />
<!-- Images -->
<div class="card__img">
<!-- mobile -->
<img class="card__img-mobile" src="https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/illustration-woman-online-mobile.svg" alt="Woman online Mobile" />
<!-- desktop -->
<img class="card__img-desktop" src="https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/illustration-woman-online-desktop.svg" alt="Woman online desktop" />
</div>
<!-- Text -->
<div class="card__text">
<h1>FAQ</h1>
<div class="accordion">
<!-- item 1 -->
<div class="accordion__item">
<button class="accordion__title">
How many team members can I invite?
</button>
<div class="accordion__collapse collapse">
<div class="accordion__text">
<p> You can invite up to 2 additional users on the Free plan.
There is no limit on team members for the Premium plan.</p>
</div>
</div>
</div>
<!-- item 2 -->
<div class="accordion__item">
<button class="accordion__title">
What is the maximum file upload size?
</button>
<div class="accordion__collapse collapse">
<div class="accordion__text">
No more than 2GB. All files in your account must fit your
allotted storage space.
</div>
</div>
</div>
<!-- item 3 -->
<div class="accordion__item">
<button class="accordion__title">
How do I reset my password?
</button>
<div class="accordion__collapse collapse">
<div class="accordion__text">
Click “Forgot password” from the login page or “Change
password” from your profile page. A reset link will be emailed
to you.
</div>
</div>
</div>
<!-- item 4 -->
<div class="accordion__item">
<button class="accordion__title">
Can I cancel my subscription?
</button>
<div class="accordion__collapse collapse">
<div class="accordion__text">
Yes! Send us a message and we’ll process your request no
questions asked.
</div>
</div>
</div>
<!-- item 5 -->
<div class="accordion__item">
<button class="accordion__title">
Do you provide additional support?
</button>
<div class="accordion__collapse collapse">
<div class="accordion__text">
Chat and email support is available 24/7. Phone lines are open
during normal business hours.
</div>
</div>
</div>
</div>
</div>
</section>
</main>
<footer>
<div class="attribution">
Challenge by
<a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>. Coded by
<a href="https://www.frontendmentor.io/profile/MizAndhre" target="_blank">Andhre</a>.
<div class="icons">
<a href="https://github.com/MizAndhre" target="_blank" aria-label="Github">
<i class="fab fa-github"></i>
</a>
<a href="https://codepen.io/mizandhre" target="_blank" aria-label="Codepen">
<i class="fab fa-codepen"></i>
</a>
</div>
</div>
</footer>
@import url("https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@400;700&display=swap");
:root {
--textBlue: hsl(238, 29%, 16%);
--textRed: hsl(14, 88%, 65%);
--textVeryDarkBlue: hsl(237, 12%, 33%);
--textDarkBlue: hsl(240, 6%, 50%);
--gradientViolet: hsl(273, 75%, 66%);
--gradientBlue: hsl(240, 73%, 65%);
--dividerGray: hsl(240, 5%, 91%);
}
html {
box-sizing: border-box;
font-size: 62.5%;
}
*,
*::after,
*::before {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: "Kumbh Sans", sans-serif;
font-size: 1.2rem;
font-weight: 400;
background: linear-gradient(var(--gradientViolet), var(--gradientBlue));
}
main {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.card {
background-color: #fff;
border-radius: 2.5rem;
min-width: 33rem;
max-width: 92rem;
margin: 0 2.5rem 6rem;
padding: 0 2.3rem 4.8rem;
background-image: url("https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/bg-pattern-mobile.svg");
background-repeat: no-repeat;
background-position: top center;
background-size: 24rem;
}
.card__box {
display: none;
}
.card__img {
position: relative;
}
.card__img-mobile {
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%) translateY(-60%);
display: block;
width: 100%;
height: auto;
max-width: 24rem;
}
.card__img-desktop {
display: none;
}
.card__text {
margin-top: 12.9rem;
}
h1 {
margin: 0;
padding-bottom: 1.5rem;
font-size: 3.3rem;
font-weight: 700;
text-align: center;
color: var(--textBlue);
}
.accordion__item {
border-bottom: 0.1rem solid var(--dividerGray);
}
.accordion__item h2 {
margin: 0;
}
.accordion__title {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
padding: 1.45rem 0.5rem;
border: none;
background: none;
font-family: "Kumbh Sans", sans-serif;
font-size: 1.4rem;
color: var(--textVeryDarkBlue);
text-align: left;
transition: all 300ms ease-in-out;
}
.accordion__title:focus,
.accordion__title:focus-visible {
z-index: 3;
outline: solid rgba(255, 146, 113, 0.5);
box-shadow: 0 0 0.4rem 0.4rem rgba(161, 72, 45, 0.25);
border-radius: 0.3rem;
}
.accordion__title:hover {
cursor: pointer;
color: var(--textRed);
}
.accordion__title::after {
content: "";
display: block;
width: 1rem;
height: 0.6rem;
background-image: url("https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/icon-arrow-down.svg");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
transition: transform 300ms ease-in-out;
}
.accordion__text {
text-align: left;
padding: 0.5rem 3rem 2.2rem 0.5rem;
line-height: 1.5;
color: var(--textDarkBlue);
}
/* JS Classes */
.accordion__title.open {
font-weight: 700;
color: var(--textBlue);
}
.accordion__title.open::after {
transform: rotate(180deg);
}
.accordion__collapse.collapse {
display: none;
}
.accordion__collapse.collapsing {
height: 0;
overflow: hidden;
transition: height 1s ease;
}
.accordion__collapse.open {
display: block;
}
/* DESKTOP STYLE */
@media (min-width: 56em) {
.card {
position: relative;
display: flex;
padding: 6.1rem 9.4rem 8.4rem 0;
margin: 0;
background-image: url("https://raw.githubusercontent.com/MizAndhre/FAQ-accordion-card/2ff2a02d093554f14d0390a409e825669313a16e/images/bg-pattern-desktop.svg");
background-size: 100%;
/* background-position: -73rem center; */
background-position: -53rem -28rem;
}
.card__box {
display: block;
position: absolute;
z-index: 1;
top: 57%;
left: 0;
transform: translateX(-50%) translateY(-50%);
}
.card__img,
.card__text {
flex: 1;
}
.card__img {
display: flex;
align-items: center;
overflow: hidden;
padding-right: 9.2rem;
}
.card__img-mobile {
display: none;
}
.card__img-desktop {
display: block;
max-width: 47.2rem;
transform: translateX(-8.4rem);
}
.card__text {
margin-top: 0;
}
h1 {
padding-bottom: 2.1rem;
text-align: left;
}
.accordion__title {
font-size: 1.5rem;
}
.accordion__text {
line-height: 1.4;
padding: 0.5rem 3rem 2rem 0.5rem;
}
}
/* FOOTER */
.attribution {
text-align: center;
font-size: 1.5rem;
padding-bottom: 2rem;
color: var(--dividerGray);
}
.attribution a {
color: #fff;
text-decoration: none;
transition: color 200ms ease-in-out;
font-weight: 700;
}
.attribution a:hover {
color: var(--textRed);
}
.icons i {
margin-top: 1rem;
font-size: 2.5rem;
padding-right: 1rem;
}
const accordionBtns = document.querySelectorAll(".accordion__title");
accordionBtns.forEach((button) => {
button.addEventListener("click", (event) => {
let accCollapse = button.nextElementSibling;
if (!button.classList.contains("collapsing")) {
// open accordion item
if (!button.classList.contains("open")) {
accCollapse.style.display = "block";
let accHeight = accCollapse.clientHeight;
setTimeout(() => {
accCollapse.style.height = accHeight + "px";
accCollapse.style.display = "";
}, 1);
accCollapse.classList = "accordion__collapse collapsing";
setTimeout(() => {
accCollapse.classList = "accordion__collapse collapse open";
}, 300);
}
//close accordion item
else {
accCollapse.classList = "accordion__collapse collapsing";
setTimeout(() => {
accCollapse.style.height = "0px";
}, 1);
setTimeout(() => {
accCollapse.classList = "accordion__collapse collapse";
accCollapse.style.height = "";
}, 300);
}
button.classList.toggle("open");
}
});
});
Also see: Tab Triggers