What's the best way to include a div on the right side of my adaptable divs?

I need the "div 1" label to always appear on the right side of the divs, while still maintaining responsiveness. Is there a way to achieve this effectively?

Struggling to find a wrapper that meets my responsiveness requirements.

#wrapper {
  width: auto;
  clear: both;
}
#second {
  background-color: blue;
  width: auto;
  float: left;
}
.items {
  display: flex;
  flex-wrap: wrap;
  margin-left: -10px;
  margin-top: -10px;
}
.items .item {
  flex: 1 0 200px;
  box-sizing: border-box;
  background: #e0ddd5;
  color: #171e42;
  padding: 10px;
  margin-left: 10px;
  margin-top: 10px;
  width: auto;
  float: left;
}
@media (min-width: 410px) {
  .items .item {
    max-width: calc(50% - 10px);
  }
}
@media (min-width: 620px) {
  .items .item {
    max-width: calc(33.33333% - 10px);
  }
}
@media (min-width: 830px) {
  .items .item {
    max-width: calc(25% - 10px);
  }
}
@media (min-width: 1040px) {
  .items .item {
    max-width: calc(20% - 10px);
  }
}
@media (min-width: 1250px) {
  .items .item {
    max-width: calc(16.66667% - 10px);
  }
}
@media (min-width: 1460px) {
  .items .item {
    max-width: calc(14.28571% - 10px);
  }
}
@media (min-width: 1670px) {
  .items .item {
    min-width: calc(12.5% - 10px);
  }
}
<body>

  <div id="wrapper">

    <div class="items">
      <div class="item">
        <img src="http://i2.cdn.turner.com/cnnnext/dam/assets/150324154025-14-internet-cats-restricted-super-169.jpeg" height="82" width="82" align="left">
        <label style="margin-top:1px;">Bob</label>
        <br/>
        <label style="margin-top:1px;">Bob</label>
      </div>
      <div class="item">
        <img src="http://i2.cdn.turner.com/cnnnext/dam/assets/150324154025-14-internet-cats-restricted-super-169.jpeg" height="82" width="82" align="left">
        <label style="margin-top:1px;">Bob</label>
      </div>
      <div class="item">
        <img src="http://i2.cdn.turner.com/cnnnext/dam/assets/150324154025-14-internet-cats-restricted-super-169.jpeg" height="82" width="82" align="left">
        <label style="margin-top:1px;">Bob</label>
      </div>
      <div class="item">
        <img src="http://i2.cdn.turner.com/cnnnext/dam/assets/150324154025-14-internet-cats-restricted-super-169.jpeg" height="82" width="82" align="left">
        <label style="margin-top:1px;">Bob</label>
      </div>
      <div class="item">
        <img src="http://i2.cdn.turner.com/cnnnext/dam/assets/150324154025-14-internet-cats-restricted-super-169.jpeg" height="82" width="82" align="left">
        <label style="margin-top:1px;">Bob</label>
      </div>
    </div>

    <div id="second">
      DIV 1
    </div>

  </div>

</body>

Answer №1

Solution 1: Utilizing Float Property

Instead of relying on flexbox for ordering your divs, consider using display: inline-block. There are two main benefits to this approach:

1) It boasts slightly better cross-browser support compared to flexbox (refer to caniuse on flexboxes). Notably, IE10 and 11 do not fully support flexbox, making it a consideration if you need compatibility with these browsers.

2) It allows for more effective utilization of the float CSS property, offering the functionality you seek in styling.

If you set all your .item divs as display: inline-block and position the desired right-aligned div next to them within the HTML structure, applying float: right to the right div will achieve the desired layout. However, there are some caveats to keep in mind, which I'll elaborate on below.

HTML Structure

<div id="wrapper">
    <div class="items">
      <div class="item">
        <img src="image-link" height="82" width="82" align="left">
        <label style="margin-top:1px;">Shane</label>
        <br/>
        <label style="margin-top:1px;">Shane</label>
      </div>
      <!-- Other .item elements here -->

      <div class="right">
          DIV 1
      </div>
    </div>
  </div>

CSS Styling

.items .item{
    display: inline-block;
}

.items .right{
    float: right;
}

Potential Issues

While this solution is viable, there are some drawbacks to be aware of, particularly relating to situations where no items exist or when the right element's height exceeds the total content height of items, necessitating a clearfix.


Solution 2: Side-by-Side Content Arrangement

An alternate approach involves encapsulating all items in a div with a specified width (x) and placing the right content in a div with a width that complements the screen space left by x.

Structured HTML

<div id="wrapper" class="clearfix">
    <div class="left">
        <div class="items">
            <div class="item">
                <img src="image-link" height="82" width="82" align="left">
                <label style="margin-top:1px;">Shane</label>
                <br/>
                <label style="margin-top:1px;">Shane</label>
            </div>
            <!-- Other .item entries here -->
        </div>
    </div>
    <div class="right">
        DIV 1
    </div>
</div>

Styling via CSS

In this scenario, determine the ideal width for the right content and employ the calc() function along with float property alignment to maintain side-by-side positioning.

.left{
    float: left;
    width: calc(100% - 150px);
}

.right{
    float: left;
    width: 150px;
}

/* Include a clearfix for the wrapper */
.clearfix:after {
   visibility: hidden;
   display: block;
   font-size: 0;
   content: " ";
   clear: both;
   height: 0;
}

