Three equal sized buttons in Bootstraper - html

I've started to use bootstraper. And I want a row with three buttons. The buttons should have the same height and width. How can I achieve this?
I have come up with the following, but this gives me different heights of the buttons.
<div class="row-fluid">
<div class="span2 offset1">
<a href="#" class="btn btn-info btn-block">
<div class="buttonbody">
<img src=".." />
<p>Button1<br />Second row<p>
</div>
</a>
</div>
<div class="span2 offset1">
<a href="#" class="btn btn-info btn-block">
<div class="buttonbody">
<img src=".." />
<p>Button2<p>
</div>
</a>
</div>
<div class="span2 offset1">
<a href="#" class="btn btn-info btn-block">
<div class="buttonbody">
<img src=".." />
<p>Button3<p>
</div>
</a>
</div>
</div>

To get the same height, you'll have to use jQuery to calculate the max then apply it to all the elements that should have the same height:
var selector = ".row-fluid .buttonbody";
var maxHeight = 0;
$(selector).each(function() {
var selfHeight = $(this).height();
if (selfHeight > maxHeight) {
maxHeight = selfHeight;
}
});
// set the same height on all elements
$(selector).height(maxHeight);
UPDATE: To resize buttons each time the window is resized, you can do the following:
// declare a function to be called
// each time buttons need to be resized
var resizeButtons = function() {
var selector = ".row-fluid .buttonbody";
var maxHeight = 0;
$(selector).each(function() {
var selfHeight = $(this).height();
if (selfHeight > maxHeight) {
maxHeight = selfHeight;
}
});
// set the same height on all elements
$(selector).height(maxHeight);
}
$(function() {
// attach function to the resize event
$(window).resize(resizeButtons);
// call function the first time window is loaded;
resizeButtons();
});
Hope that helps.

Short Answer : http://jsfiddle.net/D2RLR/2942/
Long Answer:
The following code does what you want.
<div class="container">
<strong>Button 1</strong>
<strong>Button 2</strong>
<strong>Button 3</strong>
</div>​
Here is tutorial for the same.
I recommend you go through twitter bootstrap documenation and bootsnipp.com for more information.
From your comments, as you say you are using <br/> you can use the following : fiddle,
<div class="container">
<strong>Button 1<br/>Second row</strong>
<strong>Button 2<br/> </strong>
<strong>Button 3<br/> </strong>
</diV>​

Related

How to add a hover event handler in JQuery, that will just target sibling elements with the same parent element?

how to make hover over one div to trigger changes in another div, but not to affect to another div with Jquery. Here is example
I know for this option but It's not working for me
$(function() {
$(".single-holder-image").hover(function() {
$(".read-more-a-black", this).css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(".read-more-a-black", this).css('color', '');
});
});
maybe I need to change html structure
<div class="big-holder">
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
<div class="single-post-holder">
<a class="" href="#">
<div class="single-holder-image">
<img src="https://i.picsum.photos/id/717/200/300.jpg?hmac=OJYQhMLNcYlN5qz8IR345SJ7t6A0vyHzT_RdMxO4dSc" alt="">
</div>
</a>
<div class="description-holder">
<p class="category name "></p>
<a class="read-more-a-black" href="#"><h5>Title 2</h5></a>
<a class="read-more-a-black-p" href="#">lorem test test test test</a>
<div class="pdf-holder">
<p>Tools:</p>
</div>
</div>
</div>
</div>
Also, will I be able to do the same when the mouse is hover over the title to trigger image and gets a transform: scale?
Use $(this) in the .hover() event handler callback.
This way just the very element where the event occured will be selected.
After that some JQuery DOM traversing with .parents() and .find() and problem solved:
$(document).ready(function() {
$(".single-holder-image").hover(function() {
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '#a2d0ba');
}, function() {
// on mouseout, reset the background colour
$(this).parents(".single-post-holder").find(".read-more-a-black").css('color', '');
});
});

Two Modals Windows On Page - But Only Displaying One

