[英]Remove space between rows
I have a row for every dilemma/question and a image-button beside the questions.每个困境/问题都有一行,问题旁边还有一个图像按钮。 When I click the button, an answer for the specific question appears just below the question.当我单击该按钮时,特定问题的答案会出现在问题下方。 The answers are hidden until I click on a button to show them.答案是隐藏的,直到我点击一个按钮来显示它们。 However, before I click on button of a question, all the questions are listed with no answers shown.但是,在我单击问题按钮之前,所有问题都会列出,但没有显示答案。
The problem I want to solve is that there is too much space between the questions and I suppose that the reason is that the hidden text is between them.我想解决的问题是问题之间的空间太大,我想原因是隐藏的文本在它们之间。 I would like to fix that there is not much space between the question rows when no one is clicked, and then show the answer-text below the clicked question.我想解决当没有人点击时问题行之间没有太多空间的问题,然后在点击的问题下方显示答案文本。 It already shows the answer below the question after being clicked, but I want to remove the big space when it is not clicked.点击后它已经显示了问题下方的答案,但我想在没有点击时删除大空间。 The thing is that I don't even have any <br>
between the question and answer, and there is much space probably because of the hidden text.问题是我什至在问题和答案之间没有任何<br>
,而且可能是由于隐藏的文本而有很多空间。
Is it something I have to add to the CSS?我必须将其添加到 CSS 中吗? I show you what I have.我给你看我有什么。
<style>
.question-wrap {
margin-bottom: 2em
}
p.answer {
display: none
}
</style>
<script>
$(document).ready(function(){
$(".answer-toggle").click(function(){
$(this).closest('.question-wrap').find('.answer').toggle();
});
});
</script>
echo "<div class='question-wrap'><b><small>Dilemma ".$row['qid']." - Svar ". $row['aid'].":</small></b> ". $row['points']." av 10 <b><small>Poäng</small></b>
<button class='answer-toggle'><input type='image' title='Information' src='img/down.png' width='13' height='10'></button>
<p class='answer'>This is a paragraph with little content.</p></div>
<br>";
There is nothing wrong with your JavaScript or HTML, but your CSS has a pretty obvious problem.你的 JavaScript 或 HTML 没有任何问题,但你的 CSS 有一个非常明显的问题。
You have a margin-bottom: 2em;
你有一个margin-bottom: 2em;
on every question , along with a <br>
between each question/answer pair.在每个问题上,以及每个问题/答案对之间的<br>
。 All of that spacing is really adding up, so to remove the spacing, either所有这些间距真的加起来了,所以要删除间距,要么
Remove the margin-bottom
statement.删除margin-bottom
语句。
or或者
Remove the <br>
tag and change the margin-bottom
to something like 0.5em
.删除<br>
标签并将margin-bottom
更改为类似0.5em
。
I recommend doing the second option because CSS should in charge of styling, not HTML.我建议做第二个选项,因为 CSS 应该负责样式,而不是 HTML。
$(document).ready(function() { $(".answer-toggle").click(function() { $(this).closest('.question-wrap').find('.answer').toggle(); }); });
.question-wrap { margin-bottom: 0.5em; /* Change this to what you want */ } p.answer { display: none; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class='question-wrap'> <b>Question 1</b> <button class='answer-toggle'>Show Answer</button> <p class='answer'>Answer 1</p> </div> <div class='question-wrap'> <b>Question 2</b> <button class='answer-toggle'>Show Answer</button> <p class='answer'>Answer 2</p> </div> <div class='question-wrap'> <b>Question 3</b> <button class='answer-toggle'>Show Answer</button> <p class='answer'>Answer 3</p> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.