How to keep CSS blocks equal? - css

I am creating a virtual store where the main page shows the products, this is where the quantity of information in the detail of the product varies, the blocks begin to deform. How could you do to keep the size constant and in any case the text is truncated?
I'm working with MVC 5 and Bootstrap.
<!-- Bloque 1 -->
#foreach (var item in Model)
{
<div class="col-sm-3 col-lg-3 col-md-3">
<div class="thumbnail">
<!-- TRAE UNA IMAGEN DE CUALQUIER MANERA-->
<img src="#Url.Action("RenderImage", new { id = item.ProductoID})" alt="" width="150" height="320" />
<div class="panel panel-yellow">
<div class="panel-heading">
<h4 class="pull-right">$#item.PrecioUnitario</h4>
<h4>
<a href="#Url.Action("Detalle", new { id = item.ProductoID })" class="my-class">
#item.Nombre
</a>
</h4>
</div>
</div>
<div class="ratings">
#*<p>See more snippets like this online store item at <a target="_blank" href="http://www.bootsnipp.com">Bootsnipp - http://bootsnipp.com</a>.</p>*#
<p>#item.DetallesCorto</p>
</div>
<div class="ratings">
<p class="pull-right">15 Me gusta</p>
<p>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
<span class="fa fa-fw fa-star"></span>
</p>
<p>
<button type="button" class="AddLink btn btn-block btn-success btn-xs" href="#" data-id="#item.ProductoID" data-toggle="modal" data-target="#myModal">
<i class="fa fa-fw fa-shopping-cart"></i> Agregar
</button>
</p>
</div>
<div class="ratings">
#if (Request.IsAuthenticated && User.IsInRole("Root") || User.IsInRole("Admin"))
{
<p>
<button type="button" class="anchorDetail btn btn-block btn-info btn-xs"
href="javascript:void(0);" data-id="#item.ProductoID">
<i class="fa fa-pencil"></i> Edicion rápida
</button>
</p>
<p>
<button type="button" class="popupDelete btn btn-block btn-danger btn-xs"
href="javascript:void(0);" data-id="#item.ProductoID">
<i class="fa fa-trash"></i> Eliminar
</button>
</p>
}
</div>
</div>
</div>
} <!-- Cierro Forech -->
</div>
That's how it looks now:

Solution 1 (CSS)
Set a fixed height on the red paragraph and the title and hide the overflow.
.thumbnail .ratings:nth-of-type(1) p {height: 100px; overflow: hidden;}
.thumbnail h4:nth-child(2) {height: 30px; overflow: hidden;}
Solution 2 (jQuery)
Create a javascript function setting the height equal to the tallest red paragraph and the tallest title.
var maxh = 0;
$('.thumbnail .ratings:nth-of-type(1) p').each(function() {
var h = $(this).height();
if(h > maxh) maxh = h;
});
$('.thumbnail .ratings:nth-of-type(1) p').css('height', maxh);
var maxh = 0;
$('.thumbnail h4:nth-child(2)').each(function() {
var h = $(this).height();
if(h > maxh) maxh = h;
});
$('.thumbnail h4:nth-child(2)').css('height', maxh);
You might be tempted to set a fixed height to the thumbnail div. But that will require you to set the rating stars and the green button to position: absolute; bottom: [amount]px; to align them properly. I am quite sure that is not compatible with the bootstrap floats and the responsive behaviour of these items.

You can loop through each .thumbnail item and find the max height, then apply a min-height to each element matching that max height:
$(document).ready(function() {
var maxHeight = 0;
$('.thumbnail').each(function() {
var height = $(this).height();
if(height > maxHeight) {
maxHeight = height;
}
});
$('.thumbnail').css('min-height', maxHeight);
});
You may need to utilize a delay such as setTimeout to ensure everything has been loaded prior to calculating the heights.

You should use rows or set equal height to all boxes with javascript/jquery. Bootstrap uses 12 cols per row so you could modify your code to separate by 4 items per row. Also you only need the smallest device col width if larger ones are same. In your case use col-sm-3 only.
<div class="row">
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
<div class="col-sm-3" ></div>
</div>