I'm not sure why this is happening. I'm using two separate modals with two separate scripts that are identifying two separate classes. The first is the "Specials" Modal Window and the second is the "Emergency" Modal Window. Yet when I click the "Specials" links the "Emergency" Modal window opens. When I click the Emergency model window, it opens fine. How can this be fixed so that it works as intended? Thanks in advance for your assistance.
HTML & JQUERY for First Modal Window
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front_03">
<img src="./images/free.png">
</div>
<div class="back_03">
<a class="button-to-click" href="#">
Blah...Blah..
Blah...Blah..<br />
[ CLICK HERE ]
</a>
</div>
</div>
</div>
<div class="popup-container">
<div class="specials_title">BLAH TITLE</div>
<p>Blah...Blah...Blah...</p>
<div class="coupon_container">
<p><div class="fa fa-star checked"></div> Blah.. Blah..</p>
<p><div class="fa fa-star checked"></div> Blah.. Blah..</p>
<p><div class="fa fa-star checked"></div> Blah.. Blah..</p>
<p><div class="fa fa-star checked"></div> Blah.. Blah..</p>
</div>
<a class="popup-close closer" href="#">X</a>
</div>
<script>
$(document).ready(function() {
// config
popup = $('.popup-container');
clickme = $('.button-to-click');
// pop-up
vh = $(window).height();
vw = $(window).width();
bw = popup.width();
bh = popup.height();
clickme.click(function(e) {
e.preventDefault();
popup.fadeOut();
popup.css('left', vw/2 - bw/2);
popup.css('top', vh/2 - bh/2);
popup.fadeIn();
});
//close button
$('.popup-close').click(function() {
$('.popup-container').fadeOut();
});
});
</script>
HTML & JQUERY for Second Modal Window
<div class="co_R_content">
<button type="button" class="click_emergency">
<div class="led-content">CLICK HERE</div>
<div class="led-box">
<div class="led-red"></div>
</div>
</button>
</div>
<div class="popup-container popup-emergency">
<div class="emergency_title">EMERGENCY?</div>
<p>Blah...Blah...Blah...</p>
<div class="entry-content">
<div class="wpforms-container">
<form id="wpforms-form">
<--- WPForms HTML Goes Here --->
</form>
</div> <!-- .wpforms-container -->
</div><!-- .entry-content -->
<a class="popup-close closer closer2" href="#">X</a>
</div>
<script>
$(document).ready(function() {
// config
popup = $('.popup-emergency');
clickme = $('.click_emergency');
// pop-up
vh = $(window).height();
vw = $(window).width();
bw = popup.width();
bh = popup.height();
clickme.click(function(e) {
e.preventDefault();
popup.fadeOut();
popup.css('left', vw/2 - bw/2);
popup.css('top', vh/2 - bh/2);
popup.fadeIn();
});
//close button
$('.popup-close').click(function() {
$('.popup-emergency').fadeOut();
});
});
</script>
Renamed the Variables in the second script from popup & clickme to different names and that did the trick.
FROM:
<script>
$(document).ready(function() {
// config
popup = $('.popup-emergency');
clickme = $('.click_emergency');
// pop-up
vh = $(window).height();
vw = $(window).width();
bw = popup.width();
bh = popup.height();
clickme.click(function(e) {
e.preventDefault();
popup.fadeOut();
popup.css('left', vw/2 - bw/2);
popup.css('top', vh/2 - bh/2);
popup.fadeIn();
});
//close button
$('.popup-close').click(function() {
$('.popup-emergency').fadeOut();
});
});
</script>
TO:
<script>
$(document).ready(function() {
// config
popup2 = $('.popup-emergency');
clickme2 = $('.click_emergency');
// pop-up
vh = $(window).height();
vw = $(window).width();
bw = popup2.width();
bh = popup2.height();
clickme2.click(function(e) {
e.preventDefault();
popup2.fadeOut();
popup2.css('left', vw/2 - bw/2);
popup2.css('top', vh/2 - bh/2);
popup2.fadeIn();
});
//close button
$('.popup-close').click(function() {
$('.popup-emergency').fadeOut();
});
});
</script>

