I am working on simple FAQ section, and I need a little bit help.
The problem is that when I switch between questions, the expand/collapse arrow will stay UP. Do you have any suggestions?
$(document).ready(function(){
var nadpis = $('.nadpis');
nadpis.on('click', function () {
$(this).siblings().slideToggle()
$(this).children().toggleClass("off on")
nadpis.not(this).siblings().slideUp();
});
});
.textbox:first-child p {
display: none;
}
.nadpis {
display: flex;
flex-direction: row;
align-items: baseline;
justify-content: space-between;
gap: 5em;
border-bottom: 1px solid;
}
.off i:nth-child(2) {
display: none;
}
.off i:first-child {
display: block;
}
.on i:nth-child(2) {
display: block;
}
.on i:first-child {
display: none;
}
<link href="https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght#400;700&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/7a8caae1e8.js" crossorigin="anonymous"></script>
<section class="faq-content">
<div class="faq-textside">
<div class="faq-text">
<div class="textbox">
<div class="nadpis">
<h2>How many team members can I invite?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<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 class="textbox">
<div class="nadpis">
<h2>What is the maximum file upload size?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p> No more than 2GB. All files in your account must fit your allotted storage space.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>How do I reset my password?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p>Click “Forgot password” from the login page or “Change password” from your profile page.
A reset link will be emailed to you.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>Can I cancel my subscription?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p>Yes! Send us a message and we’ll process your request no questions asked.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>Do you provide additional support?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p> Chat and email support is available 24/7. Phone lines are open during normal business hours.</p>
</div>
</div>
</div>
</section>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
Here is full code pen
Your toggleClass call only affects the content of the clicked item. Extend the scope of this effect: first select the container element, and then find all relevant "on" elements, and the "off" elements below the clicked item, and toggle those:
$(this).closest(".faq-text").find(".on")
.add($(this).find(".off"))
.toggleClass("off on")
Snippet:
$(document).ready(function(){
var nadpis = $('.nadpis');
nadpis.on('click', function () {
$(this).siblings().slideToggle()
$(this).closest(".faq-text").find(".on")
.add($(this).find(".off"))
.toggleClass("off on")
nadpis.not(this).siblings().slideUp();
});
});
.textbox p {
display: none;
}
.nadpis {
display: flex;
flex-direction: row;
align-items: baseline;
justify-content: space-between;
gap: 5em;
border-bottom: 1px solid;
}
.off i:nth-child(2) {
display: none;
}
.off i:first-child {
display: block;
}
.on i:nth-child(2) {
display: block;
}
.on i:first-child {
display: none;
}
<link href="https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght#400;700&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/7a8caae1e8.js" crossorigin="anonymous"></script>
<section class="faq-content">
<div class="faq-textside">
<div class="faq-text">
<div class="textbox">
<div class="nadpis">
<h2>How many team members can I invite?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<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 class="textbox">
<div class="nadpis">
<h2>What is the maximum file upload size?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p> No more than 2GB. All files in your account must fit your allotted storage space.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>How do I reset my password?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p>Click “Forgot password” from the login page or “Change password” from your profile page.
A reset link will be emailed to you.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>Can I cancel my subscription?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p>Yes! Send us a message and we’ll process your request no questions asked.</p>
</div>
<div class="textbox">
<div class="nadpis">
<h2>Do you provide additional support?</h2>
<div class="off">
<i class="fas fa-chevron-down"></i>
<i class="fas fa-chevron-up"></i>
</div>
</div>
<p> Chat and email support is available 24/7. Phone lines are open during normal business hours.</p>
</div>
</div>
</div>
</section>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
Unrelated remark
Make sure to hide all involved <p> elements when the pages loads. In the CSS replace this:
.textbox:first-child p {
display: none;
}
...with just this:
.textbox p {
display: none;
}
Related
So It's a theme without a responsive logo and
I've been messing around trying to fix it but with any position it doesn't change /:
I wasted days trying to fix this but still it would not work
Does anyone have any suggestions or solutions how to fix this?
Html Code :
<a name="top" id="top"></a> <br /> <br />
<div id="mainwidth">
<div id="container">
<div id="content">
<div class="menu">
<ul>
<li id="nav-portal"><i style="font-size: 12px;" class="fa fa-home fa-fw"></i> Home</li>
<li id="nav-forums"> <i style="font-size: 12px;" class="fa fa-comments fa-fw"></i> Forums</li>
<li id="nav-search"> <i style="font-size: 12px;" class="fa fa-search fa-fw"></i> {$lang->toplinks_search}</li>
<li id="nav-member"> <i style="font-size: 12px;" class="fa fa-users fa-fw"></i> Members</li>
<li id="nav-instructions"><img src="img/new-icon.jpg" style="width: 20px;position:center;cursor:pointer;"> <i style="font-size: 12px;" class="fa fa-question-circle fa-fw"></i> Forum Instructions</li>
<li id="nav-calendar"> <i style="font-size: 12px;" class="fa fa-calendar fa-fw"></i> {$lang->toplinks_calendar}</li>
<li id="nav-help"> <i style="font-size: 12px;" class="fa fa-info fa-fw"></i> {$lang->toplinks_help}</li>
<li><i style="font-size: 14px;" class="fa fa-angle-down fa-fw"></i>More</li>
<ul>
</div>
<div id="extraslink_popup" class="popup_menu" style="display: none;">
<div class="popup_item_container">
Logout
</div>
<div class="popup_item_container">
Show team
</div>
<div class="popup_item_container">
{$lang->welcome_newposts}
</div>
<div class="popup_item_container">
{$lang->welcome_todaysposts}
</div>
<div class="popup_item_container">
Link five here
</div>
</div>
<div class="topbar">
<table width="100%" cellspacing="0" cellpadding="{$theme['tablespace']}" border="0">
<tr>
<td valign="top">
<!--- LOGOO CODE STARTS HERE -->
<div class="logo-b">
<img src="{$theme['logo']}" alt="{$mybb->settings['bbname']}" />
</div>
<!--- LOGOO CODE ENDS HERE -->
</td>
<td> </td>
<td valign="bottom">
<div style="margin-top: 120px;"><div class="userbg">{$welcomeblock}</div></div>
</td>
</tr>
</table>
</div>
<br />
<div class="wrapper">
{$pm_notice}
{$bannedwarning}
{$bbclosedwarning}
{$unreadreports}
{$pending_joinrequests}
{$awaitingusers}
<navigation>
<br />
<script type="text/javascript">
// <!--
if(use_xmlhttprequest == "1")
{
$("#extraslink").popupMenu();
}
// -->
</script>
And the CSS code :
#logo {
padding: 10px 0;
margin-top: 40px;
text-align: center;
max-width: 150px;
}
I've messed around alot with the CSS code but heres the original one
First of all, you didn't add an element with logo id, add it in html and change it in css. If the problem is still not resolved, check if you have added your css file to html. If the problem still persists, add display: block property to your logo in css and give margin
I'm trying to achieve an effect where on the hover of an element A, an element B is fadeOut and an element C is fadeIn, both inside the element A.
That's what I tried:
$('.button').hover(function() {
info = $(this).find('.info');
download = $(this).find('.download');
info.stop().fadeOut(150, function() {
download.stop().fadeIn(150);
})
}, function() {
download.stop().fadeOut(150, function() {
info.stop().fadeIn(150);
})
})
.button {
background-color: orange;
padding: 10px;
width: 250px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 10px;
}
.download {
display: none;
font-size: 17px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
Hovering one element at a time seems working fine but when you try to hover more elements concurrently the animation it starts to break.
Any solution? Other approaches are accepted. Thanks.
The main problem is to stop the animation before assigning another. This way there are no glitches:
$('.button').each(function(i) {
var thisButton = $(this);
var thisInfo = thisButton.find('.info');
var thisDownload = thisButton.find('.download');
thisButton.on('mouseenter', function(e) {
thisDownload.stop();
thisInfo.stop().fadeOut(150, function() {
thisDownload.stop().fadeIn(150);
});
}).on('mouseleave', function(e) {
thisInfo.stop();
thisDownload.stop().fadeOut(150, function() {
thisInfo.stop().fadeIn(150);
});
});
});
.button {
background-color: orange;
padding: 10px;
width: 250px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 10px;
}
.download {
display: none;
font-size: 17px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="button">
<div class="button_inner">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
</div>
<div class="button">
<div class="button_inner">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
</div>
<div class="button">
<div class="button_inner">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
</div>
Also on JSFiddle
Posting this because this may happen to skyline's answer:
You are inadvertently creating global variables for info and download by omitting the var, let, or const keywords. That means every function call is using and overwriting those variables. You need to create local variables in each function.
$('.button').hover(function() {
var info = $(this).find('.info');
var download = $(this).find('.download');
download.stop();
info.stop().fadeOut(150, function() {
download.stop().fadeIn(150);
})
}, function() {
var info = $(this).find('.info');
var download = $(this).find('.download');
info.stop();
download.stop().fadeOut(150, function() {
info.stop().fadeIn(150);
})
})
.button {
background-color: orange;
padding: 10px;
width: 250px;
height: 40px;
line-height: 40px;
text-align: center;
margin-bottom: 10px;
}
.download {
display: none;
font-size: 17px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
<div class="button">
<div class="info">
<i class="fas fa-download"></i> <strong>Mega Limited</strong> 1GB
</div>
<div class="download">Download</div>
</div>
I have a very simple module to develop. On click of an image I need to open up a div element that I have created.I have attached my HTML and javascript file.When I am loading the page the div wont be coming because I have given style="display:none
myfunction() {
document.getElementById('Chatbot').style.visibility = "visible";
}
<body>
<a href="#Chatbot" id="chat" onclick="myfunction()">
<img src="sticky.png" style="width:50px;height:50px">
</a>
<div id="Chatbot" style="display:none">
<div id="header">
Legal Genie
<div class="icons">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<i class="fa fa-refresh" aria-hidden="true"></i>
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</div>
<div><textarea rows="3" cols="20">Press enter to send your message</textarea>
</div>
</div>
</body>
document.getElementById('Chatbot').style.display = "block";
function myfunction() {
document.getElementById('Chatbot').style.display = "block";
}
<body>
<a href="#Chatbot" id="chat" onclick="myfunction()">
Some Image
</a>
<div id="Chatbot" style="display:none">
<div id="header">
Legal Genie
<div class="icons">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<i class="fa fa-refresh" aria-hidden="true"></i>
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</div>
<div><textarea rows="3" cols="20">Press enter to send your message</textarea>
</div>
</div>
</body>
Avoid using inline scripts and also avoid capitalising the first letter of your ID or class name.
Just add an event listener to your #chat anchor link that loads a function which sets the css display property of your div to block on click like this:
/* JavaScript */
var chat = document.getElementById("chat");
var div = document.getElementById('chatbot');
function showDiv(){
div.style.display = "block";
}
chat.addEventListener("click", showDiv);
/* CSS */
a {text-decoration: none; padding: 5px; background-color: green; color: white;}
#chatbot {display: none;}
<!-- HTML -->
<a type="button" href="#Chatbot" id="chat">Open Div</a>
<hr>
<div id="chatbot">
<div id="header">
Legal Genie
<div class="icons">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<i class="fa fa-refresh" aria-hidden="true"></i>
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</div>
<div><textarea rows="3" cols="20">Press enter to send your message</textarea>
</div>
It can be a simple way
<script>
$( document ).ready(function() {
$('#chat').click( function(){
if ( $('#Chatbot').hasClass('active') ) {
$('#Chatbot').removeClass('active');
} else {
$('#Chatbot').addClass('active');
}
});
});
</script>
Add lil css
<style>
.active {
display:block!important;
}
</style>
Your HTML
<body>
<div id="chat">
Some Image
</div>
<div id="Chatbot" style="display:none">
<div id="header">
Legal Genie
<div class="icons">
<i class="fa fa-question-circle" aria-hidden="true"></i>
<i class="fa fa-refresh" aria-hidden="true"></i>
<i class="fa fa-times" aria-hidden="true"></i>
</div>
</div>
<div><textarea rows="3" cols="20">Press enter to send your message</textarea>
</div>
</div>
</body>
Hello I am trying to make a toggle for multiple elements in jQuery but it not working the plus button when click does not slide toggle the element please help here is the link
HTML
<!-post begin-- post 4 >
<div class="col-xs-12 post-card">
<div class="col-xs-3">
</div>
<div class="col-xs-7 post-start" >
hello this is a test caption
</div>
<div class="col-xs-2">
<button class="fa fa-plus plus-icon post-btn11" type="button">+</button>
</div>
<div class="collapse col-xs-12" style="font-size: 16px; color:#646464;">
<i class="fa fa-comments comment2"></i> <span>10 comments</span><span class="margin-left-10"><i class="fa fa-heart"></i>
10 likes</span>
</div>
</div>
<!-post end for post 4-->
<!-post begin-- post 5 >
<div class="col-xs-12 post-card">
<div class="col-xs-3">
</div>
<div class="col-xs-7 post-start" >
This is a test comment
</div>
<div class="col-xs-2">
<button class="fa fa-plus plus-icon post-btn11" type="button" >+</button>
</div>
<div id="post-info" class="collapse col-xs-12" style="font-size: 16px; color:#646464;">
<i class="fa fa-comments comment2"></i> <span>11 comments</span><span class="margin-left-10"><i class="fa fa-heart"></i>
13 likes</span>
</div>
</div>
<!-post end for post 5-->
CSS
.post-card {
background-color: #f4f4f4;
padding: 10px;
border: 1px solid #eee;
margin-top: 10px;
}
.fa {
float: right;
}
.post.info {
display: none;
}
jQuery
$(document).ready(function(){
$(".post-btn11").click(function(){
$(this).siblings(".post-info").slideToggle();
});
});
Totally wrong selector post-info is an id not a class, then post-info not siblings of post-btn11 but it's parent siblings, so the selector should like this:
$(".post-btn11").click(function(){
$(this).parent().siblings('#post-info').slideToggle();
});
But better use class because it should repeat and not unique. Also add this class to first one too.
$(".post-btn11").click(function(){
$(this).parent().siblings('.post-info').slideToggle();
});
JSFiddle
Here is the correction to your code. I have also updated your fiddle so go check it out. You had a problem with giving your post-info element an ID. In corrected version I simply add post-info as a class name. And also the .sublings() function will not work, since you applied it to your button element and it will not find any nested elements in it. So I needed to find a button's parent element first to get on the "same level" with your next post-info element and then simply use .next() function
$(document).ready(function(){
$(".post-btn11").click(function(){
$(this).parent(".col-xs-2").next(".post-info").slideToggle();
});
});
.post-card {
background-color: #f4f4f4;
padding: 10px;
border: 1px solid #eee;
margin-top: 10px;
}
.fa {
float: right;
}
.post.info {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-post end for post 3-->
<!-post begin-- post 4 >
<div class="col-xs-12 post-card">
<div class="col-xs-3">
</div>
<div class="col-xs-7 post-start" >
hello this is a test caption
</div>
<div class="col-xs-2">
<button class="fa fa-plus plus-icon post-btn11" type="button">+</button>
</div>
<div class="collapse col-xs-12 post-info" style="font-size: 16px; color:#646464;">
<i class="fa fa-comments comment2"></i> <span>10 comments</span><span class="margin-left-10"><i class="fa fa-heart"></i>
10 likes</span>
</div>
</div>
<!-post end for post 4-->
<!-post begin-- post 5 >
<div class="col-xs-12 post-card">
<div class="col-xs-3">
</div>
<div class="col-xs-7 post-start" >
This is a test comment
</div>
<div class="col-xs-2">
<button class="fa fa-plus plus-icon post-btn11" type="button" >+</button>
</div>
<div class="collapse col-xs-12 post-info" style="font-size: 16px; color:#646464;">
<i class="fa fa-comments comment2"></i> <span>11 comments</span><span class="margin-left-10"><i class="fa fa-heart"></i>
13 likes</span>
</div>
</div>
<!-post end for post 5-->
I have a div with some text and another one that I'm filling it with a list of photos and a footer div. The footer div should be below photos div but it gets under it. This is my code:
div.gallery {
margin: 5px;
border: 2px solid #ccc;
float: left;
width: 280px;
}
div.gallery:hover {
border: 2px solid #777;
}
div.gallery img {
width: 80%;
height: auto;
margin: auto;
}
div.desc {
padding: 15px;
text-align: left;
}
<div>
<p>Software Engineer
</div>
<div id="test">
<div id="comments">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
<div id="footer" style="background:blue;height:100px;width:100%">
<div style="background:blue;height:200px;width:100%"></div>
</div>
Ans here is a screenshot of it
How can i fix it?
Issue may be because of the floats. Try using Clearfix
Try adding this class to comments.
(Modified Some HTML)
Give this a try.
HTML
<div>
<p>Software Engineer
</div>
<div id="test">
<div id="comments" class="clearfix">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
</div>
<div id="footer" style="background:blue;width:100%">
<div style="background:blue;width:100%"> footer div here</div>
</div>
CSS
.clearfix::after {
content: "";
display: table;
width: 100%;
clear: both;
}
div.gallery {
margin: 5px;
border: 2px solid #ccc;
float: left;
width: 280px;
}
div.gallery:hover {
border: 2px solid #777;
}
div.gallery img {
width: 80%;
height: auto;
margin: auto;
}
div.desc {
padding: 15px;
text-align: left;
}
.clearfix::after {
content: "";
width: 100%;
display: table;
clear: both;
}
<div>
<p>Software Engineer
</div>
<div id="test">
<div id="comments" class="clearfix">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
</div>
<div id="footer" style="background:blue;width:100%">
<div style="background:blue;width:100%"> footer div here</div>
</div>
Link for reference
Hope this helps…
UPDATED Your floats are not cleared. Use #Chandras example or you can add a CSS ID #footer { clear:both; } and call on it in your footer div as you have in your example already. <div id=footer">.
Bonus, add your style="width:100%; height:200px; background:blue; color:#FFF;" line to your css file and remove the style attr from your div footer tag all together.
In your example snipit, I used a class with clear in your footers ID.
Check it:
div.gallery {
margin: 5px;
border: 2px solid #ccc;
float: left;
width: 280px;
}
div.gallery:hover {
border: 2px solid #777;
}
div.gallery img {
width: 80%;
height: auto;
margin: auto;
}
div.desc {
padding: 15px;
text-align: left;
}
#footer {
clear:both;
width:100%;
height:200px;
background:blue;
color:#FFF;
}
<div>
<p>Software Engineer
</div>
<div id="test">
<div id="comments">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
<div id="footer">Footer
</div>
FYI
Bootstrap V3 soon to release v4.
CDN: Bootstrap CDN link
BS V3 Grid System: specific grid layout system
Bootstrap is an open source plugin that uses a standardized set of css and js rules already coded for you.
Among the many other awesome css and js additions, float your html tags using a standardized set of classes known as cols. These are used with media short cuts: xs, sm, md, lg, then add a division of 12, so you get something like. <div class="gallery col-xs-12 col-sm-12 col-md-4 col-lg-4"> (col-md-4 means you are using up 4 of the 12 increments for a single div. You have 3 gallery divs, so 3 X 4 = 12 = col-md-4) These validate for different screen size media.
Here is the layout from bootstrap grid per media:
/* Extra small devices (phones, less than 768px) */
/* No media query since this is the default in Bootstrap */
/* Small devices (tablets, 768px and up) */
#media (min-width: #screen-sm-min) { ... }
/* Medium devices (desktops, 992px and up) */
#media (min-width: #screen-md-min) { ... }
/* Large devices (large desktops, 1200px and up) */
#media (min-width: #screen-lg-min) { ... }
// Extra small devices Phones (<768px) = .col-xs
// Small devices Tablets (≥768px) = .col-sm
// Medium devices Desktops (≥992px) = .col-md
// Large devices Desktops (≥1200px) = .col-lg
So by looking at my example, class="col-xs-12" on phones we would get one div that would be width=100%;. Where as "col-md-4" on lap tops and desk tops with resolution of any media larger than 992px we would get the divs stacked side by side at width=33.33%;
Best to just read up on bootstrap as it is a bit to get into in one of these forums. It is actually very simple to add and use if you read up on it and how it works.
There is also Bootply -> Bootstrap online editor, there are some amazing tools there to help you get started using bootstrap!
Hope this helps...
Remember that float are removed from normal document flow. You should clear floats when using them.
But I suggest you to rewrite your float code using flexbox. In this case you can remove floats because they will be ignores. Demo:
#comments {
/* specify element as flex-container */
/* its children will be treated as flex items */
display: flex;
/* allow moving elements to next line */
flex-wrap: wrap;
}
div.gallery {
margin: 5px;
border: 2px solid #ccc;
width: 280px;
}
div.gallery:hover {
border: 2px solid #777;
}
div.gallery img {
width: 80%;
height: auto;
margin: auto;
}
div.desc {
padding: 15px;
text-align: left;
}
<div>
<p>Software Engineer
</div>
<div id="test">
<div id="comments">
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 74</i>
<i class="fa fa-comment-o" style="color:#333;"> 0</i>
<button id="1547014733616513536_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 65</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1535724697949655394_414010731">comment</button>
</div>
</div>
<div class="gallery">
<img src="https://example.com">
<div class="desc">
<i class="fa fa-thumbs-o-up" style="color:red;"> 68</i>
<i class="fa fa-comment-o" style="color:#333;"> 1</i>
<button id="1501575131271622723_414010731">comment</button>
</div>
</div>
</div>
<div id="footer" style="background:blue;height:100px;width:100%">
<div style="background:blue;heoght:200px;width:100%"></div>
</div>
</div>
You can replace This Code.
<div style="background:blue;height:200px;width:100%"></div>
Your issue that your comments container height is not correct, it is is not considering the inner nodes size.
So give comments overflow:hidden; or a fixed height or minheight
#footer {
float:left;
width:100%;
}