Give the boxes a set height for example:
.box {
height: 150px;
}

Related

Bootstrap modal-dialog resize with Maximize/Minimize icons in Angular 7

I am using Bootstrap Model-dialog popup to display my content in my Angular 7 application. using this in multiple places, I am changing the width and height of popup against the content loaded.
Now I need to add the Minimize/Maximize icons to popup. Users can resize the popup by clicking on min/max icons. is there any property to resize popup width and height.
this.showModelPopup.open().then((result) => {
}, (reason) => {
});
In Html
<div class="modal-dialog">
<ng-template #content let-modal>
<div id="Status" data-grid="col-md-12">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" (click)="">
<span aria-hidden="true">×</span>
</button>
<button type="button" class="close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
<div>
// My content here
</div>
</div>
</div>
</div>
</ng-template>
Your angular html template is going to look like this:
<div class="modal-dialog" id="my-modal-dialog">
<div class="modal-content">
<form>
<div class="modal-header">
<span class="fa fa-window-maximize cursor-pointer modal-resize" (click)="maximize();" *ngIf="!this.isMaximize" title="Maximize"></span>
<span class="fa fa-window-restore cursor-pointer modal-resize" (click)="restore()" *ngIf="this.isMaximize" title="Restore"></span>
Your header
</div>
<div class="modal-body" id="my-modal-body">
Your body
</div>
<div class="modal-footer">
Your footer
</div>
</form>
</div>
And your respective angular component .ts class file going to have following:
isMaximize = false;
maximize() {
this.isMaximize = !this.isMaximize;
document.getElementById('my-modal-dialog').style.maxWidth = "100%";
document.getElementById('my-modal-dialog').style.margin = "auto";
document.getElementById('my-modal-dialog').style.display = "inline";
document.getElementById('my-modal-body').style.maxHeight = "calc(100vh - 139px)";
}
restore() {
this.isMaximize = !this.isMaximize;
document.getElementById('my-modal-dialog').style.maxWidth = "";
document.getElementById('my-modal-dialog').style.margin = "";
document.getElementById('my-modal-dialog').style.display = "block";
document.getElementById('my-modal-body').style.maxHeight = "calc(100vh - 190px)";
}

Set css style on click and remove them on click

