What is the best way to manage the ordering of float elements?

Check out my code snippet below:

.wrapper {
    border: 1px solid red;
    padding-left: 20px;
}

.table {
  display: table;
  width: 100%;
}

.table > div {
  display: table-cell;
  border: 1px solid green;
  min-width: 190px;
}

@media screen and (max-width: 600px) {
  .table > div {
  float:left;
}
  .author, .editor{
     clear: both;
  }
}
<div class="wrapper">    

<div class="table">
  <div class="share_edit_flag">
    <span>share</span>
    <span>edit</span>
    <span>close</span>
  </div>

  <div class="editor">
    <a href="#">edited May 21 16 at 11:58</a>
    <div class="profile">
      <img src="#" />
      <a href="#">Rory O'Kane</a>
      <b>12.6k</b>
      <!-- I don't have any badge in my website -->
    </div>
  </div>

  <div class="author">
    <a href="#">asked May 21 16 at 11:51</a>
    <div class="profile">
      <img src="#" />
      <a href="#">vasanthkumarmani</a>
      <b>1</b>
      <!-- I don't have any badge in my website -->
    </div>
  </div>
</div>

</div>

Try resizing the screen after running the above snippet as full size. Notice how the author and editor boxes drop down under each other when the screen is reduced. Now, I want to change the order so that the author box appears above the editor box instead. Can you help me achieve this rearrangement?

Please note: I would like to maintain the current order when the screen is full-size (with the author box appearing on the rightmost side).

Answer №1

If you're looking to update your layout, consider using flexbox instead of relying on floats. Flexbox offers more flexibility and control over the order of elements with features like the order property. Here's an example of how you can easily implement this:

.container {
    border: 1px solid blue;
    padding-left: 20px;
}

