wordpress-seo
domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home2/thebrand/public_html/wp-includes/functions.php on line 6114In the real world, content often differs vastly from the neat, perfectly fitting content presented in designs. Added to that, on the modern web, users have an ever-increasing range of options for how they access the sites we build.<\/p>\n
In this article, we\u2019ll walk through the process of taking a seemingly simple design for a text-and-media component and deciding how best to translate it into code, keeping in mind the needs of both users and content authors. We\u2019re not going to delve into how<\/em> to code it \u2014 rather, the factors that will determine our development decisions. We\u2019ll consider the questions we need to ask (both ourselves and other stakeholders) at every step.<\/p>\n Changing Our Development Mindset <\/p>\n We simply can no longer design and develop only for \u201coptimal\u201d content or browsing conditions. Instead, we must embrace the inherent flexibility and unpredictability of the web, and build resilient components. Static mockups cannot cater to every scenario, so many design decisions fall to developers at build time. Like it or not, if you\u2019re a UI developer, you are<\/em> a designer \u2014 even if you don\u2019t consider yourself one!<\/p>\n In my job at WordPress specialist web agency Atomic Smash<\/em>, we build websites for clients who need maximum flexibility from the components we provide, while ensuring the site still looks great, no matter what content they throw at it. Sometimes interpreting a design means asking the designer to further elaborate on their ideas (or even re-evaluate them). Other times, it means making design decisions on the fly or making recommendations based on our knowledge and experience. We\u2019ll look at some of the times these approaches might be appropriate in this case study.<\/p>\n The Design <\/p>\n We start with a simple design for a text-and-media component \u2014 something fairly commonly seen on product landing pages. It consists of an image or video on the left and a column on the right containing a heading, a paragraph of text and a call-to-action link. This design is for a (fictional) startup that helps people who want to learn a new skill find a tutor.<\/p>\n <\/p>\n Note:<\/strong> If you want to jump straight to the code and view all the possible solutions we alighted on for this component, you can find it in this Codepen demo<\/a>.<\/em><\/p>\n Layout And Order <\/p>\n The designer has stipulated that every other component should have the layout flipped so that the image is on the right and the text column on the left. <\/p>\n <\/p>\n In the mobile layout, however, the image is stacked above the text content in all cases. Assuming we build this layout using either Grid or flexbox, we could use It\u2019s worth bearing in mind that while these will reorder the content visually, it does not change the DOM order. This means that to a partially-sighted person browsing the site using a screenreader, the order of the content may not appear logical, jumping from left-to-right to right-to-left.<\/p>\n Speaking personally, in the case where the only content in one of the columns is an image, I feel that using the We also need to consider whether to enforce the order through the Dealing With Different Content Lengths <\/p>\n In the design, the proportion of text content compared to the image is quite pleasing. It allows the image to maintain an ideal aspect ratio. But what should happen if the text is longer or shorter than what\u2019s presented? Let\u2019s deal with the former first.<\/p>\n We can set a character limit on the text field in our chosen CMS (if we\u2019re so inclined), but we should allow for at least some<\/em> variation in our component. If we add a longer paragraph, the opposing media column could behave in one of several ways:<\/p>\n <\/p>\n <\/p>\n <\/p>\n We decided that option 3 was the most pleasing visually, and that for the most part content authors would be able to source appropriate images where a small amount of clipping would be acceptable. But it presented more of a challenge for video content, where there is more of a risk that important parts could be clipped. We alighted on another option, which was to create a different variation of the design where the video would maintain its original aspect ratio, and be contained within a maximum width instead of aligning to the edge of the page.<\/p>\n <\/p>\n Content authors could choose this option when it better suited their needs.<\/p>\n Additionally, we opted to extend this choice to instances where an image was used instead of a video. It gives the client a wider variety of layout options without adversely impacting the design. Seen in the wider page context it could even be considered an improvement, allowing for more interesting pages when several of these blocks are used on a page.<\/p>\n Dealing with less content is a little simpler, but still presents us with some issues. How should the image behave when the text content is shorter? Should it become shallower, so that the overall height of the component is determined by the text content (fig. 4)? Or should we set a minimum aspect ratio, so that the image doesn\u2019t become letterboxed, or allow the image to take up its natural, intrinsic height? In that case, we also have the consideration of whether to align the text centrally or to the top (fig. 5 and 5a).<\/p>\n <\/p>\n <\/p>\n <\/p>\n Let\u2019s not forget we\u2019ll also need to test headings of different lengths. In the design the headings are short and snappy, rarely wrapping onto a second line. But what if a heading is several lines long, or the content uses a lot of long words, resulting in text wrapping differently? This might especially be a problem in languages such as German, where words tend to be much longer than English, for example. Does the size of the heading font in the design allow for an appropriate line length when used in this layout? Should long words be hyphenated when they wrap? This article<\/a> by Ahmad Shadeed addresses the issue of content length and included some handy tips for ways to deal with it in CSS.<\/p>\n Are content authors permitted to omit a heading altogether where it suits them? That brings us to the next consideration.<\/p>\n Omitting Content <\/p>\n Building this component as flexibly as possible means making sure that content authors can omit certain fields and still have the design look and function properly. It seems reasonable that the client may wish to omit the body text, the link, or even the heading when using this component in the wild. We need to take care to test with every conceivable combination of content, so that we can be confident our component won\u2019t break under stress. It\u2019s good practice to ensure we\u2019re not rendering empty HTML tags when field content isn\u2019t present. This will help us avoid unforeseen layout bugs.<\/p>\n <\/p>\n We can<\/em> restrict content authors with \u201crequired\u201d fields in the CMS, but perhaps we might also wish to consider scenarios where a client might choose to omit the image, or, conversely, without any<\/em> of the text content? It might be helpful to provide them with these options. Here\u2019s an example of how we might elect to render the component in those cases:<\/p>\n <\/p>\n By indenting the text a little more and increasing the width of the body text, we can keep it feeling balanced, even when there is no image.<\/p>\n Multiple Links <\/p>\n Omitting content is one scenario. But at Atomic Smash, we found that more often, clients wanted the option to add more than one link to the component. That presents us with another choice: how to layout multiple links? Do we lay them out side-by-side (fig. 8), or stack them vertically (fig. 8a)?<\/p>\n <\/p>\n <\/p>\nflex-direction<\/code> or the
order<\/code> property to reorder the layout for every second component:<\/p>\n
.text-and-media:nth-child(even) { flex-direction: row-reverse; }<\/code><\/pre>\n
order<\/code> property is more or less okay. But if we had two columns of text, for instance, reordering with CSS might make for a confusing experience. In those cases, we have some other options available to us. We could:<\/p>\n
\n
:nth-child<\/code> selector or to allow the client to control the order (by adding a class to the component, say). The suitability of each option will likely depend on the project.<\/p>\n
Longer Content<\/h3>\n
\n
object-fit: cover<\/code> to prevent distortion and ensure the image fills the available space. This would mean some parts of the image may be clipped (fig. 3).<\/li>\n<\/ol>\n
Shorter Content<\/h3>\n
Heading Length<\/h3>\n