hover effect on child div creating focus event on parent div

Consider the below code snippet:
<div class="row">
<div class="col-sm-12">
<div class="form-group form-group-default">
<label>OPTIONS</label>
<div class="checkbox">
<input type="checkbox" id="checkbox2">
<label for="checkbox2">Email</label>
</div>
</div>
</div>
</div>
Whenever I hover over the <div class="checkbox">, focus event of <div class="form-group form-group-default"> gets triggered; where as in css code I didnt find any relevant hover code for <div class="checkbox">.
As far as i know all events of DOM will get propagate through it's parents. Unless some event handler stops it.
Look at this example.
<!-- https://jsfiddle.net/z0ncxhfq/ -->
<div class="parent">
<a class="dontpropagate child" href="#one">Link one</a>
</div>
<div id="dont" class="parent">
<a class="child" href="#two">Link two</a>
</div>
<script>
var elements = document.querySelectorAll(".dontpropagate");
for(var i = 0, len = elements.length; i < len; ++i) {
elements[i].addEventListener("click", stopPropagation, false);
}
function stopPropagation(event) {
event.stopPropagation();
}
</script>
If I understood it right, you have to simply remove the form-group styling.
Try:
.form-group:focus,
.form-group:hover,
.form-group:active {
outline: none !important;
}

AdminLTE collapsed boxes by default

AdminLTE is based on Bootstrap: https://github.com/almasaeed2010/AdminLTE
Live Preview: http://almsaeedstudio.com/preview/
But I'm unsure as to how to make the collapsable boxes collapsed by default.
I'm assuming since it is built on Bootstrap, this should be rather straightforward. I've tried fellow implementations such as setting the id to "collapsedOne" and attempting to treat the divs as accordions, but to no avail.
On the AdminLTE/app.js ~line 45 there is code that implements slide up/slide down to collapse boxes. Ideally, what we'd want is to have the boxes be in the "slide up" state by default with the class "collapsed-box" so that when the icon is clicked, it executes "slide down".
/*
* Add collapse and remove events to boxes
*/
$("[data-widget='collapse']").click(function() {
//Find the box parent
var box = $(this).parents(".box").first();
//Find the body and the footer
var bf = box.find(".box-body, .box-footer");
if (!box.hasClass("collapsed-box")) {
box.addClass("collapsed-box");
bf.slideUp();
} else {
box.removeClass("collapsed-box");
bf.slideDown();
}
});
Any suggestions?
Thanks in advance.
When the page loads in its initial state, why not just add the collapsed-box class to box element?
The below will render in the collapsed state and function without modifying AdminLTE:
<!-- Default box -->
<div class="box box-solid collapsed-box">
<div class="box-header">
<h3 class="box-title">Default Solid Box</h3>
<div class="box-tools pull-right">
<button class="btn btn-default btn-sm" data-widget="collapse"><i class="fa fa-plus"></i></button>
<button class="btn btn-default btn-sm" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div>
<div style="display: none;" class="box-body">
Box class: <code>.box.box-solid</code>
<p>bla bla</p>
</div><!-- /.box-body -->
</div><!-- /.box -->
$("[data-widget='collapse']").click() Add that to a JavaScript file that runs at the bottom
Here are the steps:
Change the minus icon to plus .
Add explicit style "display:none" to box-body
Add the class "collapsed-box" to the box
For those who are using AdminLTE 2.1.1
just simply add sidebar-collapse class on the <BODY>
Before:
<body class="skin-blue sidebar-mini">
After:
<body class="skin-blue sidebar-mini sidebar-collapse">
An open box:
<div class="box">
A collapsed box:
<div class="box collapsed-box">
And then ofcourse change the icon on the button
In Admin LTE 3 collapse by default by using the class collapsed-card on the main card.
Like this
<div class="col-md-3">
 <div class="card collapsed-card">
   <div class="card-header" >
     <h3 class="card-title">Expandable</h3>
     <div class="card-tools">
       <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
       </button>
     </div>
   </div>
   <div class="card-body" >
     The body of the card
   </div>
 </div>