This setup yields a similar visual outcome, ensuring that items exceeding the right content's height appear alongside it. You can customize the right content size to fit your design needs, adjusting the values accordingly for optimal rendering.

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 successfully press a button on a website?

While testing, I start by navigating in the constructor webBrowser1.ScriptErrorsSuppressed = true; webBrowser1.Navigate("http://www.tapuz.co.il/forums/forumpage/393"); webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted; Next, in the DocumentC ...

Is there a way to utilize a JavaScript function to transfer several chosen values from a select listbox to a different listbox when a button is clicked?

Is it possible to create a functionality where users can select multiple values from a first list and by clicking a button, those selected values are added to a second list? How can this be achieved through JavaScript? function Add() { //function here ...

Aligning text vertically within an HTML <a> tag block

Calling all CSS experts! I'm struggling with aligning text to the bottom of a block element with a fixed width and height that contains a background image and a title. I've tried using display: table-cell; and vertical-align: bottom; without succ ...

What are some strategies for increasing my website's mobile responsiveness?

I've recently completed my online portfolio, and it appears to be functioning properly on desktop computers. However, I'm encountering responsiveness issues when viewing it on other devices or smartphones. Even though I have included the necessar ...

Start up a server-side JavaScript instance utilizing Express

My journey into web programming has led me to learning JavaScript, Node.js, and Express.js. My ultimate goal is to execute a server-side JavaScript function (specifically a function that searches for something in a MySQL database) when a button is pressed ...

How come I am unable to vertically align my elements with bootstrap?

Currently, I am in the process of developing a windsurfing website. Despite utilizing classes such as justify-content-center, align-items-center, and text-center, I am facing an issue where the h1 and h2 elements remain positioned at the top and are not ve ...

Organizing an Ordered List of Items into Alternating Columns Using HTML

I am in the process of developing a responsive HTML design to showcase an array of organized data. For smaller screens, the layout will consist of a single column displaying items sequentially. However, on larger screens, the design should adapt to featur ...

Adding a class to an element can be easily achieved when both input fields have values

Is it possible to apply the "active" class to the element go_back_right only when both inputs with classes search_box_name and search_box_id have content in them? I've tried looking for solutions on this platform, but being new to JavaScript, I couldn ...

What is the best way to align a button with a title on the right side of a page?

Is it possible to align my button to the top right, at the same height as the title in my design? Here is an example: view image here This is what I have achieved so far: view image here I suspect there may be an issue with my divs. The button doesn&a ...

Bracketing the Webpage: A Display of Unique Design

Currently, I am utilizing the Brackets code editor to create a webpage in HTML format. My aim is to transfer these files to another computer so that the user on that device can view the webpage created from these HTML files. Strangely, when I open the HTML ...

I am attempting to implement a feature that changes the color of buttons when they are clicked within an ng-repeat loop

A problem is occurring with the ng-class directive in this HTML code, which is generating seats using the ng-repeat directive. The colors are not being added properly when a seat is selected. If you'd like to view my code, it can be found in this JSf ...

Unable to execute project using CodeIgniter

I'm facing an issue with my current project. Unfortunately, I can't share the website due to confidentiality reasons. I apologize for any inconvenience this may cause. The project is built on the CodeIgniter framework, and it runs smoothly on lo ...

Tips for customizing the color of mat-select placeholder text?

I've been attempting to modify the color of a mat-select placeholder. It functions properly when using 'background-color' but not when using 'color'. Below is my CSS code: /deep/ .mat-select-placeholder { color: red; } .mat-s ...

Increased spacing HTML

Trying to create a footer in HTML, but each time I attempt it ends up with an extra margin on the left side. Here is my current footer code: <div id="footer"> Tester </div> #footer { background-image: url(images/backgroundrpatternf ...

Beginner in html, css, and javascript: "Tips for saving jsfiddle demos?"

Recently, I developed an interest in JavaScript and CSS and came across some impressive examples on jsfiddle. I was wondering if there is a way to "export" these examples to my computer. Simply copying and pasting doesn't seem to work. How can I modi ...

Activate simultaneous HTML5 videos on iOS devices with a simple click

I am currently in the process of developing a webpage that will play various videos when specific elements are clicked. Although the functionality works perfectly on desktop computers, it encounters an issue on iOS devices. The problem arises when the elem ...

the scrollbars are appearing on the window instead of within my div container

I'm having trouble getting a scrollbar on my div element when the content is too wide. Instead, the scrollbar always appears on the window itself. I have tried adjusting the overflow settings but can't seem to find the right solution. jsFiddle ...

Alter the position of the anchor object in the center using JavaScript upon page load

When my page loads, I want to automatically jump to a specific anchor tag and ensure that the anchor object is centered in the window. Initially, I implemented a basic function to achieve this: <body onload="goToAnchor();"> <script type="text/ja ...

Passing a parameter from AJAX to PHP

const studentNumber = $('#studno').val(); $(document).ready(function () { $('.go').click(function () { $('.inup').load('prochat.php', { studno: studentNumber }); }); }); I've ...

creating a table with only two td's for formatting

My ultimate goal is to keep my web form code as minimal as possible for easier maintenance. I am currently working on creating a questionnaire and have been using two td elements for this purpose. Here is an example of what the current text structure looks ...