Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Design > Voices That Matter

This chapter is from the book

Other fixed-width assets

Images aren’t the only asset that present some problems for responsive sites. Let’s look at two in particular: video and advertising.

Video

Embedding videos in a responsive site is, perhaps surprisingly, a little more complicated than it first appears. If you’re using HTML5 video, it’s simple. You can use the same max-width technique we discussed for making images fluid:

1.    video{
2.         max-width: 100%;
3.         height: auto;
4.    }

Most sites, however, pull their videos from a third party (YouTube or Vimeo, for example) using an iFrame. If you apply the same trick, the width scales but the height retains its original value, breaking the aspect ratio (Figure 4.7).

Figure 4.7

Figure 4.7. Unfortunately, using max-width: 100% and height: auto on video embeds will result in the video breaking the aspect ratio.

The trick is something Thierry Koblentz called “intrinsic ratios.”5 The basic idea is that the box that contains the video should have the proper aspect ratio of the video (4:3, 16:9, and so on). Then, the video needs to fit the dimensions of the box. That way, when the width of the containing box changes, it maintains the aspect ratio and forces the video to adjust with it.

The first thing to do is create a wrapping element:

1.    <div class="vid-wrapper">
2.         <iframe></iframe>
3.    </div>

The wrapper serves as the containing box so it needs to maintain the proper aspect ratio. In this situation, the aspect ratio is 16:9. The video itself is positioned absolutely, so the wrapper needs an adequate amount of padding applied to maintain the ratio. To maintain the 16:9 ratio, divide 9 by 16, which gives you 56.25%.

1.    .vid-wrapper{
2.         width: 100%;
3.         position: relative;
4.         padding-bottom: 56.25%';
5.         height: 0;
6.    }
7.    .vid-wrapper iframe{
8.         position: absolute;
9.         top: 0;
10.        left: 0;
11.        width: 100%;
12.        height: 100%;
13.   }

The styles above also position the iFrame absolutely within the wrapper and set the height and width to 100% so it stretches to fill (lines 11–12). The wrapper itself is set to 100% of the article’s width (line 2) so it adjusts as the screen size adjusts.

With these styles in place, the video responds to different screen sizes while maintaining its original aspect ratio.

Enhancing the experience

As always, it’s worth taking a step back and considering how the experience can be enhanced. At the moment, the video is being downloaded on all devices. That might not be the best approach for the base experience. To speed up the core experience, it would be nice to display only a link to the video. Then, for larger screens, the video embed could be included.

To do this, start with a simple link:

<a id="video" href="http://www.youtube.com/watch?v=HwbE3bPvzr4">
Video highlights</a>

You can also add a few simple styles to make sure the text link doesn’t look out of place:

1.    .vid{
2.         display: block;
3.         padding: .3em;
4.         margin-bottom: 1em;
5.         background: url(../images/video.png) 5px center no-repeat #e3e0d9;
6.         padding-left: 35px;
7.         border: 1px solid rgb(175,175,175);
8.         color: #333;
9.    }

There’s nothing too fancy going on here. We gave the link a little padding and margin to set it apart from the rest of the content, and applied a background with a video icon set to the left (Figure 4.8).

Figure 4.8

Figure 4.8. With some styles in place, the video link fits nicely in with the rest of the page.

Now, with JavaScript, convert the link to the appropriate embed.

Add the following function to the Utils object in yass.js:

1.    getEmbed : function(url){
2.         var output = '';
3.         var youtubeUrl = url.match(/watch\?v=([a-zA-Z0-9\-_]+)/);
4.         var vimeoUrl = url.match(/^http:\/\/(www\.)?vimeo\.com           /(clip\:)?(\d+).*$/);
5.         if(youtubeUrl){
6.              output = '<div class="vid-wrapper"><iframe src="https://
                www.youtube.com/embed/'+youtubeUrl[1]+'?rel=0"
                frameborder="0" allowfullscreen></iframe></div>';
7.              return output;
8.         } else if(vimeoUrl){
9.              output =  '<div class="vid-wrapper"><iframe src="https://
                player.vimeo.com/video/'+vimeoUrl[3]+'" frameborder="0">
                </iframe></div>';
10.             return output;
11.        }
12.   }

Let’s walk through the function.

The function takes the URL of the video as its only parameter. It then determines if the URL is a YouTube video or a Vimeo video using regular expressions (lines 4–5). Depending on the URL type, it creates the embed markup including the containing element and returns it (lines 5–11).

Armed with the getEmbed function, it’s easy to convert the video link to an embed. Throw the following JavaScript within the matchMedia("(min-width: 37.5em)") test:

