Prior to using grid for the layout styles, I might have tried absolute positioning on the image and title, used an aspect ratio padding trick to create a responsive height, and object-fit to retain the ratio of the image. Resize the viewport height and the container will flex between its max-height’s lower and upper bound values defined in the clamp() function. Notice that the image continues to grow while remaining centered in the container. The positioning of these blocks is at the heart of layout: placing elements in the. As Alexander said, you can use a, but a is based of the size of the parent element. When we build layouts, we deal with multiple blocks defined by the
tag.
Rather than setting a static position, try setting a max-height/width. Based on the image dimensions, the container height expands until it hits a maximum height. Have you tried using a framework like Foundation very good for responsive design. Open this Pen and resize the viewport width. Haven’t used them? Ahmad Shadeed conducts a fantastic deep dive in this article. Combining this layout technique and a fluid container max-height using the CSS clamp() function, we can develop something that adjusts based on the available viewport space while anchoring the hero image to the center of the container.ĬSS clamp(), along with the min() and max() comparison functions, are well-supported in all modern browsers. Because of this, the content strategy team has requested that some of the pertinent page content below the hero remain visible in the viewport as much as possible. Although the image is capped with a max-width, it scales up to be quite tall on desktop. Here’s a common hero section with a headline overlapping an image. In the demo, there is a checkbox that toggles the overflow visibility so that we can see where the image dimensions expand beyond the container on larger viewport widths.
0 Comments
Leave a Reply. |