Reorganize HTML elements for improved responsiveness on various devices

Looking for a CSS-only solution to move an element under specific conditions based on width breakpoints.

Breakpoints are already defined in the stylesheets for mobile styling, but need the icon to display below content at certain widths.

The page displays a repeating list of items with number, text, and icon that switch positions. Must remain responsive without using float due to varying content lengths.

Desktop view example can be seen here: JS Fiddle. Handles long text well while keeping the layout fluid.

For mobile, the icon should extend full width and appear below the text.

Current issue is the icon switching position between repeated items when resized.

Is there a way to use CSS3 to relocate the icon within each item specifically for mobile?

Mobile preview of the current setup can be viewed here. The goal is to have the icon consistently below the text without fixed dimensions.

Some numbers correctly display the icon below the text, while others do not.

Any suggestions or solutions would be appreciated. Thank you!

Answer №1

To accomplish this task, utilize the power of flexbox along with the flex-flow and order attributes to alter orientation and arrangement of elements.

Answer №2

To optimize display for narrow devices, use the following CSS:

http://codepen.io/cimmanon/pen/BJleF

.view-reasons .views-reasons-row {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-orient: vertical;
  -moz-box-orient: vertical;
  -webkit-box-direction: normal;
  -moz-box-direction: normal;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

.view-reasons .views-field-field-icon {
  -webkit-box-ordinal-group: 2;
  -moz-box-ordinal-group: 2;
  -ms-flex-order: 1;
  -webkit-order: 1;
  order: 1;
}

Make sure to enclose them within the necessary media query. This code is compatible with Opera, Chrome, IE10, Firefox, and most mobile browsers except Opera Mini (see: http://caniuse.com/#feat=flexbox).

Answer №3

I have recreated your fiddle HERE

You will find 6 rows, all of which are working in the same manner.

The first 2 rows are based on your original example.

For the remaining 4 rows, I have switched your original class to "row" while maintaining the same order. The styling applied to make the even rows appear differently is:

The key technique involves using absolute positioning for the image and aligning it to the right. (The majority of the rest of the code belongs to you)

.row {
    border-bottom:1px dotted #464637;
    padding-bottom:15px;
    margin-bottom:15px;
    min-height: 150px;
}

.row .views-field-field-icon{
    display:inline-block;
    width:41%;
    margin-right: 0;
}

.row:nth-child(even) .views-field-field-icon{
    position: absolute;
    right: 0px;
    padding-right: 6%;
}

Answer №4

Another option is to utilize the css3 :nth-of-type selector, as recommended in vals' previous response,

Check out this demonstration

(I have modified the class names, but you can still reference it, I believe)

You can also experiment with resizing the browser window to observe the effects of media queries.

Answer №5

If you don't have a script handy, you won't be able to "reorder HTML blocks," but with some clever CSS tricks, you can create the illusion of doing so.

Check out my personal website nicksaemenes.com (still a work in progress), to see if it achieves what you're trying to do — I believe it does. You can access all the source code for it on Githubhttps://github.com/nicksaemenes/nicksaemenes.github.io.

You might want to investigate why your HTML is switching the order of icons/images and paragraphs. In this case, consistency in the source order could be a better approach.

Although not as refined as my live website, this Codepen project demonstrates the early stages of developing my site, which might provide a clearer insight into achieving what appears to be your goal.

...

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

Creating a reusable component in Angular with a shared selector

Is it possible to create reusable HTML elements within a component and then call them separately in another component? If so, what would be the best solution to achieve this? Please share your guidance. The code I have written: I am looking to individual ...

How to Toggle the Submit Button Using jQuery

I have implemented a feature using jQuery to disable the submit button and display a loading image. Here is how I have set it up: The HTML structure for the submit button looks like this: <div id="registerbtn" name="registerbtn"> <input typ ...

Is there a way I can replicate this expandable div?

I have successfully implemented a script that expands and collapses. However, I am facing an issue when trying to use two of these scripts on the same page. I attempted to simply add "_two" to all instances of "accordion," but it doesn't seem to be f ...

Dynamic change of table cell text color based on condition utilizing ng-if and ng-style

I am looking to create a table cell with alternating color combinations based on specific conditions. Here is the code snippet: <tr ng-repeat="x in data"> <td> <span ng-if="((x.time2 < x.time1) || (x.time2 < x.time3))" ng-style="colo ...

I'm having trouble displaying my background image unless I specifically set the height in pixels or viewport height

I have been working with ReactJS and on my main page container, I am setting a background image like this: .opening-container { background-image: url("../../images/sadaqashdbg.png"); background-position: center; background-size: cover; ba ...

My goal is to create text that is opaque against a backdrop of transparency

Is it feasible using CSS to create text with a transparent background while keeping the text opaque? I attempted the following method: p { position: absolute; background-color: blue; filter: alpha(opacity=60); opacity: 0.6; } span { color: b ...

Issues with Bootstrap offsetting columns within a fluid row

I am currently working on a fluid design layout, where I need to place form group elements inside the row-fluid with one specific condition - they must be aligned to the right side. <div class="row-fluid" style="background-color: #332619; color: #fff ! ...

Enhancing the style of the top menu Index by applying a border-bottom effect when hovering over it in a CSS Horizontal Drop Down Menu

I'm having trouble adding a border-bottom: 1px solid #FFF to all the top menu (index) items when they are hovered over. Can anyone help me with this? #menu{ padding:0; margin:0; position: fixed; top: 30px; left: 0px; font-size ...

Clicking on the ajax tab control in asp.net displays a single rectangular box - how can this be removed?

When using tab control in Ajax, I encountered an issue where a blue rectangle box appeared when clicking or opening the page. How can I remove this unwanted box? ...

Guide to changing the border color in a Material-UI TextField component styled with an outline design

To complete the task, utilize the Material UI outlined input field (TextField component from "@material-ui/core": "^4.12.2",) and apply a custom blue color style to it. Here is the outcome of my work: https://i.sstatic.net/lw1vC.png C ...

Attempting to eliminate the padding from the unordered list (ul) element within the pop-up box

Upon clicking the chip with chipName="button test IPA", a popup window appears. I am attempting to remove the padding from the ul tag within that popup. The issue I'm facing is that I cannot locate the ul tag in my HTML or JSX code. I have assigned a ...

Create a single button that controls checkboxes with the help of HTML, CSS, SCSS, and Bootstrap 4

Is there a way to use only HTML, CSS, SCSS, and Bootstrap 4 to make all checkboxes default to the "on" condition when a button is clicked? Typically, this functionality would be achieved with JavaScript, but due to constraints, I am exploring alternative ...

Exploring the process of customizing native classes with Vue.js

Within vue-awesome-swiper, there's a standard class called this: .swiper-button-next { position: absolute; right: 46% } The task at hand is to adjust this CSS code only for right-to-left layouts, like so: .swiper-button-next { position: abso ...

Styling pagination in Angular 8 PrimeNG p-table

I'm having an issue with PrimeNG where my paginated table is displaying without proper styling. I want it to look like the one in this stackblitz example. I believe I have installed all the necessary packages and configured the styles paths in the ang ...

How to create a clickable link in a menu using kotlin

I am currently working on creating a Bottom navigation bar and I have encountered a few issues with my code. val bottomNavigation = findViewById<View>(R.id.bottom_navigation) as BottomNavigationView bottomNavigation.setOnNavigationItemSelecte ...

Troubleshooting a Hover Problem in Firefox

Chrome is rendering the following code perfectly fine, but Firefox seems to be having trouble applying the hover effect. HTML <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="stylesheet.css"/> ...

Is it possible to apply SlideToggle() to Div elements that have their Display property set to Table-Cell?

I am facing an issue on my web page where I have a series of div elements styled with display: table and their child div elements styled with display: table-cell. I am looking to use slideToggle() on a specific cell to change its content. However, I have c ...

What is the best way to eliminate the horizontal line in the modal's body and footer?

How can I eliminate the horizontal lines from my modal? $(document).ready(function(){ $('#myModal').modal('show'); }); <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity= ...

Having trouble interacting with buttons while an overlay is open

When I try to use the overlay to move the text upwards and reveal buttons, I encounter an issue where I am unable to hover or click on those buttons. As soon as I try to interact with the buttons, the overlay and text come down, blocking my access. I have ...

Changing the width of an SVG path from 0 to 100% using CSS

I have an SVG design of wires that I want to animate the width from "0 to 100%", but I'm having trouble achieving this effect. It's easy to do with a div element, but not with an SVG image. Below is my code snippet: svg path { animation: f ...