I want to set style when I click on div. I done this, It's work. But I want when its clicked and when I click to set the default style.
$('#tray-button').click(function() {
$('.buttons-content').css('bottom', '160px');
});
<div class="buttons-content">
<div id="tray-button" class="button">
<div class="white"></div>
<div class="black"></div>
<i class="fas fa-grip-horizontal"></i>
</div>
<div class="button">
<div class="white"></div>
<div class="black"></div>
<i class="fas fa-share-alt"></i>
</div>
<div class="button play-pause play">
<div class="white"></div>
<div class="black"></div>
<i class="far fa-1-1x fa-play-circle"></i>
</div>
<div class="button rotate">
<div class="white"></div>
<div class="black"></div>
<i class="fas fa-expand-alt"></i>
</div>
</div>
buttons-content - default bottom: 40;
When click on #tray-button -> bottom: 160px;
When click again on #tray-button -> bottom: 40px; (default)
Define a specific CSS rule e.g.
.buttons-content.toggled {
bottom: 160px;
}
with a .toggled class and on click toggle that class
$('#tray-button').click(function() {
$('.buttons-content').toggleClass('toggled');
});
When the class is removed the style of the element will be automatically reset to the previous state. Furthermore your script is more mantainable because the style is not hardcoded within.
this script just remembers the last state and does whatever you want.
$( document ).ready(function() {
var stack = 0
$("#tray-button").click(function()
{
if (stack === 0){
}
$('.buttons-content').css('bottom', '160px');
stack = 1;
}else{
$('.buttons-content').css('bottom', '40px');
stack = 0;
}
});

Center a button between two others in OnsenUI

How do I center a button between two other buttons in a toolbar?
Here's my code and resulting screenshot
<div id="toptoolbar">
<button class="toolbar-button">
<i class="fa fa-comments" style="font-size:17px"></i>
</button>
<button class="toolbar-button">
My title
<!-- text-purple center-block doesn't work -->
</button>
<button class="toolbar-button pull-right">
<i class="fa fa-ellipsis-v" style="font-size:17px"></i>
</button>
</div>
I'm using OnsenUI (and will be using VUE with it) so is there a class I can simply add from bootstrap or any other framework included with OnsenUI?
Or can I use some custom CSS to do this?
Similar to this question but with OnsenUI and Monaca (so good for both ios and android)
<div id="toptoolbar">
<button class="toolbar-button">
<i class="fa fa-comments" style="font-size:17px"></i>
</button>
<span class="stretcher"></span>
<button class="toolbar-button">
My title
<!-- text-purple center-block doesn't work -->
</button>
<span class="stretcher"></span>
<button class="toolbar-button pull-right">
<i class="fa fa-ellipsis-v" style="font-size:17px"></i>
</button>
</div>
CSS:
#toptoolbar {
display: flex;
align-items: center;
justify-content: center;
}
.stretcher {
flex: 1;
}
// HTML
<div id="toptoolbar">
<button class="toolbar-button">
<i class="fa fa-comments" style="font-size:17px"></i>
</button>
<button class="toolbar-button title">
My title
<!-- text-purple center-block doesn't work -->
</button>
<button class="toolbar-button pull-right">
<i class="fa fa-ellipsis-v" style="font-size:17px"></i>
</button>
</div>
//CSS
.toolbar-button.title{
position: absolute;
left: 49%;
}
This is just a plain css solution.
updated Fiddle http://jsfiddle.net/JfGVE/2459/

Align bootstrap dropdown in input-group to left (underneath the start of the input)

I have a input group (text input and button with dropdown). I am having trouble getting my dropdown to align with the text box.
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<input type="text" class="form-control" />
<div class="input-group-btn">
<div class="dropdown open">
<button class="btn btn-secondary dropdown-toggle"
type="button"
id="dropdownMenuButton"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
dropdown
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
I have tried <div class="dropdown-menu dropdown-menu-left"> with no avail.
Here is a fiddle
What do I need to add to this to align my dropdown menu to the left underneath the start of the input (as if it was a typeahead)?
EDIT: within the dropdown menu is an angular directive, that's likely a relative tool
Here is the Quick Fix
Working Demo Here
HTML:
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="input-group">
<div class="testing">
<input type="text" class="form-control" />
</div>
<div class="input-group-btn">
<div class="dropdown open">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="false" aria-expanded="false">dropdown</button>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuButton">
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.testing {
position: relative;
}
JS:
$(document).ready(function() {
dropmenuWidgetPosition();
function dropmenuWidgetPosition() {
$('#dropdownMenuButton').dropdown('toggle');
$(window).on('show.bs.dropdown', function(e) {
var dropdownMenu = $(e.target).find('.dropdown-menu');
var dropMenuDetach = dropdownMenu.detach();
// detach it and append it to the target
$(e.target).parents('.input-group').eq(0).find('.testing').append(dropMenuDetach);
// grab the new offset position
var eOffset = $(e.target).offset();
// make sure to place it where it would normally go (this
// could be
// improved)
dropdownMenu.css({
'display': 'block',
'top': eOffset.top + $(e.target).outerHeight(),
'left': 0
});
});
// and when you hide it, reattach the drop down, and hide it
// normally
$(window).on('hide.bs.dropdown', function(e) {
var dropdownMenu = $(e.target).parents().find('.dropdown-menu');
var dropMenuDetach = dropdownMenu.detach();
$(e.target).append(dropMenuDetach);
dropdownMenu.hide();
});
}
});

Set a button group's width to 100% and make buttons equal width?

