Create Responsive Image Effects With CSS Gradients And Aspect Ratio

Create Responsive Image Effects With CSS Gradients And Aspect Ratio


A classic problem in CSS is maintaining the aspect ratio of images across related components, such as cards. The newly supported aspect-ratio property in combination with object-fit provides a remedy to this headache of the past! Let’s learn to use these properties, in addition to creating a responsive gradient image effect for extra flair.




To prepare for our future image effects, we’re going to set up a card component that has a large image at the top followed by a headline and description.




The common problem with this setup is that we may not always have perfect control over what the image is, and more importantly to our layout, what its dimensions are.




And while this can be resolved by cropping ahead of time, we can still encounter issues due to responsively sized containers. A consequence is uneven positions of the card content which really stands out when you present a row of cards.




Another previous solution besides cropping may have been to swap from an inline img to a blank div that only existed to present the image via background-image.




I’ve implemented this solution many times myself in the past. One advantage this has is using an older trick for aspect ratio which uses a zero-height element and sets a padding-bottom value. Setting a padding value as a percent results in a final computed value that is relative to the element’s width.




You may have also used this idea to maintain a 16:9 ratio for video embeds, in which case the padding value is found with the formula: 9/16 = 0.5625 * 100% = 56.26%.




But we’re going to explore two modern CSS properties that don’t involve extra math, give us more flexibility, and also allow keeping the semantics provided by using a real img instead of an empty div.




First, let’s define the HTML semantics, including use of an unordered list as the cards’ container:





<ul class="card-wrapper">
<li class="card">
<img src="" alt="">
<h3>A Super Wonderful Headline</h3>
<p>Lorem ipsum sit dolor amit</p>
</li>
<!-- additional cards -->
</ul>
(code-box)


Next, we’ll create a minimal set of baseline styles for the .card component. We’ll set some basic visual styles for the card itself, a quick update to the expected h3 headline, then essential styles to begin to style the card image.




.card {
background-color: #fff;
border-radius: 0.5rem;
box-shadow: 0.05rem 0.1rem 0.3rem -0.03rem rgba(0, 0, 0, 0.45);
padding-bottom: 1rem;
}

.card > :last-child {
margin-bottom: 0;
}

.card h3 {
margin-top: 1rem;
font-size: 1.25rem;
}

img {
border-radius: 0.5rem 0.5rem 0 0;
width: 100%;
}

img ~ * {
margin-left: 1rem;
margin-right: 1rem;
}
(code-box)



The last rule uses the general sibling combinator to add a horizontal margin to any element that follows the img since we want the image itself to be flush with the sides of the card.




And our progress so far leads us to the following card appearance:




Create Responsive Image Effects With CSS Gradients And Aspect Ratio



One card with the baseline styles previously described applied and including an image from Unsplash of a dessert on a small plate next to a hot beverage in a mug. (Large preview)




Finally, we’ll create the .card-wrapper styles for a quick responsive layout using CSS grid. This will also remove the default list styles.




.card-wrapper {
list-style: none;
padding: 0;
margin: 0;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(30ch, 1fr));
grid-gap: 1.5rem;
}
(code-box)


Note: If this grid technique is unfamiliar to you, review the explanation in my tutorial about modern solutions for the 12-column grid.




Freebify Premium Blogger Template



Freebify Premium Blogger Template


(getButton) #text=(Demo Template) #icon=(demo) #color=(#169c87) (getButton) #text=(Buy Now) #icon=(buy) #color=(#bd2323)



Freebify is a fast, professional, modern & fully customizable responsive blogger template. It is perfect for tutorial blogs, distribution of mockups, vectors, logos, fonts, free blogger templates, wordpress themes and other diverse niches.



Freebify Premium Blogger Template is also ideal if you want to monetize your website via banners, as it is one of the blogger themes with the largest number of sections for banners.



The easily understandable design of the theme along with its readability makes it stand among the best templates. This theme looks like an App and the design of this theme makes it different from blogger themes. Developers have focused on UI/UX designs.(alert-success)


Freebify Blogger Template It is highly responsive, SEO optimized, and provides much ease in AdSense approval. This version contains many novel and updated features included in it.



While this theme is perfect for creating an anime or cartoon portfolio website for an artist or an illustrator, it can also be used to share your anime art, drawings, and even create a blog to write about your favorite anime or cartoon shows.



The main Google Core Web Vitals problem has been resolved in this template with the best optimization. To see the results of our optimization work in this adaptable modern blogger template, use the Google Page Speed Test tool by Lighthouse below.



Additionally, you can check this template's super optimization using the GTmetrix and Pingdom tools. Performing this will help you get better results and top rankings in search engines.



Freebify Template Features




Freebify is one of the most SEO-friendly and well-optimized blogger templates on the market. It's meant to provide bloggers all of the benefits of a magazine theme. Freebify is a one-of-a-kind website built in accordance with current web standards.



  1. Mobile Friendly

  2. Responsive Yes

  3. SEO Friendly Yes

  4. AdSense Friendly Yes

  5. Dark Mode Yes

  6. Version 1.3.0

  7. Size 194 KB





Freebify Premium Blogger Template



Fast & Responsive



One of the templates with the fastest loading speeds is Pixy Newspaper 11. It's also responsive and mobile-friendly. Every gadget works nicely with Freebify Premium Blogger Template.



Because search engines like Google prioritise mobile crawling, having a mobile-friendly website is essential. Freebify meets all of these requirements while also providing the best design and performance, making it the ideal choice for magazine download bloggers.




SEO Optimized



Freebify has been meticulously optimised for search engines. In Freebify, you'll find all of the Meta tags and other SEO best practises.



It was designed with search engine optimization in mind. Apart from that, SEO is the most crucial feature of any website because it aids clients in finding it.



Any website with no visitors is nothing more than HTML with no value. As a consequence, Pixy Newspaper 11 has been completely redesigned in order to offer the most number of search results possible.



Freebify Premium is Most Loved Template by our users Their are so many gadgets and amazing features like compare then any other platform. We provide osm featured posts section with fast and responsive design that assurely ehance your website look and performance over search engines




Download Template



Customer satisfaction is our major aim, and we work hard to achieve it. We are always willing to help our customers. Pixy Newspaper 11 has our whole backing. Premium members may easily contact us via Whatsapp or email for assistance with any issues. Purchase and Refund Policy



(getButton) #text=(Freebify Premium V1.3.1) #file=(Size: 194k) #icon=(download) #size=(1) #color=(#1bc517) #info=(Download)

(getButton) #text=(Freebify Premium V.1.3.0) #file=(Off: 30%) #icon=(buy) #size=(1) #color=(#bd2323) #info=(Buy Now)
Post a Comment