How to create a responsive grid (movie website) - html

I have been attempting to create a grid of movies, exactly like http://www0.yesmovies.net/
this is my first project using responsive design (rather than a simple minmax usage) and it is stopping me from moving forward.
if someone could take some time out to help me achieve this and tell me the correct way to go about it, it would be highly appreciated believe me.
i have tried using css grid (im pretty sure its the way i need to go) but i cannot get my head round the responsive side.
Thankyou.

I think you can play around with the viewport of the website by resizing your browser's width/height and identify what about the movie grid feels responsive. I gave you a starting point of some of things I noticed:
The movie cards grow smaller as I resize my viewport from larger to smaller.
At a certain set of dimensions, the movie cards go from being 8 smaller cards per row to 6 slightly larger cards.
As I keep shrinking, the site continues to resize the movie cards and change the number of cards per row.
You can achieve this level of responsiveness by using:
either Flexbox or CSS Grid and using their properties
media queries, which looks like #media only screen and...
using percentages or other scalable units for your width and height dimensions on your movie cards
using min-width and min-height to prevent your movie cards from getting too small
alternatively, you can also use max-width and max-height to do the opposite
I have included a snippet that demonstrates a rough implementation of how Flexbox might be used to achieve responsiveness for your site.
const createMovieCard = color => {
const div = document.createElement('div')
div.classList.add('movie__card')
div.style.background = color
div.innerHTML = 'Example movie'
return div
}
const container = document.querySelector('.container')
const colors = ['red', 'blue', 'yellow', 'green', 'orange']
for (let i = 0; i < 50; ++i) {
const color = colors[i % colors.length]
container.appendChild(createMovieCard(color))
}
.container {
width: 100%;
text-align: center;
/* By setting this div's display to flex,
I get access to Flexbox's properties.
I can now use these properties to manipulate
the children of this div. */
display: flex;
/* This is will center this div's children to the left. */
justify-content: left;
/* flex-wrap acts much like a code editor's soft wrapping feature. */
flex-wrap: wrap;
}
.movie__card {
margin: 1em;
background: lightgrey;
/* Children whose parent has `display: flex` also gain access to Flexbox
properties. */
flex: 0;
/* By setting width as a percentage and having a min-width property, you
enable your movie cards to have a larger width when the viewport is
larger and prevent them from getting too small when the viewport
is smaller, such as on a mobile viewport. */
width: 15%;
min-width: 100px;
height: 150px;
}
<div class="container"><!-- The movie cards are generated here using JS. --></div>

Related

How do I make a div width depending on the viewport space that is left

Please have a look at the Wireframe I created to see what I am trying to achieve.
I have created 2 screens so you can see the desired behavior depending on different screen sizes.
Wireframe Link
I basically want to have a center-aligned container "Main-Section" with a max-width (depending on screen size) and a 12col grid inside. To the left and right of the container should then be two divs "Left/Right Lane", which share the remaining space/width on each side.
My main question:
How do I set up the left/right lanes so that they occupy the rest of the screen-width evenly?
Thank you for your help!
your question does not includes code.
If you have a low level of technical capabilities, I would suggest you to use the Bootstrap Grid System.
https://getbootstrap.com/docs/5.0/layout/grid/
If you are a beginner it is a good practice to read docs and understand it.
Seems like I found the answer myself. The important piece of information I was missing was:
flex-grow
.main {
display: flex;
}
.left-col, .right-col {
flex-grow: 1;
}
.center-col {
width: 500px;
}
https://jsfiddle.net/Hangtime/L86wkce7/1/

ionic 3 auto adjust layout on the grid

I have built a dashboard using ion-grid and just one ion-row. the ion-row contains 10-12 ion-col. So basically, as soon as the screen width is hit the columns starts to flow down.
This all is good and as expected. However, the problem starts when these columns are of varying width and heights. I have defined the col of 3 width types: 200px, 400px and 600px. The height is also of 3 variations 200px, 400px and 600px. So overall each col can be either a 1*1, 2*1, 1*2, 2*2, 3*1 and 3*2 size.
I am using dragula to be able to drag and drop the titles to adjust the layout as desired. However, initial layout always renders with some holes though they can be filled by manual drag drop.
So, what should be the right way to handle it at the initial time to avoid the holes in the layout.
You probably could use css flex grow. Use one parent div for each row and set css as
.row {
display: flex;
justify-content: center;
align-items: center
}
for each column use flex grow to define their sizes.
eg. flex-grow: 1 - for normal, flex-grow: 2 for bigger width.
here I have attached what I have did. In my case, the column numbers should be dynamic, but having the same with.

Full width list in CSS

