Position a div adjacent to a nested child div

Here's a question that came to my mind:

The code I am using is as follows:

'''

<div class="container"> 
      <div class="child_1"> 
      </div> 
      <div class="child_2"> 
      </div> 
 </div> 

 <div class="another_div"> 
 </div> 

'''

Is there a way to position 'another_div' beside 'child_2'?

https://i.sstatic.net/Lhikn.png

Answer №1

To ensure proper alignment, wrap all content within a new <div> and assign it a class of main-container.

Next, set the display property of the main container to flex:

display: flex;

In order to add another <div> to the left of elements within the <div> with class container, change the flex-direction to row-reverse:

flex-direction: row-reverse;

The entire main container will align to the right. Since it is in reverse, the justify-content should be set to flex-end:

justify-content: flex-end;

The another_div appears at the bottom instead of the top, indicating that items are vertically aligned to the bottom. To achieve this, align-items should be set to flex-end:

align-items: flex-end;

.main-container {
  display: flex;
  flex-direction: row-reverse;
  justify-content: flex-end;
  align-items: flex-end;
}

Check out the code on Codepen: https://codepen.io/geekyquentin/pen/wvyJOBX

Answer №2

.item_1,
.item_2,
.additional_div {
  width: 120px;
  height: 120px;
}

.item_1,
.item_2 {
  border: 1px solid blue;
}

.additional_div {
  border: 1px solid green;
  order: 2;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}
<div class="wrapper">
  <div class="item_1"> </div>
  <div class="item_2"> </div>
</div>

<div class="additional_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

Divs Stacked and Centered

I am currently utilizing the card components from Google's Material Design Lite HTML theme, which can be found at . At the moment, my cards are positioned next to each other and aligned to the left side of the page. I am looking to center the cards o ...

Setting a static width for a specific cell in HTML5 - What's the best way to go about it?

When working with HTML5, how do I define a specific width for a table cell? Many of the <col> properties that were present in HTML4 are no longer applicable in HTML5. Just to clarify, I am aware that I can use <td style="width:150px">, but thi ...

Why isn't the right-clear property functioning correctly?

My understanding of `clear: left`, `clear: right`, and `clear: both` in CSS has always been a bit fuzzy. I know that `clear: both` means it prevents floating elements from appearing on both sides, but I recently did some testing here. I expected the layout ...

Incorporating a YouTube video

Having trouble integrating a YouTube video that won't play automatically on your website? The video is visible, but just doesn't start playing on its own. What could be causing this issue? Appreciate any help you can provide! ...

Proper method for positioning text in a line

Trying to recreate the image below, but facing alignment issues with the text in my code. How can I vertically align the text so that they are aligned like in the photo? Flexbox hasn't helped due to varying text lengths causing misalignment. const ...

Tips for removing a previous file from an 'input type' in HTML5 FileReader

Here is a file input with an associated function: <img id="uploadPreview"> <div id="changeImage">Change</div> <div id="customImage"> <input type="file" id="myfile" multiple style="display:none" onchange="PreviewImage();" / ...

Tips for choosing a frequently utilized CSS class inside a specific div element

How can I target the .formlabel class within formblock2 in my CSS code to change the color of Heading B to green instead of red? .formblock2 .formlabel {color:green;} <div class="form"> <div class="formblock1> <div class="formlabel"> ...

Learn how to evenly divide a circle based on the number of elements in an array using React, JavaScript, HTML, and CSS

Attempting to design a Polar/Radar Chart, my goal is to create distinct sections within the first circle based on the number of array items. Each item.name should be displayed in its own section with consistent text styling along the arc. The dimensions of ...

Achieving Distinct Values in an Observable Array Property - Angular

I have created an Angular application that utilizes a service to retrieve data from a mock API. The data returned is in the form of an array containing objects, as shown below: [ { "userId": 1, "id": 1, "title": "quidem molestiae enim" }, ...

Struggling to get the video in the background to function properly with the controls

My website is built on Wordpress and includes the Easywpvideo plugin, which unfortunately doesn't have any support available. We are looking to have a video playing in the background, with the ability for users to stop and start it as they please. I ...

What is the method for transferring the chosen value from a select element into a textarea?

I am currently working on a feature to allow users to select a color of a shirt from a dropdown menu and have it added to a textarea when they click a button. If anyone has advice on how to achieve the same functionality with a group of radio buttons, it ...

The text emits a soft glow even without the cursor hovering over it

I need some assistance with my code that creates a glowing effect on text. Currently, the glow effect appears not only when the cursor hovers directly over the text but also when it hovers over the area around the text. Can someone explain why this is ha ...

Styling a modal popup using session storage in CSS

I recently created a modal popup using CSS by following a helpful tutorial that can be found at this link: Now, I am curious about how to store the value entered in a textbox as session data. I came across some code in another tutorial that demonstrated h ...

Ways to ensure that floating blocks remain in the same row using CSS

Check out my demo here: http://jsfiddle.net/3c40tafe/1/ Is there a way to align the icon, file name, and description in a single row? The icon and title should have fixed widths, while the description paragraph should take up the remaining width. Here&ap ...

Selenium: Utilizing the get_attribute() function with a CSS query

I am attempting to retrieve the value of the title attribute. There are multiple links on the page and I need to specifically select the first link and extract its title attribute. Here is the selenium command that I have used: self.se.get_attribute("c ...

Is there a way to retrieve php session in a javascript file?

Here's the code snippet for reference: Contents of index.php file Javascript code from index.php function Result() { var marks = 55; document.getElementById("hdnmarks").innerHTML= marks; window.location = "results.php"; } HTML code from ind ...

Inventory displayed beneath other listings containing images

I am currently working on designing a basic navigation bar with five list items, each set at 20% width. The structure includes two text items, followed by an image logo in the center, and then another two text items. However, I am facing an issue where wh ...

Ways to verify if a web URL is contained within an HTML textbox

In the process of developing a frontend form for WordPress, I have incorporated a basic HTML textbox for users to input a web URL. My goal now is to ensure that the entered value is indeed a valid URL and not just arbitrary text. Is there a way to perfor ...

Photo showing up in an unexpected location

I am looking to add a small image before each line on my list. Here is the CSS code: .left div.arrow{background-image: url(../images/design/box.png); float:left; height:15px; width:15px; margin-right:2px;} .left a.list:link, a:visited, a:active {color:b ...

Text is not visible when hovering over it

I am facing an issue with the hover effect on my menu element. When I hover over the element, the text does not appear as expected. Even after using z-index to position the text on top, it still doesn't work. Here is a snippet of my code: HTML: < ...