One of the HTML elements that frequently comes into collision with CSS is the img
element. As we learned in Request Metrics’ Fixing Cumulative Layout Shift Problems on DavidWalshBlog article, providing image dimensions within the image
tag will help to improve your website’s score. But in a world where responsive design is king, we need CSS and HTML to work together.
Most responsive design style adjustments are done via max-width
values, but when you provide a height
value to your image, you can get a distorted image. The goal should always be a display images in relative dimensions. So how do we ensure the height
attribute doesn’t conflict with max-width
values?
The answer is as easy as height: auto
!
/* assuming any media query */ img { /* Ensure the image doesn't go offscreen */ max-width: 500px; /* Ensure the image height is responsive regardless of HTML attribute */ height: auto; }
The dance to please users and search engines is always a fun balance. CSS and HTML were never meant to conflict but in some cases they do. Use this code to optimize for both users and search engines!
How I Stopped WordPress Comment Spam
I love almost every part of being a tech blogger: learning, preaching, bantering, researching. The one part about blogging that I absolutely loathe: dealing with SPAM comments. For the past two years, my blog has registered 8,000+ SPAM comments per day. PER DAY. Bloating my database…
Create a 3D Panorama Image with A-Frame
In the five years I’ve been at Mozilla I’ve seen some awesome projects. Some of them very popular, some of them very niche, but none of them has inspired me the way the MozVR team’s work with WebVR and A-Frame project have. A-Frame is a community project…
dwProgressBar v2: Stepping and Events
dwProgressBar was a huge hit when it debuted. For those of you who didn’t catch my first post, dwProgressBar is a MooTools 1.2-based progress bar which allows for as much flexibility as possible. Every piece of dwProgressBar can be controlled by CSS…
Source link