I'm trying to implement and new layout for my site. I am capable of implementing this using JS but I'm trying to use pure CSS.
And example would be http://tympanus.net/Development/GridLoadingEffects/
It starts out with 3 columns and when you resize the page smaller, the boxes resize until it gets small enough that it turns into two columns.
Similar to that I'm trying to get my horizontal list of square images to take full width of the page with the square's max-width being 300px. So for example: the page starts out with 5 columns, the width of the page starts shrinking, the width of the boxes start shrinking as well. It reaches a point where 4 300px boxes will be able to fit into the current width.
I've screwed around with and max-width and min-width, but I'm a CSS novice and I feel like I'm missing something. I've looked around and
Any ideas?
You can use Media Queries to set differnet css rules for different browser widths.
#media (min-width: 300px) and (max-width: 600px) {
someClass {
/* some rules for browser width between 300 and 600px */
}
}
More about Media Queries:
ss-tricks.com
MDN
selfhtml
Try setting the width as percents so it will be relative to the screen width.
Then use the screen width media query to set a different width for different screen sizes.
Good luck.
What you're basically talking about is a responsive grid layout system. IMHO the simplest way to do this in pure CSS if you float your DIVs and used fixed % sizes. Use Media break-points for each screen size range you want to support. You need to calculate all the gaps (gutter widths) as well. Also watch for rounding errors in some browsers, notably IE. You might need to use slightly less than 100% for maths because you want to ensure you don't end up 1px larger than 100%.
Here's an example with just one break-point that uses a 3 column layout by default and revers to a 2 column layout when the display size falls below 480px.
<style>
/* default */
.square {
background-color: orange;
width: 30%; /* 100/3 - (margin*2) */
padding-bottom: 30%; /* matching width makes it square */
margin: 1.5%; /* margin calculated as portion of overall 100% */
}
#media (max-width: 480px) {
.square{
/* overrides for smaller screens */
background-color: purple; /* show the breakpoint switch below 480px */
width: 47%; /* (100%/2) - (margin*2) */
padding-bottom: 47%;
margin:
}
}
</style>
<div>This layout will fit 3 squares wide for any screen width</div>
<div class="square">one</div>
<div class="square">two</div>
<div class="square">three</div>
And here's the fiddle.
Your media queries can get much more complex, but it's possible to support pretty much any device. Try and design for any screen size first and than mop up the edge cases.
This soon gets very complex to manage in CSS. You really want to think about a CSS pre-processor such as SASS or LESS. However, there are plenty of grid frameworks that support this, including Twitter's bootstrap and some great inspiration from fluid squares or my favourite for simplicity responsive.gs. You'll find that most of these use a grid of 12 or 24 columns, as they divide into more even sets of columns. For instance, 24 can shrink down to a screen consisting of 1, 2, 3, 4, 6, 8, 12 and 24 columns.

Manipulating grid column layouts with media queries and breakpoints

I'm trying to get familiar with responsive, mobile-friendly layouts by redesigning my online portfolio, using the SimpleGrid framework (this one: thisisdallas.github.io/Simple-Grid/‎) combined with elements of HTML5 boilerplate to help get me started.
Here's what I've got at the moment: http://pftest.comyr.com/grid/
One of the issues I encountered was figuring out how to get the grid columns (specifically, the 3 div columns containing the hexagon shapes) to collapse at the different screen-size "breakpoints" with CSS media queries so that they won't simply overlap each other at smaller screen sizes.
After a fair amount of trial and error mucking about I eventually discovered I could get it to to collapse to two columns for tablet screen-sized devices by applying a class/ID with width: 50% and float: left to a media query of: #media only screen and (max-width: 908px) { } and (hopefully) now it collapses neatly into two columns at roughly that size (at least it does from my brief testing)
The issue I'm having is now is figuring out how to get it get into collapse into a single column for the smaller smartphone screen-sizes (#media (max-width: 22em), #media (max-width: 320px) ect.
I have tried various different properties using the same #workgrid ID I used for the two column breakpoint - but for whatever reason just can't seem to get it work, and unfortunately there is little to no documentation included with the grid framework that might aid me.
The CSS in question is:
#media (max-width: 22em) {
#workgrid {
width: 100%;
float: left;
margin-left: 0px;
margin-right: 0px;
margin-top: 10px;
margin-bottom: 10px;
padding-left: 5px;
padding-right: 5px;
}
}
Which is applied to each of the DIV "col-1-3" classes.
As you can see at the moment it collapses into the two columns and then begins to overlap at any screen size smaller than that. I'm sure it is something relatively simple I'm missing/not seeing and just need a bit of a push in the right direction... :)
The main problem is that you're working with unresponsive units inside the responsive elements of your grid and you're not using max-height and max-width for elements like images.
For example, you have an element class called .shape whose width is 300px, this class is a child of #workgrid whose width is 50%. In a small browser viewport with, for example, a 320px width, your #workgrid width in pixel will be as much 160px while .shape width will be the same, 300px, this causes the content gets out of the space and collapses with other elements space.
Here are two links that maybe help you to understand fluid elements better:
Fluid images
max-width
To fix your grid you should use max-width and max-height instead of width and height in some classes and change some css properties like background-size. Another way to solve it is using responsive units instead of fixed units in sizes. A responsive web needs responsive measures.
Fix that takes time and can be exasperating, so if you want an alternative solution yo can solve your problem changing yor main.css and simplegrid.css this:
#media (max-width: 22em) {
to this:
#media (max-width: 41em) { // If it doesn't work, test a larger number like 44em or something like that
Your grid starts to collapse when the browser viewport is smaller than 656px (656px = 41em for a current font-size of 16px), this grid becomes a single column grid when the browser's viewport width is 22em or less, so changing 22em to 41em we make single column appears before the grid collapses, thus making grid works well.

