Space between DIVs even after sing jquery Masonry - jquery-masonry

I am trying to arrange several dynamically multi-sized DIVs to fit in a container. As per members advice here in stackoverflow, I am trying to get the benefit of jquery masonry to get my job done. But I have problem as described below.
Is their any special tricks when using jquery masonry to solve this problem? I read their documentation, but I surely missed something.
If anybody can help, it'll be highly appreciated.
HTML CODE:
<div class="blockscont">
<div class="blocks" style="width:200px;height:200px">A</div>
<div class="blocks" style="width:400px;height:400px">B</div>
<div class="blocks" style="width:200px;height:200px">C</div>
<div class="blocks" style="width:200px;height:200px">D</div>
<div class="blocks" style="width:200px;height:200px">E</div>
<div class="blocks" style="width:200px;height:200px">F</div>
<div class="blocks" style="width:600px;height:200px">G</div>
<div class="blocks" style="width:200px;height:200px">H</div>
<div class="blocks" style="width:200px;height:200px">I</div>
<div class="blocks" style="width:400px;height:200px">J</div>
</div>
JQUERY MASONRY:
$(function() {
$(window).load(function(){
$('#blockscont').masonry({
itemSelector : '.blocks',
columnWidth : 0
});
});
});
OUTPUT:

I don't see a problem using Masonry for this layout, as long as the container is the correct size you will get the format you want.
I've set up your example in jsFiddle and it seems to work ok.
HTML (same as yours)
<div id="blockscont">
<div class="blocks" style="width:200px;height:200px">A</div>
<div class="blocks" style="width:400px;height:400px">B</div>
<div class="blocks" style="width:200px;height:200px">C</div>
<div class="blocks" style="width:200px;height:200px">D</div>
<div class="blocks" style="width:200px;height:200px">E</div>
<div class="blocks" style="width:200px;height:200px">F</div>
<div class="blocks" style="width:600px;height:200px">G</div>
<div class="blocks" style="width:200px;height:200px">H</div>
<div class="blocks" style="width:200px;height:200px">I</div>
<div class="blocks" style="width:400px;height:200px">J</div>
</div>
Script (simplified for use in jsfiddle)
$(function(){
$('#blockscont').masonry({
itemSelector: '.blocks'
});
});
I've removed the option columnWidth : 0 as it does not seem to make any difference.
CSS
.blocks {
background-color: #D7E4BC;
outline:1px solid white;
}
outline is used, not border, to show the blocks but prevent their size increasing and messing up the layout (in Chrome at least).
There should be no need to apply floats to any element as it is Masonry's job to position the blocks.

Just for posterity (as i came across this while having a similar problem) Gaps in the layout can be cause by incorrectly setting the columnWidth.
If you don't explicitly state the columnWidth it is taken from the width of the first item. My problem came about because my first item was supposed to cross two columns. I got over this by using another item's width to set columnWidth.
$('#m-container').masonry({
itemSelector: '.m-item',
columnWidth: $('.size1')[0]
});

Related

Modifying the <xp:section> Header

I have the following code:
<xp:section id="section1" type="box" header="Left Text Right Text">
Section content
</xp:section>
I'm using the Bootstrap3.2.0_flat theme so it displays the following: http://bit.ly/1kRu9QM
Is there a way to modify the xp:section header to have "Right Text" right aligned so that it displays the following?: http://bit.ly/1kRugMi
Thanks in advance for any tips.
I am not sure how you would do it with xpages sections, but with bootstrap you can use this.
<span class="pull-left">Left Text</span>
<span class="pull-right">Right Text</span>
Maybe you can drop the span in the section or maybe use bootstrap sections instead of xpages ones?
If you are looking to do something with bootstrap sections this is what I use.
Here is some css.
.panel-heading a:after {
font-family:'Glyphicons Halflings';
content:"\e114";
float: right;
color: grey;
}
.panel-heading a.collapsed:after {
content:"\e080";
}
And here is how I handled the div
<div class="panel-group" id="accordion">
<div class="panel panel-default" id="panel1">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-target="#collapseOne"
href="#collapseOne">
Section Header
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
</div>
Not sure if this is going to get you exactly where you want to be.
[edit]
Thinking more about this. I think you can use these sections. I have mine initially closed, and then you click on a section to expand.

Align photos and captions in a grid

