Responsive grid with masonry - responsive-design

I want to build a responsive masonry grid like THIS
I have this HTML
<div class="js-masonry" data-masonry-options='{ "gutter": 20 }'>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
</div>
and the SCSS
article{
width: 100%;
float: left;
#include breakpoint(medium) {
width: 50%;
}
#include breakpoint(large) {
width: 33.33333%;
}
}
When I remove the gutter daclared in the html the grid works as I want, but with it it displays 2 at the large breakpoint and 1 at medium. How can I get this to work with using margins to space out the article horizontally?

The problem is that masonry.js adds a margin to the element making the element 50% + 20px wide, with is to big to fit on one row.
The solution is to make the elements and gutter fit in your wrapper by making the gutter + elements in a row = wrapper. If you have a flexible layout this would be a problem as masonry.js only takes a fixed px as gutter size.
So if (like in you example) you make the elements a fixed width this would be no problem. But masonry.js has a solution; if you sett the gutter not to a fixed width but to a element, masonry.js will use the width of that element. So a flexible solution could be to do this:
<div class="js-masonry"
data-masonry-options='{ "gutter": ".gutter-sizer", "itemSelector": "article"}'>
<div class="gutter-sizer"></div>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
<article></article>
</div>
and the Scss
article {
width: 100%;
float: left;
#include breakpoint(medium) {
width: 49.2%;
}
#include breakpoint(large) {
width: 32.26%;
}
}
.gutter-sizer {
width: 0%;
#include breakpoint(medium and large) {
width: 1.6%; //About 20px on a regular monitor at full width.
}
}

Related

Changing the height of ng-table

I am dynamically creating tables using ng-table, based on the json data. Ng-tables automatically adjust their height based on the amount of rows.
Is there a way that I can fix the size of the tables, so all of them are of the same size, based on the table with the maximum rows (maximum height)?
You can do it by wrapping your table tag inside a div and then give height to that wrapper div. Give height and width to wrapper div and also give overflow-y:scroll
CSS
#scrollable-area {
margin: auto;
width: 80%;
height: 150px;
border: 2px solid #ccc;
overflow-y: scroll; /* <-- here is what is important*/
}
HTML
<div id="scrollable-area">
<table ng-table="tableParams" class="table">
</table>
</div>
Plunkr here

How do I make this div responsive in height?

