This question already has answers here:
CSS-only masonry layout
(4 answers)
Closed 4 days ago.
So im trying to use css grid to make a gallery for pictures liek pinterest. So diffrent height pictures to be next to each other and each picutre to take over the empty space. But all the examples i see are with adding diffrent classes on each picture depending on their height they want and i want to add pictures dynamically from a data base.
I tried like this:
My gallery component:
<div className=‘gallery’>
<img className=‘image’> </img>
<img className=‘image’> </img>
<img className=‘image’> </img>
<img className=‘image’> </img>
</div>
And my css file:
.gallery{
max-width: 80vh;
display: grid;
grid-template-columns:repeat(3,1fr);
}
.image{
max-width: 200px;
height: 100%;
object-fit: cover;
}
But like this the small picutres are in the same row and the bigger picutres in another when i need it to be randomised.
Is there any way to do it without adding different classes om each picture?
Pinterst uses a vertical alignment. So if you want to replicate it you should create vertical boxes next to each other with fixed width.
And show as many rows as the screen lets you. (If you resize the pinterest windiow width, the whole page gets regenerated, but that is outside the sope of your question I guess)
So I recomment using divs or even a table with one row and a long column.
<table>
<tr>
<td>images</td>
<td>images</td>
<td>images</td>
</tr>
</table>
of course dynamically. (I created a 3 long row for a smaller screen)
And from here you add the images to each column, setting the tr width to like 200px and the image width to 100%.
Ok i found the answer here in case someone else needs it:
https://css-tricks.com/seamless-responsive-photo-grid/
Related
Trying to help a friend of mine with a Squarespace website and attempting to add an image in the header code.
I've tried aligning centrally but it doesn't seem to work. Only padding and margin pixels have any effect but then it's not consistent when using different sized monitors.
Any help is greatly appreciated!
Current code below:
<a href="https://wwwmisscurrentcom.squarespace.com/about-1/"><img class=
"thumb-image loaded" data-image-dimensions="960x41" data-image-resolution=
"1500w" data-src=
"https://static.squarespace.com/static/53ce81e3e4b065e3be155770/53cfbd0ce4b056db8c5d3b42/53e4fdb9e4b036cda0551713/1407516127095/header-shipping.png?format=1000w"
id="yui_3_17_2_1_1407515470914_1223" src=
"https://static.squarespace.com/static/53ce81e3e4b065e3be155770/53cfbd0ce4b056db8c5d3b42/53e4fdb9e4b036cda0551713/1407516127095/header-shipping.png?format=1000w"
style="top: 114px; position: relative;margin-left: 150px;"></a>
After re-reading your question a few times, I think I know what you are asking. You can centre your image with margin: 0 auto;. The auto left and right margin will keep the block element (in this case, a div) dead centre horizontally across all resolutions and screen sizes.
Have a jsBin example!
HTML
<div class="header">
<img src="http://www.placehold.it/200x100" alt="logo" />
</div>
CSS
.header {
width: 200px;
margin: 0 auto;
/*
shorthand margin =
top (0)
right (auto)
bottom (0 - inherited from top)
left (auto - inherited from right);
*/
}
If you want it properly centered you will have to access the custom css and use media queries. The problem with standard pixels and percentages in SquareSpace is that you may get it centered on your monitor but it will not always center on other hardware/devices.
I have this design layout that has a gradient background in the content container.
the gradient is a solid color on the left and right and gradient to white near the center. (horizontal gradient)
I have three images left-solid.png and a right-solid.png for extending the left and right of the content area if the viewing area is larger. I have main-gradient.png as the background for the main content and is a fixed size of 900px
Is there a way to lay this out without using a html table?
It looks like I need three columns of some sort
[leftcolumn][contentcolumn][rightcolumn]
rightcontent= can stretch and filled with right-solid.png repeat-x
content = 900px filled with main-gradient.png as background no repeat
leftcontent = canstrech and filled with left-solid.png repeat-y
any suggestions?
There are a number of ways you can achieve a multi-column layout without using tables. In fact, using tables is semantically incorrect. This very thing is one of the reasons CSS was created.
Using the following HTML structure:
<div class="container">
<div class="left">
</div>
<div class="middle">
</div>
<div class="right">
</div>
</div>
Then you could do this in CSS:
.left, .middle, .right {
display: inline-block;
}
This will tell the div's to appear next to each other. Additional CSS styles will be needed as well, like width properties for each column (preferable to use percents).
Another option for CSS would be:
.left, .middle, .right {
float: left;
}
This will also tell the div's to appear next to each other, but it does it a very different way.
A further note is that you don't need to use images for your gradient. You can do gradients using CSS. Take a look at http://www.colorzilla.com
I've been working with a html page that has a form in the bottom of the page. That form is inside a table and table is inside a div. Fiddle here : http://jsfiddle.net/2ZTvQ/
Problem is on smaller screen the div is taking 100% width(full width of the screen) but not width of the whole table containing the form. I'm not an expert with html/css so I'm not even sure if it can be done this way.
Sample HTML:
<div class='wide'>
<table width="100%">
<tr>
<td>
looooooooooooooo ooooooooooo00000 ooooooong text goes here
</td>
</tr>
</table>
</div>
CSS:
.wide {
text-align:center;
background:#e7e7e4;
width: 100%;
padding-top:20px;
}
Remove text-align:center; or create a new aligning style for the table.
What I think you will have to do is add a min-width to .wide of however small the table will get after manually trying to reduce it's width. So once it is as small as you can get it (use media queries to change classes under a certain window width) set
.wide { min-width: thatSize; }
What will happen now is instead of the content disappearing or running out of the div, you will now just have to scroll horizontally to see it all.
Or what you can do is add
.wide { overflow: scroll; }
What that will do is keep the viewport the same size, but make the content inside .wide scrollable like an iframe. Probably better looking than the first solution. Whatever you decide is a design choice on your part. But most important thing would be using media queries and trying to get the form as thin as possible. Display block and percentage widths are your friends there.
Looking for some expert advice here about how best to style the following HTML:
<body>
-Some content-
<div class="parent" style="height:50%;">
<div class="child" style="background-color:#FF9999;">An image</div>
<div class="child" style="background-color:#9999FF;">Some text</div>
</div>
</body>
To obtain a result that behaves like this:
The criteria that I am working with are the following:
The container div, .parent, is a block element and fills the entire width of the browser window.
I know the width of the first/left inner div, in pixels but not as a percentage, based on the regularity of the images that will go there.
I don't know the width of the second/right inner div - as it contains a variable amount of text that should automatically fill the entire space to the right, regardless of browser window width
The height of the first/left div, when shorter than the second/right div, should stretch to the same height (here's the reason: the first/left div will have a right-border to set it off from the second/right div, and this border should be the height of the .parent div; however, the first/left div is not always present in the mark-up, in which case the border should not appear).
I cannot use JavaScript trickery.
Solutions I have tried based on my experience and help from web sources:
Float:
The traditional method that uses float:left leaves me apparently unable to stretch the first/left div to the (variable) height of either its sibling or .parent.
Inline-block:
.parent {background-color:#999999;}
.parent > .child {display:inline-block;vertical-align:top;height:100%;}
Using display:inline-block appears to work like a charm when the text in the second/right div is not enough to fill an entire line. The moment there is more text, however, the second/right div grows as wide as the outer container will let it, forcing it to wrap under the first/right div.
Any insights would be much appreciated!
Using table based markup is not the answer. However, iff you don't need to support IE7 or lower, you can use display:table to solve this. Check out this demonstration i threw together. Edit the amount of content in the second child div to see the effect.
jsfiddle demonstrating display:table
.parent {
display:table;
}
.child {
display:table-cell;
}
Basically, you tell the parent element to act like a table, the two child elements to act like table cells. This gives you the benefits of the table layout without the accessibility problems and extra markup of html tables. As I mentioned though, this doesn't work in IE7. If you need old IE support, you'll have to resort to less graceful workarounds :(
While tables have gotten a bad reputation, this would be a good application for one.
<body>
-Some content-
<table class="parent" style="height:50%;">
<tr>
<td class="child" style="background-color:#FF9999;" width="10">An image</td>
<td class="child" style="background-color:#9999FF;">Some text</td>
</tr>
</table>
</body>
If you set the width to a minimum, it will push your content over even if it's larger, and no matter which column is taller, it will push the overall content box down.
I am creating an HTML5 web page with a one column layout. Basically, it is a forum thread with individual posts.
I have specified in my CSS file the column to be 600px wide and centered it in the window using margin: 0 auto;. However, some images that are in the individual posts are larger than 600px and spill out of the column.
I'd like to widen an individual post to fit the larger images. However, I want all the other posts to still be 600px wide.
Right now, I'm just using overflow:auto which will create a scroll bar, but this is less than ideal. Is this possible to have the an individual post width grow for larger content yet stay fixed for normal content? Is this possible using just pure CSS?
Thanks in advance!
try using min-width: 600px instead of width, though it won't work in old versions of internet explorer.
You can use display:table on divs that contain your posts. You can see the effect with this example markup:
<html>
<head>
<style>
.post{
margin:0 auto;
border:1px solid red;
display:table;
}
</style>
</head>
<body style="width:100%;border:1px solid blue;">
<div class="post" style="width:600px;">
asd
</div>
<div class="post" style="width:900px;">
asd
</div>
</body>
</html>
Of course this will not work IE under version 8.