In the following FAQ code,
why does the font size not get changed in the ‘.ans’ class display?
I have the ‘.faq’ class font size set larger than the ‘.ans’ font size,
but it appears that the ‘.ans’ class inherits the larger setting.
Is that as expected or what am I doing wrong to have
the answer font size smaller than the question font size.
[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″ />
<title> css FAQ </title>
<style>
p { color: black; }
div.faq { margin-top: 1em; cursor: pointer; font-size: 1.25em; }
.ans { font-size: 1em; color: red; }
.hide { display: none; }
</style>
</head>
<body>
<h1>FAQ Page (no nesting)</h1>
<div class=”faq”> FAQ 1 <div class=”hide ans”>Answer 1</div> </div>
<div class=”faq”> FAQ 2
<div class=”hide ans”>Answer 2
<p> <i>Additional</i> information about answer </p>
<p> <b>And even more</b> <i>additional</i> information about answer </p>
</div>
</div>
<div class=”faq”> FAQ 3 <div class=”hide ans”>Answer 3</div> </div>
<div class=”faq”> FAQ 4 <div class=”hide ans”>Answer 4</div> </div>
<div class=”faq”> FAQ 5 <div class=”hide ans”>Answer 5</div> </div>
<script>
function init() {
var sel = document.querySelectorAll(‘.faq’);
for (var i=0; i<sel.length; i++) {
sel[i].addEventListener(‘click’, function() { this.firstElementChild.classList.toggle(‘hide’); });
}
} init();
</script>
</body>
</html>