Rearrange the sequence of specific child elements within the Div

Is there a way to reverse the order of specific div's children elements using just CSS?

For instance:

I need

<div id="parent">
    <a>A</a>
    <a>B</a>
    <a>C</a>
    <a>D</a>
    <div id="sub-child">
        <a>X</a>
        <a>Y</a>
        <a>Z</a>
   </div>
</div>

to appear like this:

D

C

B

A

X

Y

Z

I attempted:

#parent {
    display:flex;
    flex-direction: column-reverse; 
}

However, all contents within parent were reversed (Not achieving the desired outcome)

Answer №1

  • apply the CSS property display: flex to both elements with IDs #parent and #sub-child;
  • set flex-direction: column-reverse for #parent and flex-direction: column for #sub-child;
  • use a negative value for the order property on #sub-child to ensure it stays at the bottom.

#parent {
 display: flex;
 flex-direction: column-reverse;
}

#sub-child {
  order: -1;
  display: flex;
  flex-direction: column;
}
<div id="parent">
    <a>A</a>
    <a>B</a>
    <a>C</a>
    <a>D</a>
    <div id="sub-child">
      <a>X</a>
      <a>Y</a>
      <a>Z</a>
    </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

What is the process for indicating a specific spot on Google Maps?

Hello, I am a new programmer trying to indicate the location of my company. The map pointer is not showing up even though the location is correct. I have tried numerous solutions but none seem to be working. Any assistance would be gre ...

CSS ratings bar styling

Looking to create a unique ratings bar for my website, I have some questions that need answering. Take a look at the codepen link to see what I've come up with so far. My main query is about incorporating two different colors for Likes (green) and Di ...

Guidance on editing list items individually using jQuery from separate input fields

Working with li presents some challenges for me. On my webpage, I have an input field that dynamically adds values to a list. However, the function to edit these values is not working properly. After editing an li element, it deletes all classes and span ...

Ensure that the width does not decrease

Edited: included fiddle and code snippets I am facing an issue with the width of columns in my layout. The width of the columns is dynamically calculated based on the content they hold. However, when I filter the results using a search input for a specifi ...

Guide to implementing the offcanvas sidebar with bookmarks using Bootstrap

On my website, I have implemented a convenient offcanvas sidebar using Bootstrap 5. This sidebar contains html bookmark links that allow users to quickly navigate to specific points on the page by clicking on them. Here is an abbreviated version of the cod ...

Tips for eliminating null elements from an array with the help of jquery

Similar Question: How to delete empty values from an array using JavaScript? I'm looking for a way to eliminate null or empty elements from an array with the use of jquery var clientName= new Array(); clientName[0] = "jack"; clientName[1] = ""; ...

Show JSON data as choices in a dropdown menu

On my webpage, I want to display a dropdown list populated with objects from a JSON file using JavaScript. Here is the structure of my HTML and JSON: HTML <html> <body> <select id="myid">MyList</select> <script src="m ...

What is the best way to incorporate keyboard shortcuts into carousel operations using jQuery?

The example can be found here. I want to be able to navigate through the images using the left and right arrows on my keyboard. How can I achieve this using jQuery or CSS? This is the structure of the HTML: <div id="slider-code"> <a cla ...

JavaScript class name modifications are not functioning as expected

Testing a sprite sheet on a small web page I created. The code for each sprite in sprites.css is structured like this... .a320_0 { top: 0px; left: 0px; width: 60px; height: 64px; background: url("images/sprites.png") no-repeat -787 ...

Using Jquery to adjust the width of table cells within a div container

Is there a way to use JQuery to access the first table's td in this HTML code and change the width to 40% and 60% respectively? <div id="DeltaPlaceHolderMain"> <a id="mainContent" tabindex="-1" name="mainContent"></a> ...

Utilize Laravel to send a string using Ajax with the post method

Here is an example of jQuery code: field1="11111",field2="2222",field3="3333" $.ajax({ url:"getdata" , data:{'field1' : field1 , 'field2':field2 , 'field3':field3 }, processData: false, type:&a ...

MacOS web browsers adjust content to fit the screen size

As I delve into React development, one thing that has caught my attention is how MacOS browsers try to fit all the page content in view rather than allowing users to scroll. Let me illustrate this with an example: function Example() { const Elements = ...

The CSS within the WebComponent nesting is not valid

Upon testing, I have found that writing CSS directly using nesting is effective. However, when used within a WebComponent and nested with the :host selector, it becomes invalid. Below is a demo code snippet showcasing this issue. My Chrome version number i ...

Combining multiple images into one CSS image sprite to create 4 clickable

Could someone please review this segment of the CSS to ensure its accuracy? CSS #nav-list { list-style-type: none; background-repeat: no-repeat; background-image:url("../_img/Footersprite.png") } #nav-list li, #nav-footer a { height: 40 ...

Learn how to launch a new webpage using jQuery Colorbox plugin

I am experiencing an issue with jQuery colorbox on my website. Instead of opening web pages in a dialog, they are opening as regular links. Despite searching for demos, I have not found any that work correctly. Below is the code I am using: <asp:GridV ...

Stop flex items from expanding larger than their sibling elements

Is there a way to prevent a flex item from growing bigger than its siblings? Check out the example on CodeSandbox: LINK Here is the sample code: <div class='wrapper'> <div class='box one'></div> <div class ...

Retrieve the values of the recently selected options in a multiple selection

I am trying to retrieve the last or most recently selected option value from a dropdown menu. In my Django code, I have attempted the following: <script type="text/javascript> django.jQuery(document).ready(function(){ django ...

Tips for adjusting the size of icons in Ionic Framework v4 and Angular 7

The library ngx-skycons offers a variety of icons for use in projects. If you're interested, check out the demo here. I'm currently incorporating this icon library into an Ionic project that utilizes Angular. While the icons work perfectly, I&ap ...

How to eliminate certain elements from the DOM in Angular 5

I'm facing a minor issue in my Angular/Typescript project that I can't seem to resolve. I am still new to these technologies and struggling with removing certain DOM elements. The content is auto-generated with specific CSS classes, and unfortuna ...

Balancing heights with jQuery

Is there a way to set the height of an h3 element based on the tallest version of its siblings, but only for certain elements? I have a list where CSS organizes items into rows of 3. The last li element in each row has the class "endRow". I want to find t ...