</div>
You should change the icon to a fas fa-plus then the initial box starts with a plus
$("[data-widget='collapse']").click(function() {
//Find the box parent........
var box = $(this).parents(".box").first();
//Find the body and the footer
var bf = box.find(".box-body, .box-footer");
if (!$(this).children().hasClass("fa-plus")) {.
$(this).children(".fa-minus").removeClass("fa-minus").addClass("fa-plus");
bf.slideUp();
} else {
//Convert plus into minus
$(this).children(".fa-plus").removeClass("fa-plus").addClass("fa-minus");
bf.slideDown();
}
});
and use in section div
for one specify div
$(function() { $('your-button-id').click(); })
for all
$(function() { $("[data-widget='collapse']").click(); })
Simply add "collapsed-box" to the box and change this:
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
to
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
This should work for me
The correct tested Steps which worked for me are :
Add explicit style "display:none" to box-body
You are done :)
<div class="box ">
<div class="box-header with-border bg-yellow">
<h3 class="box-title">Box Title Here</h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
<button class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
</div><!-- /.box-header -->
<div class="box-body" style="display: none;">
<div class="table-responsive">
<!--Your content here -->
</div><!-- /.table-responsive -->
</div><!-- /.box-body -->
</div>
<div class="box box-default collapsed-box">
<div class="box-header with-border">
<h3 class="box-title">Expandable</h3>
<div class="box-tools pull-right">
<button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
</div><!-- /.box-tools -->
</div><!-- /.box-header -->
<div class="box-body">
The body of the box
</div><!-- /.box-body -->
</div><!-- /.box -->
This soluction worked for me:
I added "collapse-left" class for the menu and added the "strech" class for the main content.
I use the version 1 for the AdminLTE. It is divided in aside class="left-side" for the left menu and aside class="right-side" for the main content.
So, this is the final code:
<aside class="left-side collapse-left">
<!-- put the left menu here -->
</aside>
<aside class="right-side strech">
<!-- put the main content here -->
</aside>
I added this to the boxWidget object:
setInitialCollapseStatus: function (container) {
var _this = this;
var collapsedBoxes = container.find('.box.collapsed-box .btn-box-tool > i');
collapsedBoxes.each(function (index) {
var box = $(this);
//Convert minus into plus
box
.removeClass(_this.icons.collapse)
.addClass(_this.icons.open);
});
}
and called it during initializiation:
activate: function (_box) {
var _this = this;
if (!_box) {
_box = document; // activate all boxes per default
}
//Listen for collapse event triggers
$(_box).on('click', _this.selectors.collapse, function (e) {
e.preventDefault();
_this.collapse($(this));
});
//Listen for remove event triggers
$(_box).on('click', _this.selectors.remove, function (e) {
e.preventDefault();
_this.remove($(this));
});
// Set initial collapseStatus
_this.setInitialCollapseStatus($(_box));
},
Add css classes into body tag in the index.html file:
sidebar-closed sidebar-collapse
<body class="hold-transition sidebar-mini sidebar-closed sidebar-collapse layout-fixed layout-navbar-fixed layout-footer-fixed">
With Adminlte 3:
Card Parent add ID: <div class="card card-default" id="a">
Change <i class="fas fa-minus"></i> TO => <i class="fas fa-plus"></i>
Add Display:none <div class="card-body" style="display:none">
Add jquery $('#a').CardWidget('toggle');

Bootstrap Responsive Product Grid

