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

Adjust the dimensions of the canvas without disrupting the existing artwork

I am currently working on a pixel art application where I am facing an issue with saving images from the canvas. The saved image appears small and pixelated when I try to resize it. I would like to resize the image to larger dimensions, but I am unsure of ...

Express-minify is having trouble loading the CSS file. If we remove a portion of the file, it should be able

After implementing the express-minify middleware, I encountered an issue with loading the attached CSS file. Even after validating the CSS using an online service, no errors were detected. I attempted to debug by gradually removing elements, and the prob ...

Design a circular progress bar with a cut-off at the bottom

Does anyone have suggestions on how to create a circular progress bar with cropping at the bottom, similar to this example: PROGRESS BAR? I've been searching for a component like this but haven't had any luck. Any ideas, especially utilizing Mate ...

Update the class name of an element depending on the URL

Hey there! I'm working on customizing the style of some elements (specifically tds within a table) based on the current URL. Here are the pages I'm targeting: http:\\domain\site\welcome.html http:\\domain\site& ...

Implementing a Vue.js v-bind:style attribute onto a dynamically generated element post-page initialization

Let me start by explaining my current issue and dilemma: I have been tasked with converting an existing JS project into a Vue.js framework. While I could easily solve a particular problem using jQuery, it seems to be posing quite a challenge when it comes ...

Using PHP to utilize logical OR or AND operators when adding a class to the global navigation's list items

I am currently working on implementing a global navigation bar using PHP on all pages. The PHP code is also being used to add a class and display the current page. The main challenge I am encountering involves selecting the parent navigation item. When on ...

Embedding SVG or image code within the </style> tags is a common practice in web development

Can anyone assist me in placing this code within </style>? I am unsure of how to proceed with this. I believe the best approach would be to start by moving most of it into </style>, and then I can decide what should remain there. I would grea ...

When a <dl> element is nested within an <ol>, it will be rendered as a list format

I'm facing an issue with my CSS that affects how different browsers render definition lists embedded within ordered lists. In IE10, the list displays as expected - a bulleted list inside the ordered list without affecting the numbering. However, Firef ...

Using jQuery to animate one widget with the login widget

EDITED : I have decided to switch from jQuery to PHP for my WordPress sidebar issue. Please refer to this link for more details: Add echo to my wordpress sidebar for non-connected users I am using the Nice Login Widget plugin on my test WordPress website. ...

Eliminate jQuery's delayed blinking effect with the use of an event

Utilizing the mouseenter and mouseleave events, I have implemented a functionality to add a button (not actually a button) to an <li>. However, there seems to be a problem with my code. The button appears and disappears on mouseleave and mouseenter, ...

Setting up Stylelint in a Next.js project: A step-by-step guide

I'm looking to incorporate Stylelint into my Next.js app. Can I modify the next.config.js file to include the stylelint-webpack-plugin, in order to receive style errors during compilation? // next.config.js module.exports = { reactStrictMode: true, ...

Placing a gradient background in front of two divs

I have created two divs with gradients: .container_middle_page{ margin: auto; height: 100%; display: flex; flex-direction: column; } .container_middle_page_up{ background-image: linear-gradient(to top, #F28118,white); height: ...

Is there a way to align these buttons in the middle?

I am currently designing a webpage at The challenge I'm facing is: How can I center those buttons on the page? They need to remain centered and responsive even when the page is resized. Additionally, the spacing between the buttons is inconsistent. ...

What is the process for locating and displaying a database in WordPress?

I seem to be facing a challenge when it comes to developing a new functionality since I am relatively new to both WordPress and web development. My current goal is to incorporate a search feature into my project. The idea is that when a user enters a sea ...

CSS for a navigation menu with underlined links

I am attempting to create an underline effect when hovering over a link. However, I am facing an issue where the underline does not align perfectly with the line below it. Can someone please guide me on how to modify this CSS so that when the link is hov ...

Tips for defining conditions within the style attribute in JSP

Below is the code that I attempted: <div style="width:85%;"> <input class="formbutt" value="AddNew" title="AddNew" type="button" style="{(${projectEnvironmentBean.divStyle}=='dipslay:none') ? 'display:block' :'display: ...

The nested table is overflowing beyond the boundaries of its outer parent table

I have created a nested table, shown below: <table border="0" width="750" cellspacing="0" cellpadding="0"> <tr align="center"> <td width="530"> <table border="0" cellspacing="0" cellpadding="0" width="530"> <tr&g ...

What is the best way to choose a specific div within a container that contains additional HTML elements?

I am facing an issue with selecting the second div tag within a section that contains 2 divs and an img tag. I attempted to use section div:nth-child(2), but it is targeting the second element inside the first div. However, my goal is to select the secon ...

How can I create two left-aligned columns in CSS, with the first column being fixed in place?

Is there a way to create two columns without using HTML tables? I'm looking for the first column to contain an image and the second column to display text aligned left, extending to the rest of the page width. I found this CSS solution for the first ...

Adjust the parent container to match the height of the child container when it is being hovered

I have been searching for a solution to this issue, but none of the answers I found seem to work in my specific case. Currently, I have a "Mega Menu" with links on the left side that expand when hovered over, revealing hidden links with images on the righ ...