1.    //load in the video embed
2.    var videoLink = document.getElementById('video');
3.    if (videoLink) {
4.         var linkHref = videoLink.getAttribute('href');
5.         var result = Utils.getEmbed(linkHref);
6.         var parent = videoLink.parentNode;
7.         parent.innerHTML = result + videoLink.parentNode.innerHTML;
8.         parent.removeChild(document.getElementById('video'));
9.    }

The first two lines grab the link to the video and the link’s href. On line 5, the link is passed to the getEmbed function we created. Once you have the result, lines 6–8 insert it into the article and remove the text link (Figure 4.9).

Figure 4.9

Figure 4.9. On large screens (right) the video is embedded but small screens will see a link to the video instead.

Now the video embed is responsive, and is pulled in only when the screen size is greater than 37.5em, ensuring that the base experience won’t need to make the expensive HTTP requests to embed the video.

Advertising

Another fixed asset that presents some difficulties is advertising.

Like it or not, advertising is a key part of many businesses’ revenue stream online. We won’t get into a debate here about advertising-based revenue versus the pay-for-content model; that’s a discussion that gets ugly quickly. The reality of the matter is that for many businesses, ad revenue is essential.

From a purely technical standpoint, advertising in a responsive layout isn’t that difficult to implement. You could use JavaScript to conditionally load an ad unit based on the screen size. Rob Flaherty, a developer in New York City, demonstrated a basic method:6

1.    // Ad config
2.    var ads = {
3.         leaderboard: {
4.              width: 728,
5.              height: 90,
6.             breakpoint: false,
7.              url: '728x90.png'
8.         },
9.         rectangle: {
10.             width: 300,
11.             height: 250,
12.             breakpoint: 728,
13.             url: '300x250.png'
14.        },
15.        mobile: {
16.             width: 300,
17.             height: 50,
18.             breakpoint: 500 ,
19.             url: '300x50.png'
20.        }
21.   };

This configuration sets up three different ads (leaderboard, rectangle, and mobile). Each ad has a width (lines 4, 10, and 16), height (lines 5, 11, and 17), URL (lines 7, 13, and 19), and breakpoint at which point the ad should load (lines 6, 12, and 18). You could use the matchMedia function to determine which ad should be loaded based on the breakpoint.

Even better, the ad itself could be responsive. It could consist of HTML and CSS that allow it to adjust to different screen sizes. Going this route would eliminate the JavaScript dependency and potentially allow the ad to do some cool things by playing on its interactive nature.

From a technical perspective, neither of these options is particularly difficult. The problem is that creating and displaying an ad has a lot of moving parts.

Most ads are served by third-party networks or the creative pieces are developed externally and then submitted according to the specifications of the site. At the moment, no major ad-serving networks accommodate varying ad sizes based on screen size.

Using an internal ad serving platform is a bit more flexible, but if the creative is developed outside your company, then you’ll need to be willing to do some education. The people creating the ad materials may not be up to speed on what’s going on.

More importantly, ads are currently sold much like they are in print: You pay based on the size and placement of the ad. So how exactly do you do that when the size and placement vary?

One solution is to sell ad groups instead of ads. For example, instead of selling a skyscraper ad, you sell a Premier Group ad (or whatever you want to call it). The Premier Group may consist of a skyscraper for screens above 900px wide, a boom box for screens above 600px but below 900px, and a small banner for screen sizes below that point.

Obviously, this won’t be an easy transition. Creative teams, decision makers, and the salesforce all need to be educated on why this approach makes more sense than buying a defined ad space. It won’t be an easy sell, but with time it should get easier.

The other consideration here is that some companies may want to target only a single form factor. Perhaps their service is something specific to mobile devices, and they decide they’d only like to serve their ads to those smaller screens. That of course throws a little wrinkle into the ad groups, as things start to get broken up.

Ultimately, I’d like to see the discussion of responsive advertising lead to fewer ad spots and a higher cost per ad. Sites whose revenues are ad-based frequently overload their pages with a plethora of ads. This makes the situation more difficult when trying to handle the small-screen experience. Do you hide all those ads, thereby limiting page views for your advertisers, or do you cram them all in there and ruin the experience for your visitors?

Instead of loading up pages with more and more ads, reduce the amount of ads on a page. Instead of ten ad slots at $1,000 per month, offer three at $4,000 each. Make the ad spaces something worth coveting. It benefits advertisers because they have fewer ads competing for attention, and it benefits users because they are greeted with a much better experience.

Unfortunately there’s a chicken and the egg problem: advertising rates are currently a race to the bottom. Ads struggle to get quality click-through rates so the way to compete is to see how far you can lower the cost of entry. Someone has to be bold enough to make that first step.

Peachpit Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from Peachpit and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about Peachpit products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites; develop new products and services; conduct educational research; and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email ask@peachpit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by Adobe Press. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.peachpit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020