How do I make this div responsive in height ?
<style>
.full1 {
margin-bottom: 10px;
margin-top: 10px;
width: 100%;
height: 225px;
}
.left1,
.middle1,
.right1 {
float: left;
width: 33%;
height:100%;
}
</style>
<body>
<div class="full1">
<div class="left1" >
<img class="left-image" src="http://s16.postimg.org/nc57l3p8l/1_screen_shot_2014_08_24_at_12_43_26_pm_medium.jpg" />
</div>
<div class="middle1">
<img class="left-image" src="http://s16.postimg.org/wl7dv7y4l/windows_9_logo_01_medium.jpg" />
</div>
<div class="right1">
<img class="right1-image" src="http://s16.postimg.org/ig6675eh1/windows_9_logo_08_medium.jpg" />
</div>
</div>
</body>
Here is the fiddle: http://jsfiddle.net/k07gg3pv/.
The images get resized by width but the height leaves large blank space when zoomed.
You have to set the width / height for the images:
.full1 img {
width: 100%;
height: 100%;
}
(here is your fiddle for that: http://jsfiddle.net/k07gg3pv/3/)
This will make the images fit exactly. But this isn't a good solution because your images won't have the proportions they should have. So you have to decide whether you want to fit exactly 100% in width or exactly the height, you won't get proper images and both.
So you have to set one value (width or height) for the images:
.full1 img {
width: 100%;
}
(here is your fiddle for that: http://jsfiddle.net/k07gg3pv/4/)

Make a Facebook Like Box responsive

When we want to insert a Facebook like box, we're given auto-generated code to insert into our website.
Unfortunately, the width of the like box is hard baked into the code:
<div class="fb-like-box" data-href="https://www.facebook.com/bibandtucker.net.au" data-width="450" data-colorscheme="light" data-show-faces="false" data-width="300" data-header="true" data-stream="true" data-show-border="false"></div>
How can I make the Facebook like box responsive, so that it will reduce in width to accommodate content areas less than the hard coded width value?
You can see the problem on this website. Watch what happens when you reduce the width of the view port.
You can make it fluid by doing this (googled for it):
.fb_iframe_widget,
.fb_iframe_widget span,
.fb_iframe_widget span iframe[style] {
width: 100% !important;
min-width: 200px;
}
You can make it responsive by finding where it starts messing up the layout:
#media (max-width:1100px) {
.fb_iframe_widget,
.fb_iframe_widget span,
.fb_iframe_widget span iframe[style] {
width: 100% !important;
min-width: 200px;
}
}
Since it's an iframe that you don't control, you can't style it further.
Demo: http://jsbin.com/mehil/1
This no longer works as of 2015 -- facebook has updated their code so that there is a minimum width of 180px.
to get around this you have to use JS.
in this case, .facebook-likebox is the wrapper (which is dynamically being scaled in relation to other elements), and .fb-page is the container for the iframe. the code is cross browser.
here is my code snippit:
facebookScale = function () {
var adjustWidth;
adjustWidth = $('.facebook-likebox').width() / 180;
return $('.fb-page').css({
'-webkit-transform': 'scale(' + adjustWidth + ')',
'-moz-transform': 'scale(' + adjustWidth + ')',
'transform': 'scale(' + adjustWidth + ')'
});
}
$(function(){
$(window).on('resize', facebookScale);
})
EDIT: also make sure the following is in your CSS:
.fb-page{
transform-origin: 0 0;
-webkit-transform-origin: 0px 0px;
-moz-transform-origin: 0px 0px;
}
Edit 2: facebook seems to have updated the widget to now have a min width of 180. so the code has been updated to reflect that. the widget should resize to fit the width of your container otherwise
<div class="fb-wrap">
<div class="fb-like-box" data-href="http://www.facebook.com/#"
data-width="100%" data-height="#"
data-show-faces="true" data-stream="false" data-header="false"></div>
</div>
.fb-wrap {
padding-top: 10px; width:90%; margin: 0 auto;}
.fb-like-box, .fb-like-box span, .fb-like-box span iframe[style]
{width: 100% !important; }
This works perfectly for me
this works for me with show faces true
.fb_iframe_widget,.fb_iframe_widget span,.fb_iframe_widget span iframe[style]
{max-width: 100% !important;}

Fluid, centered content block with sidebar

I'm pulling my hair here. Trying to come up with a simple responsive layout where two fluid boxes are aligned next to each other. The main box must always be centered in the browser window, while the other should be aligned beside it in its top right corner. See example image below -
Tried different approaches involving negative percentages and three-column faux layouts but it just doesn't work.
Demo: http://dabblet.com/gist/7201560
Markup:
<div class='container'>
<div class='main-col'></div>
<div class='right-col'></div>
</div>
CSS:
.container {
text-align: center;
}
.main-col, .right-col {
display: inline-block;
vertical-align: top;
text-align: left;
margin-right: -4px; /* css-tricks.com/fighting-the-space-between-inline-block-elements/‎ */
}
.main-col {
width: 50%;
margin-left: 20%; /* equal to .right-col's width */
}
.right-col {
width: 20%;
}
What's happening here:
The centered main column and right column have display: inline-block, and they're centered in the viewport by giving their container text-align: center. They're still not centered the way you want though. Since they're sibling elements you can use margin to push the main column to the left with a value equal to right-column's width, essentially centering itself.
Hi you can check my try in this link http://jsfiddle.net/WHq8U/17/.
I had to use a little jquery to calculate the sidebar absolute position. Let me know your opinion about this.

Responsive images and negative margin

I have a site where I have an element with padding. I want the images to be the full width of the container regardless of padding, so I have added a negative margin equal to the padding to make it stretch right to the edge. The problem arises when I use responsive images. They ignore the negative margin and squish down to the container size plus padding.
Example:
<article style="padding:20px">
<img style="margin:0 -20px;">
</article>
In a non-responsive world this works fine. How would I achieve this with responsive images. I realize I could close and re-open the article tag, but this will cause a bunch of other issue in my real code, so I'm hoping for an alternative.
Most likely the only way is to wrap images into a div, e.g.
<article>
<p>...</p>
<div class="img-wrapper">
<img src="..." />
</div>
<p>...</p>
</article>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
with css
article {
padding: 20px;
}
.img-wrapper {
margin: 0 -20px; /* minus left/right padding of article */
text-align: center; /* center small images */
line-height: 0; /* remove possible gap below image */
}
​​.img-wrapper > img {
max-width: 100%; /* max-width now is relative to .img-wrapper */
height: auto; /* to keep aspect ratio */
}​​

Resources