CSS table, varying dimensions

I'm working on a responsive layout that displays some <div> boxes as part of a rectangular grid:
http://sl.cosd.com
The six boxes you can see on this page are all ungrouped in the HTML source, all in a row:
<div class="control">
<div class="controlContent">
<a>SOME VARIABLE-HEIGHT CONTENT including an image which might float</a>
</div>
</div>
The control divs assign the boxes percentage widths to first the whole, then 1/2 or 1/3 the screen width, so they double & triple up into rows as the screen size is increased. The controlContent divs assign properties like padding, margin, background, border-radius, etc.
I have imagined this as a linear set of boxes, standards-compliant and screenreader-friendly, to be displayed via CSS like a table. I know CSS2.1 allows elements to be assigned properties like:
display: table;
display: table-row;
display: table-cell;
My main problem: I have assigned display: table-cell to these elements (via the controlContent div) which prevents margin collapse inside the content but does not provide a uniform height to the cell-like divs. I need a way for all siblings on the same row to have matching height.
The smaller cells generally have gaps below them where the gradient background only covers the box height of the cell. (Worse, the text after this array of cells sometimes fills into these gaps: another problem that could be fixed with presentation markup, though one which will probably go away when the first problem is fixed.)
I think I understand the basics of the problem: each <div> which I have told to behave like a table cell has nothing to match its height to, since I have no way of grouping elements into a containing <div> to which I can assign the display: table-row property, since this grouping changes according to CSS media queries.
In my reading about the problem I've heard of anonymous table boxes and anonymous table rows being created but don't know how to use them in this case. Since I'm using the CSS :nth-child() selectors to clear the floating boxes at the beginning of each new row, I'd hoped I could also use these selectors to establish a new table row at every such point... but how?
I'm not married to any particular solution. I'd just like to know the best-practice way of doing this. I'm hoping to find a solution that doesn't involve presentation markup, especially since a general solution should provide a responsive variable-dimension table for any number of cells, not just a small, easily factorable number like 6.
display:table-cell; should give the div/columns the same height, as long as the parent div has display:table; set.
Check this fiddle (you can add/remove as many cols as you want).
Another solution is to give .control a fixed height, then you can use height:100%; on controlContent.
If you need to use percentages only, then you've to declare an height on all the parent containers of .controlContent, up to html and body:
html, body, .control, .controlContent {
height:100%;
}
Obviously it's just a simplification. This is the most reliable method, because table-cell is not rendered properly by some older browsers.
On the other hand, you always have to know the height (in pixels or percentage) of all containers.
Then, there's the faux column method, but i don't thinks it suits your case.
Lastly, there's the JavaScript / jQuery method, which in your case would be something like
$(document).ready(function(){
var higherContent = 0;
$('.controlContent').each(function() {
var currentHeight = $(this).height();
if( currentHeight > higherContent ) higherContent = currentHeight;
}).height(higherContent);
});
Which basically (when the page loads) passes through all the controlContent and sets the value of the highest one in the variable higherContent. Then this value is assigned to all controlContent.
Probably not the best jQuery function ever written anyway :-) and you'ld have to adapt it for every resolution targeted by your media-queries.
If i were you, i would probably go for the table-cell method, so that you can set different widths for different resolution, and the layout will adapt in most of modern desktop/mobile browsers. But be sure to test it on as many devices as possible!
EDIT: I see you're using min-width media queries. You can change your code this way:
div.controlContent {
/* other stuff */
display: block;
/* other stuff */
}
#media only screen and (min-width: 480px) {
/* other stuff */
div.controlContent {
display: table-cell;
}
/* other stuff */
}