.grid {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.grid > div {
  border: 1px solid purple;
  min-width: 190px;
}

@media screen and (max-width: 600px) {
  .designer {
      order: 1;
  }
  
  .developer {
    order: 2;
  }
}
<div class="container">    

<div class="grid">
  <div class="share_feature_flag">
    <span>share</span>
    <span>feature</span>
    <span>flag</span>
  </div>

  <div class="developer">
    <a href="#">developed on May 21 16 at 11:58</a>
    <div class="profile">
      <img src="#" />
      <a href="#">Eva Smith</a>
      <b>8.9k</b>
      <!-- No badges featured yet -->
    </div>
  </div>

  <div class="designer">
    <a href="#">designed on May 21 16 at 11:51</a>
    <div class="profile">
      <img src="#" />
      <a href="#">John Doe</a>
      <b>3</b>
      <!-- No badges available -->
    </div>
  </div>
</div>

</div>

Answer №2

You have the ability to adjust the order using flexbox.

.wrapper {
  border: 1px solid red;
  padding-left: 20px;
}

.table {
  display: table;
  width: 100%;
}

.table > div {
  display: table-cell;
  border: 1px solid green;
  min-width: 190px;
}

@media screen and (max-width: 600px) {
  .table {
    display: flex;
    flex-direction: column;
  }
  .author {
    order: -1;
  }
}
<div class="wrapper">

  <div class="table">
    <div class="share_edit_flag">
      <span>share</span>
      <span>edit</span>
      <span>close</span>
    </div>

    <div class="editor">
      <a href="#">edited May 21 16 at 11:58</a>
      <div class="profile">
        <img src="#" />
        <a href="#">Rory O'Kane</a>
        <b>12.6k</b>
        <!-- I don't have any badge in my website -->
      </div>
    </div>

    <div class="author">
      <a href="#">asked May 21 16 at 11:51</a>
      <div class="profile">
        <img src="#" />
        <a href="#">vasanthkumarmani</a>
        <b>1</b>
        <!-- I don't have any badge in my website -->
      </div>
    </div>
  </div>

</div>

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 there a way to automatically distribute a discount coupon if it is present in the URL?

My discount coupon system is fully operational and functions flawlessly. The information is sent via Ajax from the form below. <div class="form-group relative"> <div class="response"> <div class="success&q ...

What steps can be taken to avoid the duplication of color and stock values when including additional sizes?

Individual users have the ability to include additional text fields for size, color, and stocks. When adding more sizes, the data inputted for colors and stock will duplicate from the initial entry. Desired output: 1st Size : small color: red, stocks: 10 ...

Access the value of a field inside nested objects (Parent-child) by using underscore.js

const paths = [ { path: 'RS', hasChild :true }, { path: 'MO', hasChild: true }, { path: 'EL', hasChild: true }, { path: 'CL', ...

Trouble with scrolling horizontally on the website

After completing the coding for this website with bootstrap, I encountered an unexpected issue with a horizontal scroll appearing. This is my first project using bootstrap. I attempted to troubleshoot by using the 'divide et impera' method - rem ...

Unable to cancel $interval within factory

I created a factory for long-polling, complete with start and stop methods. However, I am struggling to cancel the timer. Any suggestions or ideas? app.controller("AuthCtrl", function($scope, $http, $window, User, Poller) { Poller.start(1, $scope.sess ...

The functionality of Vue slot-scope seems to be restricted when used within nested child components

Here is the component configuration being discussed: Vue.component('myComponent', { data () { return { msg: 'Hello', } }, template: ` <div class="my-component"> <slot :ms ...

The Ajax success or error message is only shown one time

I have successfully created a form using php, ajax, and JavaScript. By implementing ajax, I am able to display error/success messages without redirecting the user to another page. Everything works as expected when I use console.log to showcase these mess ...

Ways to Adjust the Earth's Position in WebGL Earth

I have been working with this WebGL Earth component for my project, but I am facing difficulty in adjusting the position of the planet on the canvas. My intention was to place the planet at the bottom of the page, but I haven't been able to achieve th ...

Firebase Functions + monorepo: Deployment fails and dependencies are missing in local installation

It seems like a similar issue has been raised here: https://github.com/firebase/firebase-functions/issues/1050 Challenge I recently restructured my project into a monorepo with the following layout: / | | - node_modules/ | | - packages/ | - - app/ | - - ...

An alternative option for the location parameter in the post

$.post("location_example.php",{data:data},function(){ //performing some action }); I attempted to specify the full location path as "localhost:8888/myweb/data/index.php", but it does not seem to be posting anything. It appears that the parameter cannot ...

Comparison of Web Development Techniques: localStorage versus Cached HTTP

Imagine a scenario where there is a web server responding to a GET request by sending a .json file. The response instructs the browser to cache it for a period of 5 years. Furthermore, picture a webpage that initiates this GET request for the JSON data du ...

The Soundcloud ajax response failed to be delivered

I'm attempting to retrieve user data from SoundCloud using this query. Although I can see the successful call in the Chrome network tab after clicking, the JSON response is not reaching the javascript alert as expected. This is preventing me from addi ...

Transferring reference from a parent component to a child component

One of my components is called ChatScroller, which manages scrolling in a chat by autoscrolling when new messages come in. Here's a simplified version of it: class ChatScroller extends Component { scrollRef = node => this.scrollNode = node c ...

Using a loop to iterate through an object within a table cell and generate an unordered list

One of my tables contains a column where cells may or may not have values, with those values being in JSON format when they exist. Otherwise, the cells are empty (null). <table> <tbody> <tr> <td>Barley</td> <td>AK, ...

Implementing custom object property filtering in Angular typeahead

I'm currently working on integrating a versatile typeahead directive. This directive requires a list of options and a configuration object as attributes. Within the configuration object, there is a property called "label" which dictates what the user ...

Exploring the basics of Three.js: a step-by-step guide using a shadertoy example on transforming patterns with objects

Check out this snippet, inspired by the second live example found at : html, body { height: 100%; margin: 0; } #c { width: 100%; height: 100%; display: block; } <canvas id="c"></canvas> <script type="module"> // Three.j ...

When utilizing bootstrap, encasing an input text element in a label results in the text becoming bold and not occupying the entire width

I have been experimenting with wrapping my text input fields in labels. While this technique works well with pickers on my form, it seems to cause issues when applied to text boxes. If I choose not to wrap the text boxes, the alignment between the label an ...

The Jquery UI autocomplete feature seems to be malfunctioning when attempting to search for names based

Utilizing autocomplete feature to search for a name and retrieve its corresponding ID. The functionality is working fine, but upon selecting a name, the ID is displayed while the name field gets replaced by the ID. Jquery: <script type="text/javascrip ...

Steps for displaying a division on clicking a hyperlink

I am currently working on my main menu layout in HTML, and here is the code snippet: <div id="main-container"> <div id="main-wrapper"> <div id="logo"> <h1 id="title">port ...

react-router is unable to navigate to the desired page

I am currently using react-router-dom in my project, but I am still relatively new to it. I have encountered an issue regarding page navigation. Below is the code for my App.js: class App extends Component { render() { return ( <div classN ...