I'm trying to align four pictures with their captions in a square grid.
I'm using the following HTML code:
<div class="grid">
<div class="post-block">
<img src="img1.jpg" />
<div class="caption">caption1</div>
</div>
<div class="post-block">
<img src="img2.jpg" />
<div class="caption">caption2</div>
</div>
<div class="post-block">
<img src="img3.jpg" />
<div class="caption">caption3</div>
</div>
<div class="post-block">
<img src="img4.jpg" />
<div class="caption">caption4</div>
</div>
</div>
and the following CSS code:
.post-block {
display: inline-block;
position: relative;
text-align: center;
}
If images and captions are the same size everything is ok, but when they are different I get this (an example):
I've tried to align images and captions of different sizes using CSS with no success. I need something like this:
Any help would be appreciated.
Thanks in advance
You'll need to use separate block elements at the same DOM level for the image and the caption to achieve what you've shown in the "RIGHT" image. Right now your caption DIV is nested inside the image DIV, and that's gonna do what you've shown. The caption DIV needs to be outside the image DIV.
You will probably want two separate div wrappers around each 2 photos..
Then align images vertically to bottom.
Vertical align images to bottom
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
<div class="myWrapClass">
<img src="my image">
<img src="my image">
</div>
then set the styling via inline or your css file
<div style="vertical-align:bottom;">
or
.myWrapClass{
vertical-align:bottom;
}
check out this site... Use the css properties there to keep it responsive
Example

Bootstrap 3 layout design

How can I make a layout shown in this image
I could have done it easily with grid system but I want the first post's description off the grid system or below the both column. However, for mobile devices I want it to appear with the image or in the same grid like the image below
I don't expect you can do this with Bootstrap's CSS only cause the order of your elements change from desktop to mobile.
Try this html:
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-12" style="background-color:red;">1</div>
<div class="rightblock col-md-6 col-xs-12">
<div class="row">
<div class="col-xs-12" style="background-color:lightgreen;">3</div>
<div class="col-xs-12" style="background-color:lightyellow;">4</div>
</div>
</div>
<div class="clearfix visible-md visible-lg"></div>
<div class="col-md-12 col-xs-12 lefttext" style="background-color:lightblue;">2</div>
</div>
</div>
Where 2 = the caption of your first item (1) and 3 and 4 are your second and third item.
For the mobile version use javascript to swap 2 (.lefttext) and the 3/4 block (.rightblock):
$(window).resize(function () {
if ($(window).width() < 992) {
$(".rightblock").insertAfter($(".lefttext"));
}
});
Demo: http://bootply.com/94560
Note 1: $(window).resize only will called on a real resize (from big to small) and not when opening the small screen direct. See here for better solution to react on screen size changes: How to detect responsive breakpoints of Twitter Bootstrap 3 using JavaScript?
Note 2: see http://getbootstrap.com/css/#grid-responsive-resets for explanation of the clearfix

Bootstrap: fluid layout with no external margin

if i have:
<div class="container-fluid">
<div class="row-fluid">
<div class="span8">
Some Element....
</div>
<div class="span4">
Other Element
</div>
</div>
</div>
With this code i have some margin from left and right window borders. How can eliminate these margins?
Thanks for your support
If i understand your question correctly, I believe you want this:
.container-fluid {
padding: 0px;
}
Also if you are using responsive bootstrap you will also want this:
#media (max-width: 797px) {
body {
padding-left: 0px;
padding-right: 0px;
}
}
Edit: here is a js fiddle.
The effect you are seeing is because of the container’s padding.
You can change the container’s default padding with the built-in Bootstrap 4 spacing utility classes.
To remove the padding, add p-0 to the container:
<div class="container-fluid p-0">
<div class="row">
<div class="col-8">
Some Element....
</div>
<div class="col-4">
Other Element
</div>
</div>
</div>
Using the built-in utility classes has the benefit of keeping your CSS lean and it also does not modify the default container-fluid class definition.

A negative value for svg attribute <width> is not allowed

I am trying to draw two google treemaps and keep them in tabs and am getting the error:
A negative value for svg attribute <width> is not allowed
Only one of the treemaps is visible. I am assuming the other one is not able to finish drawing. There is no other description of the error in the console. (Google chrome).
My code:
http://jsfiddle.net/tTqjr/
Solved the problem. The div element on which Google Annotated timeline was being created had display:none property. Just made sure that display:none is changed to display:block before calling the draw function.
Appreciate this wasn't the OP's issue, but I had the same error, and setting display: block; didn't make any difference for me, but I had padding-top: 50px; on the div for the chart, and removing that resolved the issue for me!
I wrapped my two divs in a boostrap row/col pair to solve and togglke them with hide()/show()/toggle() buttons.
From
<div class="row">
<div class="col-md-12" id="chart_div">
</div>
</div>
<div class="row">
<div class="col-md-12" id="chart_div2">
</div>
</div>
to:
<div class="row">
<div class="col-md-12">
<div id="chart_div">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="chart_div2">
</div>
</div>
</div>

Resources