Tips for refraining from transmitting visuals to cell phones in a more meaningful way

Typically when working on responsive or mobile-first design, media queries are utilized to deliver different CSS styles based on screen size.

An optimal design strategy may involve not including any images in the default (small) resolution layout.

While using background-image in CSS makes it simple to achieve this, it seems challenging to implement for semantic <img> tags.

  • Is it possible to accomplish this with HTML alone?
  • Is it considered good practice to use CSS exclusively for handling images?

Personally, I prefer a design with no images by default for small screens, but I find it unappealing to have no images for desktop-only versions that lack CSS.

Please note: Solutions involving JavaScript are not viable options.

Reference Image

Answer №1

A common misconception is that using CSS for all images is acceptable. However, images are valuable data and should be marked up as an <img> element for semantic clarity. Consider the analogy of considering all images optional, which would render the <img> element obsolete, indicating that it's not justifiable to use CSS for all images.

CSS is best utilized for enhancing elements visually through properties like background-image, without compromising their functionality. An element should remain usable even without a background image, demonstrating that if it can't be visible without one, it may not be a valid element at all.

Display and positioning properties in CSS serve the purpose of arranging elements on the screen and adjusting their visibility based on different displays.

To correctly handle this situation, utilizing display: none; is recommended, assuming that most browsers won't download the image unnecessarily. In cases where browser support is inadequate, alternative strategies such as using a hack like background-image or dynamically loading the image with Javascript can be considered as fallback options.

Answer №2

A creative solution using only CSS, with potential browser support limitations. By avoiding the img tag, the content remains semantic even without the image.

Find more details at: http://www.w3.org/TR/CSS2/generate.html

Check out an example here: http://jsfiddle.net/davetayls/SuhDj/1/

Personally, I suggest providing descriptive links for images and utilizing JavaScript to load them when necessary (like this: https://github.com/davetayls/jquery.lazyLoader). This ensures accessibility for users on various devices or connections, allowing everyone to access the images naturally rather than being hindered by embedded URLs in a CSS file.

Answer №3

When considering the option of utilizing descriptive links and implementing JavaScript to load images for screens that meet your specific criteria:

  1. Lazyloader.js is specifically designed for this purpose. According to the readme, "If you want to dynamically load images dependent on the screen dimensions ..." and it provides guidance on scripting for this functionality.

  2. Nettutsplus has compiled a comprehensive overview of lazyloader and various other useful scripts tailored for similar purposes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Controling attributes during the design process

Experimenting with a basic User Control in Visual Studio 2008: I've created a Panel called Wrapper with various controls inside. Will Visual Studio be able to handle this during the design phase? public partial class TestControl : System.Web.UI.UserC ...

The HTML form is not displaying any content and instead is returning "Not a Number

I've been struggling to create a form that can generate a numerical value based on the input from two fields. Specifically, I need to calculate the output by subtracting the product of two values - one entered in an input field and another selected vi ...

Using jQuery to Drag: Creating a draggable effect on a div element

I recently posted a question, but I feel like I need to rephrase it to make it more general. Basically, I have an element that can be moved around and resized using jQuery. I used CSS to attach another div to the right of this element. Initially, when you ...

A guide on personalizing HTML for Django forms

I have implemented an HTML template on my website and need to capture information for my Django backend. Specifically, I am trying to extract the email address from this section of code: <input type="text" placeholder="Email" value="" style="height: 30 ...

Tips for overlaying text on the background in Next.js:

I'm currently working on creating an image element with overlay text. Check out my jsx code below: <div className={styles.img}> <img src={src} alt="" /> <p>{`(${size})`}</p> </div> And here is t ...

I'm looking for assistance in changing my mascot image to a pixelated image when I hover over it. Can anyone provide guidance on how to achieve this?

Seeking assistance on how to change my mascot image to a pixelated image when hovered over. Any tips or advice would be appreciated! Here is the CSS I'm currently using: .mascot { display: block; margin-left: auto; margin-right: auto; ...

Prevent a div from scrolling once it reaches the end of its content, while allowing the other div to continue

I am trying to make the col-md-4 column stop scrolling once it reaches the end of the content, similar to the right sidebar on Facebook. I have attempted using jQuery to add a fixed position when it reaches the bottom, but it is not working as expected. Th ...

What is the best way to style the current element being targeted in React?

In my React application, I am trying to dynamically adjust the height of a textarea element based on its content. I want to achieve this by utilizing an 'onchange' listener to trigger a resize function. While I have successfully implemented the ...

Adjust the hue as you scroll

I've been searching for a solution to this issue, but I haven't been able to make it work. My goal is to have the page header change from a transparent background to a red background as the user starts scrolling down the page. $(window).on("s ...

Design a CSS floating div with a captivating bubble effect

My current setup includes a DIV element styled as follows: <div class="modal"></div> .modal { position: fixed; z-index: 999999; right: 310px; top: 67px; width: 431.6px; height: 550px; border-radius: 25px; box-s ...

What is the method for embedding HTML content into the header section of tcpdf?

I am currently utilizing the tcpdf library to create a PDF document. I have implemented the smarty template engine to manage the data. Below is the code snippet for inserting header data: // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, ...

Is it possible to change label text using CSS without referencing the element by its ID?

Here is a simple code snippet: <div class="delem"><label class="required" for="last_name">Full Name :</label><input id="fullname" type="text" name="fullname" value="" class="fullsize" required=""></div> <div class="delem" ...

Get the file from the web browser

Hey there, greetings from my part of the world. I have some straightforward questions that I'm not sure have simple answers. Currently, I am working on a web application using the JSP/Servlet framework. In this app, users can download a flat text fil ...

What could be the reason for the clone function not duplicating the data within the table

Recently, I utilized jQuery's clone method to duplicate and add an HTML table. The rows and cells of the table were added using jQuery. However, despite using clone, it only replicated the headers and CSS, not the appended data. This raises the ques ...

Interested in compressing CSS and JavaScript using PHP, but uncertain about the impact on performance and the best methods to implement it?

My current approach involves using PHP to combine multiple css (or js) files into a single file, while also compressing the content using GZIP. For example, the HTML page makes calls to resources like this... <link rel="stylesheet" href="Concat.php?fi ...

Customizing the hover behavior of a div element without causing displacement of surrounding elements

I am facing an issue where the descriptions in my list of 100 items are longer than the width of the div, causing the text to be cut off. I want to display the full description on hover without affecting the layout of other items. Currently, when I hover o ...

Having issues with CSS animation keyframes not functioning properly in NextJS

Currently, I have a straightforward component in NextJS that is displaying "HI" upon loading. This component fades in when rendered, but I am facing an issue while trying to pass a prop to make it fade out. The problem lies in the fact that even though the ...

What is the simplest method to create a scroller for engaging narratives?

I am in the process of creating a static but responsive storytelling website using HTML. My objective is to create an effect similar to this: https://i.stack.imgur.com/zIEpU.gif The idea is to have text on the left and a *.jpg image fixed on the right. As ...

What is the process for saving an SVG element from an HTML page as a downloadable text file?

I've been practicing creating SVG elements from scratch on an HTML page using Javascript. The texts within the SVG element are styled with typefaces fetched from the server through a "@font-face" declaration in the CSS file. It's been quite succe ...

How to create a vertically scrollable div within another div by utilizing scrollTop in jQuery

I need assistance with scrolling the #container div inside the .bloc_1_medias div. The height of #container is greater than that of .bloc_1_medias. My goal is to implement a function where clicking on the "next" and "previous" text will scroll the #contai ...