I'm using Bootstrap, and I'd like to set an entire btn-group to have a width of 100% of its parent element. I'd also like the inner buttons to take equal widths. As it is, I can't achieve either.
I've made a JSFiddle here: http://jsfiddle.net/BcQZR/12/
Here is the HTML:
<div class="span8 background">
<div class="btn-group btn-block" id="colours">
<span class="btn"><input type='checkbox' name='size' value='red'/>red</span>
<span class="btn"><input type='checkbox' name='size' value='orange'/>orange</span>
<span class="btn"><input type='checkbox' name='size' value='yellow'/>yellow</span>
</div> <!-- /btn-group -->
</div>
And here is my current CSS, which doesn't work:
#colours {
width: 100%;
}
Bootstrap has the .btn-group-justified css class.
How it's structured is based on the type of tags you use.
With <a> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
...
</div>
With <button> tags
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Left</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Middle</button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default">Right</button>
</div>
</div>
There's no need for extra css the .btn-group-justified class does this.
You have to add this to the parent element and then wrap each btn element in a div with .btn-group like this
<div class="form-group">
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="submit" id="like" class="btn btn-lg btn-success ">Like</button>
</div>
<div class="btn-group">
<button type="submit" id="nope" class="btn btn-lg btn-danger ">Nope</button>
</div>
</div>
</div>
BOOTSTRAP 2 (source)
The problem is that there is no width set on the buttons. Try this:
.btn {width:20%;}
EDIT:
By default the buttons take an auto width of its text length plus some padding, so I guess for your example it is probably more like 14.5% for 5 buttons (to compensate for the padding).
Note:
If you don't want to try and compensate for padding you can use box-sizing:border-box;
http://www.w3schools.com/cssref/css3_pr_box-sizing.asp
I don't like the solution of settings widths on .btn because it assumes there'll always be the same number of items in the .btn-group. This is a faulty assumption and leads to bloated, presentation-specific CSS.
A better solution is to change how .btn-group with .btn-block and child .btn(s) are display. I believe this is what you're looking for:
.btn-group.btn-block {
display: table;
}
.btn-group.btn-block > .btn {
display: table-cell;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/123/
If you'd prefer to have equal-width buttons (within reason) and can support only browsers that support flexbox, try this instead:
.btn-group.btn-block {
display: flex;
}
.btn-group.btn-block > .btn {
flex: 1;
}
Here's a fiddle: http://jsfiddle.net/DEwX8/124/
For bootstrap 4 just add this class:
w-100
Bootstrap 4 removed .btn-group-justified. As a replacement you can use <div class="btn-group d-flex" role="group"></div> as a wrapper around elements with .w-100.
Try this:
<div class="btn-group d-flex" role="group>
<button type="button" class="btn btn-primary w-100">Submit</button>
<button type="button" class="btn btn-primary w-100">Cancel</button>
</div>
Angular - equal width button group
Assuming you have an array of 'things' in your scope...
Make sure the parent div has a width of 100%.
Use ng-repeat to create the buttons within the button group.
Use ng-style to calculate the width for each button.
<div class="btn-group"
style="width: 100%;">
<button ng-repeat="thing in things"
class="btn btn-default"
ng-style="{width: (100/things.length)+'%'}">
{{thing}}
</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="btn-group btn-block">
<button type="button" data-toggle="dropdown" class="btn btn-default btn-xs btn-block dropdown-toggle">Actions <span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span></button><ul role="menu" class="dropdown-menu"><li>Action one</li><li class="divider"></li><li><a href="#" >Action Two</a></li></ul></div>
Bootstrap 4
<ul class="nav nav-pills nav-fill">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Longer nav link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
Bootstrap 4 Solution
<div class="btn-group w-100">
<button type="button" class="btn">One</button>
<button type="button" class="btn">Two</button>
<button type="button" class="btn">Three</button>
</div>
You basically tell the btn-group container to have width 100% by adding w-100 class to it. The buttons inside will fill in the whole space automatically.

Resources