14.01.2015 Views

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

Eric lippert - Amazon Web Services

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

This as we can see is not pretty at all, so we go ahead and apply<br />

the following CSS styling<br />

But now let’s reduce the size of the browser and see how this looks<br />

.imageColumns {<br />

margin: 10px;<br />

}<br />

.mediaImage {<br />

max-width: 85%;<br />

max-height: 200px;<br />

}<br />

.mediaDiv {<br />

float: left;<br />

width: 16%;<br />

margin: 2px;<br />

height: 200px;<br />

border: 1px solid #7ba9ca;<br />

display: table-cell;<br />

vertical-align: middle;<br />

text-align: center;<br />

}<br />

h3 {<br />

font-family: ‘Segoe UI’;<br />

font-size: 0.8em;<br />

}<br />

As we can see, the images shrunk due to the width specified in<br />

% but the image divs are beginning to look odd with their fixed<br />

height.<br />

Finally if we look at the results in a Mobile browser (simulated), it<br />

looks totally wacky.<br />

This sets up four CSS classes.<br />

The ‘mediaDiv’ class arranges the image divs so that they float left<br />

instead of going one under the other. Once all horizontal spacing<br />

is occupied, it wraps the next div into the next line. They have been<br />

given a height of 200 pixels and a width of 16% which will roughly<br />

accommodate 6 images per line.<br />

The ‘mediaImage’ class sets the max-width of the image to 85% so<br />

that there is some spacing between two horizontal images, and a<br />

max-height is set to the same as the height specified in the<br />

‘mediaDiv’. This ensures that the aspect ratio for the images are<br />

maintained when we change the browser width. Let’s run this and<br />

see how it looks in various browser sizes. This time we ‘Get’ images<br />

for a Twitter handle called ‘FascinatingPics’. As we can see below,<br />

we have a nice collage of the 20 latest images posted by this<br />

account.<br />

So our one-size-fits all CSS style quickly breaks down as we view<br />

the page in different form-factors. We need to do something better.<br />

Getting Media Queries into Play<br />

As we can see from above, the Mobile view looks the most out of<br />

place. So let’s fix that first using a Media Query to declare a new<br />

set of styles. But before we do that, let’s do some house-cleaning<br />

first.<br />

DNcmagazine www.dotnetcurry.com | 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!