I am building a product grid built upon AngularJS data - where there will be images and product details (text)
The text sometimes extends to the 2nd line, causing havoc.
Here is my code:
<div class="row">
<div data-ng-repeat="s in Results">
<div class="col-xs-4">
<a href="#" class="thumbnail">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive">
</div>
<div>
{{s.Store}} {{s.Category}} {{s.ProductName}}
</div>
</a>
</div>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
This is what it looks like:
How do I fix it so that <div>s all have the same height?
I tried to look online for solutions, but I think I am 50% there. Please help.
Note: I Don't want to hide content.
This is what I ended up doing for anyone who stumbles on this again in the future.
Javascript
function ResizeToLargestElement(element) {
var maxHeight = -1;
if ($(element).length > 0) {
$(element).each(function () {
maxHeight = maxHeight > $(this).height() ? maxHeight : $(this).height();
});
$(element).each(function () {
$(this).height(maxHeight);
});
}
}
Without AngularJS
For those who aren't using AngularJS, just call ResizeToLargestElement() when data changes or the window is resized using
$(window).resize(function() {
ResizeToLargestElement('.AutoResizeToLargestElement');
});`
With AngularJS
The idea is to call the ResizeToLargestElement() function whenever $scope.Results changes or when the window resizes.
To know when $scope.Results changed is easy, but to know when elements (that are bound to it) finished rendering is not easy. To do that, you need a AngularJS directive.
To know when the window re-sizes, use angular.element($window).on('resize', function () {...});
HTML
<div class="row">
<div data-ng-repeat="s in Results" data-ng-repeat-finished> <!--ADDED Directive-->
<div class="col-xs-4">
<a href="#" class="thumbnail AutoResizeToLargestElement"> <!--ADDED Class-->
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive">
</div>
<div>
{{s.Store}} {{s.Category}} {{s.ProductName}}
</div>
</a>
</div>
<!--REMOVED clearfix-->
</div>
</div>
MyDirectives.js
angular.module('myApp').directive('ngRepeatFinished', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function () {
scope.$emit('ngRepeatFinished');
});
}
}
}
});
mycontroller.js
$scope.$on('ngRepeatFinished', function (ngRepeatFinishedEvent) {
ResizeToLargestElement(".AutoResizeToLargestElement");
});
angular.element($window).on('resize', function () {
ResizeToLargestElement(".AutoResizeToLargestElement");
});
Note: this requires you to include $window in the AngularJS dependency list.
I.E. angular.module('myApp').controller('....', ['...., '$window', ....]);
If you want to keep the height of each product dynamic, you will need to split the results into columns. And then use ng-if to put the right items in the right column. Every 3rd item will go into the same column. To set them to different columns, just reduce the $index by 1 for each extra column.
<div class="row">
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="$index%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="($index-1)%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
<div class="col-xs-4">
<div ng-repeat="s in Results"> <a href="#" class="thumbnail" ng-if="($index-2)%3==0">
<div>
<img ng-src="{{s.ProductImage}}" class="img-responsive" />
</div>
<div>{{s.Store}} {{s.Category}} {{s.ProductName}}</div>
</a>
<div class="clearfix visible-xs-block"></div>
</div>
</div>
</div>
You can manually restrict the height of the div and use an overflow. Use something like
<div class="col-xs-4" style="height:200px; overflow: auto;">Content</div>
Or, you could always use a responsive table (<table class="table table-responsive">) for your layout.
The best solution for this problem is to add clearfix class to hidden divs for earch size of viewport. for example:
Large size: i want 6 columns (large desktops)
Medium size: i want 4 columns (Desktops)
Tablets: i want 3 coumns
phones: i want 2 columns
so i have the products list:
<?php $count=1; foreach($productList as $product) : ?>
<div class="item col-xs-6 col-sm-4 col-md-3 col-lg-2">
Picture and description
</div><!-- /item -->
<?php if( ($count%2)==0) {?><div class="clearfix visible-xs-block"></div><?php }?>
<?php if( ($count%3)==0) {?><div class="clearfix visible-sm-block"></div><?php }?>
<?php if( ($count%4)==0) {?><div class="clearfix visible-md-block"></div><?php }?>
<?php if( ($count%6)==0) {?><div class="clearfix visible-lg-block"></div><?php }?>
<?php $count++; endforeach?>