ag Flexible Captioned Slanted Images By feedproxy.google.com Published On :: Sat, 21 Dec 2019 12:00:00 +0000 Eric Meyer gift wraps the most awkwardly shaped of boxes using nothing but CSS, HTML and a little curl of ribbon. No matter how well you plan and how much paper you have at your disposal, sometimes you just need to slant the gift to the side. We have a lot of new layout tools at our disposal these days—flexbox is finally stable and interoperable, and Grid very much the same, with both technologies having well over 90% support coverage. In that light, we might think there’s no place for old tricks like negative margins, but I recently discovered otherwise. Over at An Event Apart, we’ve been updating some of our landing pages, and our designer thought it would be interesting to have slanted images of speakers at the tops of pages. The end result looks like this. The interesting part is the images. I wanted to set up a structure like the following, so that it will be easy to change speakers from time to time while preserving accessible content structures: <div id="page-top"> <ul class="monoliths"> <li> <a href="https://aneventapart.com/speakers/rachel-andrew"> <img src="/img/rachel-andrew.jpg" alt=""> <div> <strong>Rachel Andrew</strong> CSS Grid </div> </a> </li> <li> <a href="https://aneventapart.com/speakers/derek-featherstone"> <img src="/img/derek-featherstone.jpg" alt=""> <div> <strong>Derek Featherstone</strong> Accessibility </div> </a> </li> <li> … </li> <li> … </li> </ul> </div> The id value for the div is straightforward enough, and I called the ul element monoliths because it reminded me of the memorial monoliths at the entrance to EPCOT in Florida. I’m also taking advantage of the now-ubiquitous ability to wrap multiple elements, including block elements, in a hyperlink. That way I can shove the image and text structures in there, and make the entire image and text below it one link. Structure is easy, though. Can we make that layout fully responsive? I wondered. Yes we can. Here’s the target layout, stripped of the navbar and promo copy. So let’s start from the beginning. The div gets some color and text styling, and the monoliths list is set to flex. The images are in a single line, after all, and I want them to be flexible for responsive reasons, so flexbox is 100% the right tool for this particular job. #page-top { background: #000; color: #FFF; line-height: 1; } #page-top .monoliths { display: flex; padding-bottom: 1em; overflow: hidden; } I also figured, let’s give the images a simple basis for sizing, and set up the hyperlink while we’re at it. #page-top .monoliths li { width: 25%; } #page-top .monoliths a { color: inherit; text-decoration: inherit; display: block; padding: 1px; } So now the list items are 25% wide—I can say that because I know there will be four of them—and the links pick up the foreground color from their parent element. They’re also set to generate a block box. At this point, I could concentrate on the images. They need to be as wide as their parent element, but no wider, and also match height. While I was at it, I figured I’d create a little bit of space above and below the captioning text, and make the strong elements containing speakers’ names generate a block box. #page-top .monoliths img { display: block; height: 33rem; width: 100%; } #page-top .monoliths div { padding: 0.5em 0; } #page-top .monoliths strong { display: block; font-weight: 900; } It looks like the speakers were all cast into the Phantom Zone or something, so that needs to be fixed. I can’t physically crop the images to be the “correct” size, because there is no correct size: this needs to work across all screen widths. So rather than try to swap carefully-sized images in and out at various breakpoints, or complicate the structure with a wrapper element set to suppress overflow of resized images, I turned to object-fit. #page-top .monoliths img { display: block; height: 33rem; width: 100%; object-fit: cover; object-position: 50% 20%; } If you’ve never used object-fit, it’s a bit like background-size. You can use it to resize image content within the image’s element box without creating distortions. Here, I set the fit sizing to cover, which means all of the img element’s element box will be covered by image content. In this case, it’s like zooming in on the image content. I also set a zooming origin with object-position, figuring that 50% across and 20% down would be in the vicinity of a speaker’s face, given the way pictures of people are usually taken. This is fairly presentable as-is—a little basic, perhaps, but it would be fine to layer the navbar and promo copy back over it with Grid or whatever, and call it a day. But it’s too square and boxy. We must go further! To make that happen, I’m going to take out the third and fourth images temporarily, so we can see more clearly how the next part works. That will leave us with Rachel and Derek. The idea here is to clip the images to be slanted, and then pull them close to each other so they have just a little space between them. The first part is managed with clip-path, but we don’t want to pull the images together unless their shapes are being clipped. So we set up a feature query. @supports (clip-path: polygon(0 0)) or (-webkit-clip-path: polygon(0 0)) { #page-top .monoliths li { width: 37.5%; } } I decided to test for both the un-prefixed and WebKit-prefixed versions of clip-path because Safari still requires the prefix, and I couldn’t think of a good reason to penalize Safari’s users for the slowness of its standards advancement. Then I made the images wider, taking them from 25% to 37.5%, which makes them half again as wide. Thanks to object fitting, the images don’t distort when I change their parent’s width; they just get wider and scale up the contents to fit. And now, it is time for clipping! @supports (clip-path: polygon(0 0)) or (-webkit-clip-path: polygon(0 0)) { #page-top .monoliths li { width: 37.5%; -webkit-clip-path: polygon(25% 0, 100% 0, 75% 100%, 0 100%); clip-path: polygon(25% 0, 100% 0, 75% 100%, 0 100%); } } Each coordinate pair in the polygon() is like the position pairs in background-position or object-position: the horizontal distance first, followed by the vertical distance. So the first point in the polygon is 25% 0, which is 25% of the way across the element box, and no distance down, so right at the top edge. 100% 0 is the top right corner. 75% 100% is on the bottom edge, three-quarters of the way across the element, and 0 100% is the bottom left corner. That creates a polygon that’s a strip three-quarters the full width of the element box, and runs from bottom left to top right. Now we just have to pull them together, and this is where old tricks come back into play: all we need is a negative right margin to bring them closer together. #page-top .monoliths li { width: 37.5%; margin-right: -7.5%; -webkit-clip-path: polygon(25% 0, 100% 0, 75% 100%, 0 100%); clip-path: polygon(25% 0, 100% 0, 75% 100%, 0 100%); } The separation between them is a little wider than we were originally aiming for, but let’s see what happens when we add the other two images back in and let flexbox do its resizing magic. Your browser doesn’t support HTML5 video. Here is a link to the video instead. Notice how the slants actually change shape as the screen gets narrower or wider. This is because they’re still three-quarters the width of the image element’s box, but the width of that box is changing as the screen width changes. That means at narrow widths, the slant is much steeper, whereas at wide widths, the slant is more shallow. But since the clipping path’s coordinates were all set with percentage distances, they all stay parallel to each other while being completely responsive to changes in screen size. An absolute measure like pixels would have failed. But how did the images get closer together just by adding in two more? Because the list items’ basic sizing added up to more than 100%, and they’re all set to flex-shrink: 1. No, you didn’t miss a line in the CSS: 1 is the default value for flex-shrink. Flex items will shrink by default, which after all is what we should expect from a flexible element. If you want to know how much they shrunk, and why, here’s what Firefox’s flex inspector reports. When there were only two list items, there was space enough for both to be at their base size, with no shrinkage. Once we went to four list items, there wasn’t enough space, so they all shrank down. At that point, having a negative right margin of -7.5% was just right to pull them together to act as a unit. So, now they’re all nicely nestled together, and fully responsive! The captions need a little work, though. Notice how they’re clipped off a bit on the left edge, and can be very much clipped off on the right side at narrower screen widths? This happens because the li elements are being clipped, and that clipping applies to all their contents, images and text alike. And we can’t use overflow to alter this: clipped is clipped, not overflowed. Fortunately, all we really need to do is push the text over a small amount. Inside the feature query, I added: #page-top .monoliths div { padding-left: 2%; padding-right: 26%; } This shifts the text just a bit rightward, enough to clear the clip path. On the right side, I padded the div boxes so their contents wouldn’t fall outside the clipped area and appear to slide under the next caption. We could also use margins here, but I didn’t for reasons I’ll make clear at the end. At the last minute, I decided to make the text at least appear to follow the slants of the images. For that, I just needed to shift the first line over a bit, which I did with a bit more padding. #page-top .monoliths strong { padding-left: 1%; } That’s all to the good, but you may have noticed the captions still overlap at really narrow screen widths. There are a lot of options here, from stacking the images atop one another to reverting to normal flow, but I decided to just hide the captions if things got too narrow. It reduces clutter without sacrificing too much in the way of content, and by leaving them still technically visible, they seem to remain accessible. @media (max-width: 35rem) { #page-top .monoliths div { opacity: 0.01 } } And that, as they say, is that! Fully responsive slanted images with text, in an accessible markup structure. I dig it. I did fiddle around with the separations a bit, and found that a nice thin separator occurred around margin-right: -8%, whereas beefier ones could be found above -7%. And if you crank the negative margin value to something beyond -8%, you’ll make the images overlap entirely, no visible separation—which can be a useful effect in its own right. I promised to say why I used padding for the caption text div rather than margins. Here’s why. #page-top .monoliths div { padding-left: 3%; padding-right: 26%; border-top: 2px solid transparent; background: linear-gradient(100deg,hsl(292deg,50%,50%) 50%, transparent 85%); background-clip: padding-box; } It required a wee bit more padding on the left to look decent, and an alteration to the background clipping box in order to keep the purple from filling the transparent border area, but the end result is pretty nifty, if I do say so myself. Alternatively, we could drop the background gradient on the captions and put one in the background, with a result like this. I have no doubt this technique could be extended, made more powerful, and generally improved upon. I really wished for subgrid support in Chrome, so that I could put everything on a grid without having to tear the markup structure apart, and there are doubtless even more interesting clipping paths and layout patterns to try out. I hope these few ideas spark some much better ideas in you, and that you’ll share them with us! About the author Eric A. Meyer (@meyerweb) has been a burger flipper, a college webmaster, an early blogger, one of the original CSS Samurai, a member of the CSS Working Group, a consultant and trainer, and a Standards Evangelist for Netscape. Among other things, Eric co-wrote Design For Real Life with Sara Wachter-Boettcher for A Book Apart and CSS: The Definitive Guide with Estelle Weyl for O’Reilly, created the first official W3C test suite, assisted in the creation of microformats, and co-founded An Event Apart with Jeffrey Zeldman. Eric lives with his family in Cleveland, Ohio, which is a much nicer city than you’ve probably heard. He enjoys a good meal whenever he can and considers almost every form of music to be worthwhile. More articles by Eric Full Article Design css
ag The scientist and the spy: a true story of China, the FBI, and industrial espionage / Mara Hvistendahl By library.mit.edu Published On :: Sun, 15 Mar 2020 08:09:28 EDT Dewey Library - HV7561.H85 2020 Full Article
ag Democracy Incorporated: Managed Democracy and the Specter of Inverted Totalitarianism - New Edition / Sheldon S. Wolin By library.mit.edu Published On :: Sun, 22 Mar 2020 07:44:49 EDT Online Resource Full Article
ag Age of iron: on conservative nationalism / by Colin Dueck By library.mit.edu Published On :: Sun, 22 Mar 2020 07:44:49 EDT Dewey Library - JC573.2.U6 D8354 2020 Full Article
ag The lost soul of the American presidency: the decline into demagoguery and the prospects for renewal / Stephen F. Knott By library.mit.edu Published On :: Sun, 5 Apr 2020 07:47:23 EDT Dewey Library - JK511.K66 2019 Full Article
ag Managing interdependencies in federal systems: intergovernmental councils and the making of public policy / Johanna Schnabel By library.mit.edu Published On :: Sun, 5 Apr 2020 07:47:23 EDT Online Resource Full Article
ag Human rights in the age of platforms / edited by Rikke Frank Jørgensen ; foreword by David Kaye By library.mit.edu Published On :: Sun, 5 Apr 2020 07:47:23 EDT Dewey Library - JC571.H7695266 2019 Full Article
ag Wartime sexual violence against men: masculinities and power in conflict zones / Élise Féron By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Dewey Library - HV6558.F47 2018 Full Article
ag Leadership studies and the desire for shared agreement: a narrative inquiry / Stan Amaladas By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Dewey Library - JF1525.L4 A63 2019 Full Article
ag Citizenship as a regime: Canadian and international perspectives / edited by Mireille Paquet, Nora Nagels, and Aude-Claire Fourot By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Dewey Library - JF801.C58 2018 Full Article
ag Federalism and national diversity in the 21st Century / Arjun Tremblay, Alain-G Gagnon By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Online Resource Full Article
ag 21st century Prometheus: managing CBRN safety and security affected by cutting-edge technologies / Maurizio Martellini, Ralf Trapp, editors By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Online Resource Full Article
ag No place on the corner: the costs of aggressive policing / Jan Haldipur By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Rotch Library - HV8148.N5 H35 2019 Full Article
ag The three Ps of liberty: pragmatism, pluralism, and polycentricity / Allen Mendenhall By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Online Resource Full Article
ag The infamous Harry Hayward: a true account of murder and mesmerism in gilded age Minneapolis / Shawn Francis Peters By library.mit.edu Published On :: Sun, 26 Apr 2020 09:04:30 EDT Hayden Library - HV6248.H3 P47 2018 Full Article
ag International intervention instruments against corruption in Central America Laura Zamudo-González By library.mit.edu Published On :: Sun, 3 May 2020 10:24:48 EDT Online Resource Full Article
ag Muzaffarnagar riots: 'They harassed me daily and killed my uncles' By archive.indianexpress.com Published On :: Thu, 19 Sep 2013 20:26:56 GMT Genesis of Muzaffarnagar riots is not just that of two communities turned against each other. Full Article
ag Speeding bus kills 2, locals damage vehicles in protest By archive.indianexpress.com Published On :: Fri, 20 Sep 2013 07:32:36 GMT The incident sparked off a massive protest by the local people. Full Article
ag DA case: Jaganmohan Reddy's judicial custody extended till October 3 By archive.indianexpress.com Published On :: Fri, 20 Sep 2013 08:51:26 GMT Court had earlier on Sept 18 reserved its order till Sept 23 on Jagan's bail plea. Full Article
ag Muzaffarnagar Violence: Two former MLAs resign from SP By archive.indianexpress.com Published On :: Sat, 21 Sep 2013 10:07:57 GMT Father-son duo said the administration could have stopped the Muzaffarnagar riots. Full Article
ag Muzaffarnagar violence to be raised at NIC meeting: Nitish By archive.indianexpress.com Published On :: Sat, 21 Sep 2013 10:42:54 GMT Kumar said his government was proactive in reducing communal disturbances. Full Article
ag Uttar Pradesh govt revokes IAS officer Durga Shakti Nagpal's suspension By archive.indianexpress.com Published On :: Mon, 23 Sep 2013 14:52:11 GMT Nagpal was suspended on July 27 ostensibly for taking on the powerful sand mining mafia. Full Article
ag Pakistan violates ceasefire again, targets Indian posts in Rajouri By archive.indianexpress.com Published On :: Sun, 22 Sep 2013 16:15:10 GMT This is the 19th ceasefire violation by Pakistan in September alone, 97 such incidents this year. Full Article
ag Dilsukhnagar blasts case: Yasin Bhatkal brought to Hyderabad By archive.indianexpress.com Published On :: Sun, 22 Sep 2013 16:39:47 GMT Yaskin Bhatkal's close associate Asadullah Akhtar is presently being interrogated by the NIA. Full Article
ag IAS body: Revocation of Durga Shakti Nagpal's suspension a delayed decision By archive.indianexpress.com Published On :: Sun, 22 Sep 2013 17:01:36 GMT IAS body demanded specific mechanism to check undue pressure on bureaucrats. Full Article
ag 1 jawan killed in militant attack in Srinagar By archive.indianexpress.com Published On :: Mon, 23 Sep 2013 10:21:20 GMT Suspect militants killed 1 Indian paramilitary soldier, seriously wounded another on Monday. Full Article
ag 26/11 Terror Attack: Magistrate denies recording false confession of Ajmal Kasab By archive.indianexpress.com Published On :: Wed, 25 Sep 2013 16:03:07 GMT "Not true that I recorded false statement of Kasab when he was produced before me" Full Article
ag Karnataka: Rains leave 119 dead, damage Rs 2724 cr property By archive.indianexpress.com Published On :: Thu, 26 Sep 2013 10:06:26 GMT The CM says the steps have been taken by his government to meet the situation. Full Article
ag Uttarakhand Tragedy: Roads remain out of bounds, villagers' woes continue By archive.indianexpress.com Published On :: Thu, 26 Sep 2013 11:11:25 GMT Things have improved substantially over the past few weeks, says Joint Relief Commissioner Nitin Bhadauriya. Full Article
ag Raghuram Rajan data backs Nitish Kumar plea: Bihar is 2nd most backward By archive.indianexpress.com Published On :: Thu, 26 Sep 2013 23:14:49 GMT "Least developed" index is dominated by non-UPA ruled states, which make up six of the bottom ten. Full Article
ag Bandh in Jammu against terror attack By archive.indianexpress.com Published On :: Fri, 27 Sep 2013 09:08:23 GMT Police deployed throughout the city to prevent any unfavorable situations. Full Article
ag Mumbai's collapsed building was tagged as dangerous to live in By archive.indianexpress.com Published On :: Fri, 27 Sep 2013 10:21:28 GMT The building constructed in 1980, was tagged in the C-2 category of dangerous buildings. Full Article
ag Anti nuke activists demand action against police officials By archive.indianexpress.com Published On :: Sat, 28 Sep 2013 12:03:12 GMT PMANE leaders said Tamil Nadu govt hasn't made efforts to withdraw cases against nonviolent protesters. Full Article
ag Weeks after Muzaffarnagar violence, women allege rape in written complaints By archive.indianexpress.com Published On :: Sat, 28 Sep 2013 23:32:30 GMT The Fugana police station has registered two cases of rape and one case of molestation. Full Article
ag Three weeks after clashes, new births offer new hope in Muzaffarnagar By archive.indianexpress.com Published On :: Sun, 29 Sep 2013 00:07:34 GMT In Muzaffarnagar, three of the biggest relief camps in Kandhla, Basikala and Malakpur have seen the birth of about 27 babies. Full Article
ag Post Riots, Samajwadi Party committee to strengthen communal harmony in Muzaffarnagar By archive.indianexpress.com Published On :: Sun, 29 Sep 2013 12:52:16 GMT Committee members to visit affected people's homes to generate confidence among them. Full Article
ag Bombay HC defers hearing on Adarsh's plea against demolition order By archive.indianexpress.com Published On :: Mon, 30 Sep 2013 12:59:47 GMT Hearing after SC decides Adarsh Society's plea seeking transfer of the matter to National Green Tribunal. Full Article
ag Out of jail, Jagan appreciates Modi as an administrator By archive.indianexpress.com Published On :: Mon, 30 Sep 2013 13:47:09 GMT 'Religion should not be politicised and my party is committed to secularism', Jagan said. Full Article
ag Jaganmohan Reddy praises Modi, urges him to build a secular platform By archive.indianexpress.com Published On :: Mon, 30 Sep 2013 23:11:41 GMT Reddy also said he would do what all other secular parties do and that he had options. Full Article
ag Muzaffarnagar violence: Mulayam wants riots relief camps to close soon By archive.indianexpress.com Published On :: Tue, 01 Oct 2013 19:32:37 GMT Mulayam expressed concern that relief camps were adversely impacting the image of the Akhilesh govt. Full Article
ag Jayalalithaa rejects Raghuram Rajan committee's state-aid report By archive.indianexpress.com Published On :: Wed, 02 Oct 2013 08:10:11 GMT Report has excluded important dimensions of development; should not be used in any form, Jaya said. Full Article
ag Muzaffarnagar riots: A munshi has his hands full writing FIRs By archive.indianexpress.com Published On :: Wed, 02 Oct 2013 21:48:26 GMT He wrote 177 FIRs in first three days and then lost count as complaints poured in. Full Article
ag Srinagar encounter ends, militants escape By archive.indianexpress.com Published On :: Thu, 03 Oct 2013 07:00:41 GMT Four more cops sustained minor injuries in the exchange of fire between the two sides. Full Article
ag Telangana decision triggers massive protests in Andhra, Jagan to go on fast By archive.indianexpress.com Published On :: Fri, 04 Oct 2013 05:51:32 GMT Protests broke out in cities from Srikakulam in north coastal AP to Anantapur down in Rayalaseema. Full Article
ag Cong MP Rajagopal to move SC against AP bifurcation decision By archive.indianexpress.com Published On :: Fri, 04 Oct 2013 06:02:17 GMT Move violates the federal principles and structure of the Constitution, Rajagopal said. Full Article
ag Riots: Inquiry commission to reach Muzaffarnagar on Oct 6 By archive.indianexpress.com Published On :: Fri, 04 Oct 2013 08:57:17 GMT The commission will be working from the camp office of Naveen Mandi guesthouse in Muzaffarnagar. Full Article
ag Ajit Singh's RLD to move SC for CBI probe into Muzaffarnagar violence By archive.indianexpress.com Published On :: Wed, 09 Oct 2013 09:01:34 GMT Singh hinted that the riots were orchestrated by ruling SP in collusion with BJP. Full Article
ag Fight against terrorism has to be unrelenting: Arun Jaitley By archive.indianexpress.com Published On :: Wed, 09 Oct 2013 09:12:17 GMT Jaitely said India is working with fellow SAARC nations to strengthen counter-terrorism cooperation. Full Article
ag Defence Ministry to issue showcause notice to AgustaWestland for cancelling deal By archive.indianexpress.com Published On :: Wed, 09 Oct 2013 13:55:20 GMT Government has frozen the contract for supply of 12 AW-101 VVIP choppers to the IAF. Full Article
ag SC disapproves gun firing to celebrate marriage ceremonies By archive.indianexpress.com Published On :: Wed, 09 Oct 2013 14:14:56 GMT Guns must be carried with a sense of responsibility and caution, SC stated. Full Article