Exceptional CG Environments Digital Paintings
Guide To Freelance Web Design Business For College Students
Description: A web designer is now one of the most popular freelance jobs that lets you organize your schedule in the most convenient way. How to start web design business in college Many college students (if not all of them) work part-time to cover their expenses, pay off the loans, and pay for writing services […]
The post Guide To Freelance Web Design Business For College Students appeared first on designrfix.com.
16 Mind Blowing Warcraft Digital Illustrations
Every Bench Has a Story – Topic Based Photography
#272: Video
Show Description
Marie and Chris talk about video tutorials and demos for CodePen, and how CodePen is planning to improve videos across documentation and our YouTube channel.
Time Jumps
- 00:54 CodePen on video
- 04:03 Videos decay
- 09:22 Asset hosting on video
- 15:19 Sponsor: Jetpack
- 16:56 Hollywood Chris
- 28:30 Landing pages and GIFs
Sponsor: Jetpack
Jetpack adds an absolute ton of powerful functionality to your self-hosted WordPress site. If you have had the feeling that you’re paying for more than you need, you’re in luck, Jetpack is starting to have features you can buy individually. Jetpack Backup and Jetpack Search are new features you can buy individually if you like, and Jetpack Scan is the very latest, scanning your site constantly for any security issues and offering one-click fixes, just $7/month.
Show Links
- Cleanshot
- Droplr
- Kap
- Screenflow
- Shoptalk Show
- The Fancy DSLR Webcam Thing
- CSS Tricks / CSS Tricks on YouTube
- CodePen Pro landing page
- Notion
- Chris on CodePen / Chris on Twitter
- Marie on CodePen / Marie on Twitter
CodePen Links
The post #272: Video appeared first on CodePen Blog.
31 Stunning Futurisitc Scifi Illustrations
30 Creative Paper Artworks – When Paper Said 1000 Words
25 Cool Brushes for Photoshop
A Brief Guide to WordPress Web Design
WordPress is one of the world’s most popular and flexible platforms for creating websites and managing content, with hundreds of millions of users taking advantage of its tools. It is capable of accommodating sites of all sizes, from basic blogs to high traffic e-commerce sites and beyond, so here is a quick look at how […]
The post A Brief Guide to WordPress Web Design appeared first on designrfix.com.
Ask Me Anything – 10 June 2020
Cool Little CSS Grid Tricks for Your Blog
I discovered CSS about a decade ago while trying to modify the look of a blog I had created. Pretty soon, I was able to code cool things with more mathematical and, therefore, easier-to-understand features like transforms. However, other areas of CSS, such as layout, have remained a constant source of pain.
This post is about a problem I encountered about a decade ago and, until recently, did not know how to solve in a smart way. Specifically, it’s about how I found a solution to a long-running problem using a modern CSS grid technique that, in the process, gave me even cooler results than I originally imagined.
That this is not a tutorial on how to best use CSS grid, but more of a walk through my own learning process.
The problem
One of the first things I used to dump on that blog were random photos from the city, so I had this idea about having a grid of thumbnails with a fixed size. For a nicer look, I wanted this grid to be middle-aligned with respect to the paragraphs above and below it, but, at the same time, I wanted the thumbnails on the last row to be left-aligned with respect to the grid. Meanwhile, the width of the post (and the width of the grid within it) would depend on the viewport.
The HTML looks something like this:
<section class='post__content'>
<p><!-- some text --></p>
<div class='grid--thumbs'>
<a href='full-size-image.jpg'>
<img src='thumb-image.jpg' alt='image description'/>
</a>
<!-- more such thumbnails -->
</div>
<p><!-- some more text --></p>
</section>
It may seem simple, but it turned out to be one of the most difficult CSS problems I’ve ever encountered.
Less than ideal solutions
These are things I have tried or seen suggested over the years, but that never really got me anywhere.
Floating impossibility
Floats turned out to be a dead end because I couldn’t figure out how to make the grid be middle aligned this way.
.grid--thumbs { overflow: hidden; }
.grid--thumbs a { float: left; }
The demo below shows the float attempt. Resize the embed to see how they behave at different viewport widths.
inline-block
madness
At first, this seemed like a better idea:
.grid--thumbs { text-align: center }
.grid--thumbs a { display: inline-block }
Except it turned out it wasn’t:
The last row isn’t left aligned in this case.
At a certain point, thanks to an accidental CSS auto-complete on CodePen, I found out about a property called text-align-last
, which determines how the last line of a block is aligned.
Unfortunately, setting text-align-last: left
on the grid wasn’t the solution I was looking for either:
At this point, I actually considered dropping the idea of a middle aligned grid. Could a combo of text-align: justified
and text-align-last: left
on the grid produce a better result?
Well, turns out it doesn’t. That is, unless there’s only a thumbnail on the last row and the gaps between the columns aren’t too big. Resize the embed below to see what I mean.
This is pretty where I was at two years ago, after nine years of trying and failing to come up with a solution to this problem.
Messy flexbox hacks
A flexbox solution that seemed like it would work at first was to add an ::after
pseudo-element on the grid and set flex: 1
on both the thumbnails and this pseudo-element:
.grid--thumbs {
display: flex;
flex-wrap: wrap;
a, &::after { flex: 1; }
img { margin: auto; }
&:after { content: 'AFTER'; }
}
The demo below shows how this method works. I’ve given the thumbnails and the ::after
pseudo-element purple outlines to make it easier to see what is going on.
This is not quite what I wanted because the grid of thumbnails is not middle-aligned. Thats said, it doesn’t look too bad… as long as the last row has exactly one item less image than the others. As soon as that changes, however, the layout breaks if it’s missing more items or none.
That was one hacky idea. Another is to use a pseudo-element again, but add as many empty divs after the thumbnails as there are columns that we’re expecting to have. That number is something we should be able to approximate since the size of the thumbnails is fixed. We probably want to set a maximum width for the post since text that stretches across the width of a full screen can visually exhausting for eyes to read.
The first empty elements will take up the full width of the row that’s not completely filled with thumbnails, while the rest will spill into other rows. But since their height
is zero, it won’t matter visually.
This kind of does the trick but, again, it’s hacky and still doesn’t produce the exact result I want since it sometimes ends up with big and kind of ugly-looking gaps between the columns.
A grid solution?
The grid layout has always sounded like the answer, given its name. The problem was that all examples I had seen by then were using a predefined number of columns and that doesn’t work for this particular pattern where the number of columns is determined by the viewport width.
Last year, while coding a collection of one element, pure CSS background patterns, I had the idea of generating a bunch of media queries that would modify a CSS variable, --n
, corresponding to the number of columns used to set grid-template-columns
.
$w: 13em;
$h: 19em;
$f: $h/$w;
$n: 7;
$g: 1em;
--h: #{$f*$w};
display: grid;
grid-template-columns: repeat(var(--n, #{$n}), var(--w, #{$w}));
grid-gap: $g;
place-content: center;
@for $i from 1 to $n {
@media (max-width: ($n - $i + 1)*$w + ($n - $i + 2)*$g) {
--n: #{$n - $i}
}
}
I was actually super proud of this idea at the time, even though I cringe looking back on it now. One media query for every number of columns possible is not exactly ideal, not to mention it doesn’t work so well when the grid width doesn’t equal the viewport width, but is still somewhat flexible and also depends on the width of its siblings.
A magic solution
I finally came across a better solution while working with CSS grid and failing to understand why the repeat()
function wasn’t working in a particular situation. It was so frustrating and prompted me to go to MDN, where I happened to notice the auto-fit
keyword and, while I didn’t understand the explanation, I had a hunch that it could help with this other problem, so I dropped everything else I was doing and gave it a try.
Here’s what I got:
.grid--thumbs {
display: grid;
justify-content: center;
grid-gap: .25em;
grid-template-columns: repeat(auto-fit, 8em);
}
I also discovered the minmax()
function, which can be used in place of fixed sizes on grid items. I still haven’t been able to understand exactly how minmax()
works — and the more I play with it, the less I understand it — but what it looks like it does in this situation is create the grid then stretch its columns equally until they fill all of the available space:
grid-template-columns: repeat(auto-fit, minmax(8em, 1fr));
Another cool thing we can do here is prevent the image from overflowing when it’s wider than the grid element. We can do this by replacing the minimum 8em
with min(8em, 100%)
That essentially ensures that images will never exceed 100%, but never below 8em. Thanks to Chris for this suggestion!
Note that the min()
function doesn’t work in pre-Chromium Edge!
Keep in mind that this only produces a nice result if all of the images have the same Aspect ratio — like the square images I’ve used here. For my blog, this was not an issue since all photos were taken with my Sony Ericsson W800i phone, and they all had the same Aspect ratio. But if we were to drop images with different Aspect ratios, the grid wouldn’t look as good anymore:
We can, of course, set the image height
to a fixed value, but that distorts the images… unless we set object-fit
to cover
, which solves our problem!
Another idea would be to turn the first thumbnail into a sort of banner that spans all grid columns. The one problem is that we don’t know the number of columns because that depends on the viewport. But, there is a solution — we can set grid-column-end
to -1
!
.grid--thumbs {
/* same styles as before */
a:first-child {
grid-column: 1/ -1;
img { height: 13em }
}
}
The first image gets a bigger height
than all the others.
Of course, if we wanted the image to span all columns except the last, one we’d set it to -2
and so on… negative column indices are a thing!
auto-fill
is another grid property keyword I noticed on MDN. The explanations for both are long walls of text without visuals, so I didn’t find them particularly useful. Even worse, replacing auto-fit
with auto-fill
in any of the grid demos above produces absolutely no difference. How they really work and how they differ still remains a mystery, even after checking out articles or toying with examples.
However, trying out different things and seeing what happens in various scenarios at one point led me to the conclusion that, if we’re using a minmax()
column width and not a fixed one (like 8em
), then it’s probably better to use auto-fill
instead of auto-fit
because, the result looks better if we happen to only have a few images, as illustrated by the interactive demo below:
I think what I personally like best is the initial idea of a thumbnail grid that’s middle-aligned and has a mostly fixed column width (but still uses min(100%, 15em)
instead of just 15em
though). At the end of the day, it’s a matter of personal preference and what can be seen in the demo below just happens to look better to me:
I’m using auto-fit
in this demo because it produces the same result as auto-fill
and is one character shorter. However, what I didn’t understand when making this is that both keywords produce the same result because there are more items in the gallery than we need to fill a row.
But once that changes, auto-fit
and auto-fill
produce different results, as illustrated below. You can change the justify-content
value and the number of items placed on the grid:
I’m not really sure which is the better choice. I guess this also depends on personal preference. Coupled with justify-content: center
, auto-fill
seems to be the more logical option, but, at the same time, auto-fit
produces a better-looking result.
The post Cool Little CSS Grid Tricks for Your Blog appeared first on CSS-Tricks.
Slider Revolution WordPress Plugin Review & How To Guide
Slider Revolution is a premium slider available as a WordPress plugin and Magento extension. It’s gained huge popularity in the WordPress community due to it’s wide range of features and ease of use. In this overview we’re going to cover the main features of the Slider Revolution WordPress Plugin, and then we’ll show you just […]
The post Slider Revolution WordPress Plugin Review & How To Guide appeared first on WPExplorer.
Online Writing Jobs: 30 Legit Websites Offering Part Time Writing Jobs
100 Realistic Pokemons Brought to Life through Art
Image SEO Optimizer: Optimize Images for Search Engines
Images play a lot of vital roles in WordPress websites. For starters, they help you to split long blocks of text, which improves readability, hence user experience. Second, beautiful images add color and life to dull posts making your content more intriguing. And, they add meaning to your textual content, but only if you use […]
The post Image SEO Optimizer: Optimize Images for Search Engines appeared first on WPExplorer.
Hasura Introduces New GraphQL Data Federation Feature: Remote Joins
Hasura, a GraphQL data and services company, has introduced a new data federation feature: Remote Joins. Remote Joins allows developers to treat data across sources as a single database. The existing data sources do not need to be modified in order to utilize Remote Joins. With a point and click, a relationship across the sources is created and unified access is created through the GraphQL API.