Using various alignment options for images on mobile devices

I've designed a theme with two columns, one for text and the other for images. I've structured it in HTML to display as:

  • Text - Img
  • Img - Text
  • Text - Img
  • Img - Text
  • Text - Img
  • Img - Text

However, for mobile responsiveness, I want it to display as:

  • Text - Img
  • Text - Img
  • Text - Img
  • Text - Img
  • Text - Img

This is my column code:

.one-half,
.three-sixths,
.two-fourths {
width: 48.4375%;
line-height: 1.2875;
}

Here's the HTML code:

<div class="one-half first"></div>
<div class="one-half"></div>

Is there a way to make this change only for mobile devices using HTML or CSS? If so, how can I achieve that?

Visit My Site

Answer №1

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
.one-half-first
{
float:left;
width:300px;
}
.one-half
{
float:left;
width:300px;
}
.clear
{
clear:both;
}
@media all and (max-width: 500px) and (min-width: 200px)
{
.one-half-first
{
float:left;
width:100px;
position:relative;
left:20px;
}
.one-half
{
float:left;
width:100px;
position:relative;
left:100px;
}
.one-half img
{
width:50px;
height:auto;
}
.clear
{
clear:both;
}

}
</style>
</head>

<body>

<div class="one-half-first">ihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdsc</div>
  <div class="one-half"><img src="file:///C|/tribhuvan/s2 dump/DCIM/sms/2012-08-14 10.29.41-1.jpg" width="300" height="200" /></div>
<div class="clear"></div>
<div class="one-half"><img src="file:///C|/tribhuvan/s2 dump/DCIM/sms/2012-08-14 10.29.41-1.jpg" width="300" height="200" /></div>
<div class="one-half-first">ihbibdsc ihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdsc</div>

<div class="clear"></div>
<div class="one-half-first">ihbibdsc ihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdscihbdbgrbgbdfvv vfv sfviuhisdv ksbihv ijbsiv ibisfv ibisv
monjonsv kbniksfv kinsviknv nionsiov iknbibsv nklnosv ibdsc</div>
  <div class="one-half"><img src="file:///C|/tribhuvan/s2 dump/DCIM/sms/2012-08-14 10.29.41-1.jpg" width="300" height="200" /></div>
<div class="clear"></div>
</body>
</html>

give this a shot as it should be helpful to you. If you encounter any other issues or if this code doesn't work with your setup, please reach out to me so I can offer alternative solutions tailored to your needs.

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

Is it possible to customize the placement of the login or register success message?

I would like to display a message indicating whether the login/register process was successful or not above my form. I am using Boostrap 3 along with some PHP functions. The message appears above my navbar but vanishes after 3 seconds, which is a bit anno ...

CSS-only Tooltip: text is getting truncated

I am experimenting with adding tooltips to my forum posts. Short tooltips work fine, but longer ones are causing issues by cutting off text. Changing the position property from relative to absolute fixes this problem, but causes the text to overlap. Here ...

The inline variables in CSS transitions are failing to be detected

The CSS transitions are not recognizing the inline variables, or if they are, they are not receiving the correct information. Below is an illustration of how the inline variables are defined in the HTML: <p class="hidden" style="--order ...

The responsiveness of Bootstrap 5 columns in Chrome inspection appears to break after reaching medium size, yet functions properly in other areas

I am currently working with cards within a grid system, but I am encountering an issue with resizing when the column size is smaller than medium in the mobile view inside the inspect section. The width does not expand to 100%, regardless of how much I try ...

css background is repeating after the height of the div is reset

I'm working on a project where I want to resize an image while maintaining its aspect ratio to fit the height/width of the browser window. However, every time the code for resizing is implemented, the div height continues to increase with each resize ...

CSS background images struggle to display properly in Safari, often not appearing even when checked in the debugger

I'm currently working on a website that I want to make responsive. I have set up a div ID that is supposed to appear once the width of a mobile device reaches a certain point. Here is the CSS code: #mobilenavbuttons1 { max-width: 750px; padding-top: ...

Achieving vertical alignment and stretching of subchild within a flexbox element

I am in the process of creating a mobile navigation menu using Flexbox. It will be a vertical menu that occupies 100% of the available height, with the navigation items evenly spaced and taking up the entire height. The structure I am using is ul>li> ...

Is there a way to insert and store a personalized field in the WordPress Gutenberg (block editor) dashboard?

https://i.stack.imgur.com/FZvts.png I'm currently working on my portfolio and am looking to include a gallery field. I couldn't figure out how to add a custom field in the screenshot provided. Does anyone have any insights on how this can be ach ...

Tips for creating fully stretched columns within Bootstrap framework

I have a simple code example available on codepen, but here is the markup for convenience: <div class="container my-container"> <div class="row m-row justify-content-between"> <div class="col-2 my-col">One of three columns</div& ...

Maximizing Content Width in FullCalendar v5 to Ensure Screen Compatibility

As I develop a calendar and timeline view using fullcalendar v5, my clients are requesting a month view that displays the entire month without any scroll bars. While I am aware of setting the contentHeight to auto, there seems to be no option for adjusting ...

React- hiding div with hover effect not functioning as expected

I'm having trouble using the :hover feature in CSS to control the display of one div when hovering over another, it's not functioning as expected. I've successfully implemented this on other elements, but can't seem to get it right in t ...

Creating a stylish CSS shadow effect for a collection of elements

In my Ionic2 project, I have an <ion-list> consisting of various items. Currently, these items are plain, but I desire to add some styling such that each item in the list displays a subtle shadow effect, similar to the one shown in the first image of ...

Show me how to customize the default confirmation box using just CSS!

Is it possible to style the standard window.confirm using only CSS without any additional JavaScript code? If so, how can this be achieved? ...

Tips for modifying the text color of radio button choices in HTML and CSS

I have set a black background image for my HTML page. How can I change the radio button labels/texts to white, similar to the questions? This is the code snippet that shows how it currently looks on the page: View Image <hr&g ...

Transforming hover interactions into onclick events involves adjusting the CSS and JavaScript

Is there a way to convert this hover menu into an onclick menu? <div id='cssmenu'> <ul> <li class='has-sub'><a href='#'><span>Users</span></a> <ul> ...

Styles created using makeStyles in MUI are no longer working properly following an update to both MUI and React versions

Implementing the MUI Dropdown in a components library. When testing the library in Storybook, everything functions properly. However, when integrating the component into a separate React project, the layout becomes distorted. The Dropdown label is posit ...

Tips for customizing the border radius style of the menu in Vuetify's v-autocomplete component

I am looking to customize the appearance of the drop-down list in the v-autocomplete component by adding a border-radius style, as depicted in the image below. The current design I have achieved closely resembles the visual shown below. Previously, I app ...

CSS positioning with absolute value + determine the number of elements positioned above

Is it feasible to adjust the position of an absolutely positioned element based on the height of the element above it? The objective is to align elements with the class "pgafu-post-categories" one line above an H2 heading, even when the lengths v ...

What are some effective ways to analyze jQuery and JavaScript using web development tools?

I'm struggling to use web development tools to inspect the JavaScript on websites. It's challenging to identify which parts of a site are utilizing JS, unlike CSS or HTML where it's more visibly defined. Even when I attempt to delete some J ...

Is it possible to move between textboxes using arrow keys in HTML?

Is there a way to navigate through textboxes using arrow keys in HTML without relying on jQuery? Possibly utilizing JavaScript, HTML, CSS, or another method? Thank you for your help! <body> <form> <input type="text"&g ...