Uninterrupted stream of multi-line div content without any breaks in between

In this scenario, there are three main divs with a width of 100% each, and within each div, there are 3 inner divs with a width of 50%. The current layout is causing a line break after every set of 3 inner elements.

<style type="text/css">
     .inner{
        width: 50%;
        display: inline-block;
     }
     .outer{
        width: 100%;
     }
</style>
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>

My goal is to have two inner elements on each row without any line breaks. I attempted using float but haven't been successful. Any suggestions on achieving this desired effect would be greatly appreciated.

Answer №1

Perhaps you are interested in this, so please take a look.

  .inner{
        width: 50%; float:left;
        display: inline-block;
     }
     .outer{
        width: 100%;
     }
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>
<div class="outer">
     <div class="inner"> content </div><div class="inner"> content </div><div class="inner"> content </div>
</div>

Answer №2

 .inner{
    width: 33%;
    display: inline-block;
 }
 .outer{
    width: 100%;
 }

To rectify the problem, you can add this CSS code snippet. Occasionally, certain browsers may present issues. The optimal solution would be to set the width at 33.33%, but you can also try slightly lower values like 30% or 32%. Hopefully, this adjustment resolves the issue for you!

Answer №3

To determine the width of each div, divide 100 by the number of divs you want to display.

For example, if you want to display 2 div's, then 100/2 = 50%. In this case, you would set the class width 50%.

Similarly, for 3 divs: (100/3) = 33.33

So, you would need to set the following CSS:

.inner{
        width: 50%;
        display: inline-block;
        float: left;
     }

Answer №4

The issue arises from the inner width being set to 50%, causing a line break as two divs already occupy 100%. If the inner width is adjusted to :33%, it will accommodate three inner divs. To fit more inner divs, divide 100 by n (the number of divs) to determine the appropriate width.

.inner {
  width: 32%;
  display: inline-block;
}

.outer {
  width: 100%;
}
<div class="outer">
  <div class="inner"> content </div>
  <div class="inner"> content </div>
  <div class="inner"> content </div>
</div>
<div class="outer">
  <div class="inner"> content </div>
  <div class="inner"> content </div>
  <div class="inner"> content </div>
</div>
<div class="outer">
  <div class="inner"> content </div>
  <div class="inner"> content </div>
  <div class="inner"> content </div>
</div>

Answer №5

To fit 3 divs inline, each div should have a width of 33%. However, to account for a 2px gap between inline-blocks, we set the inner div width to 32%. Make sure the inner div's width is 32% so that all 3 inline-blocks can fit within the parent div's given width. See the code snippet below:

.bigBox
{
    width: 700px;
    height: 500px;
    background: grey;
}

.box{
    width: 32%;
    display: inline-block;
    background: yellow;
}
<body>
<div class="bigBox">
<div class="box">
content1
</div>
<div class="box">
content2
</div>
<div class="box">
content3
</div>
</div>
  </body>

This advice was provided by @Rubenxfd in a previous comment. Hopefully, this explanation helps clarify things :)

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

Implementing a feature in React to restrict access to my URL for a specified duration

I'm currently developing my React project and I need to make a specific page on my website accessible for only a limited time, like 5 minutes. For example, I want to send the user an email with a unique url, allowing them to access the designated web ...

On mobile devices, the Next.JS application (featuring Chakra UI) does not stretch to full width

I'm stumped on this one... Maybe there's something simple I'm overlooking, but I'm hoping for some help from you guys. When viewed on mobile devices, the entire HTML element takes up around 80% of the screen width. Oddly enough, resiz ...

Is there a way to automatically submit an upload form once a file has been selected?

Need help with automatically submitting a file upload form when a file is selected. Is there a way to bypass the need for the user to click the Submit button? ...

The requested resource at http://localhost/Grafica/%7Bd.icon%7D/ was not found (Error 404)

Creating a tooltip in a weather chart, I want to display an image of the sky condition. Below is the HTML code: <div id="tooltip"> <table class="table table-condensed"> <tr><th>Time (local)</th><th data-text="d ...

Combine Angular variable in JavaScript function

I want to combine "proposal.id" in the initial parameter of the window.open function. Here is my current code snippet: <button ion-button color="light" onclick="window.open('https://mywebsite.com/offer?id={{ proposal.id }}', '_self' ...

Ways to modify the background color of the entire body excluding a sidebar div

How do I implement an overlay and dim the screen after clicking on a menu button? <ul id="gn-menu" class="gn-menu-main"> <li class="gn-trigger"> <a class="gn-icon gn-icon-menu"><span>Menu</spa ...

What is causing the href to not trigger?

Can someone explain why the href attribute of this anchor tag isn't triggering? http://jsfiddle.net/3ho7ommm/4/ <span class="menuoptions active"> If anyone has any insight, please help me out. Thanks! ...

Struggling to position search form to the right side of an <li> element

I'm having trouble aligning my search bar to the right side of the navigation menu items. HTML: <body> <div id="navbox"> <nav id="nav"> <ul id="nav"> <li><a href="#">Home< ...

What is the suitable condition necessary for optimal functionality?

Greetings all! I am a newbie in the world of development and also new to Stack Overflow. This is my maiden post seeking assistance on the following issue: $(document).ready(function() { $(".header").click(function() { if ($(".header-content"). ...

The ajax response is returning the entire page's html code instead of just the text content from the editor

I've been working with CKEditor and I'm using AJAX to send the editor's content via POST method. However, when I try to display the response in a div, the HTML for the entire page is being returned instead of just the editor's content. ...

The Bootstrap 4 Footer fails to align at the bottom of the page

Looking to design a sleek main page with a footer using bootstrap-4? Take a look at this example. Despite the footer being styled with bottom: 0;, it appears in the middle of the screen on browser or mobile view. JSFiddle Example HTML: <div class ...

The issue with the search box not being correctly displayed on Google CSE using Twitter Bootstrap

Having an issue with the Google Custom Search (CSE) as it is not displaying the search box and button correctly. I am using Twitter Bootstrap v3.1.0. <script> (function() { var cx = '009077552906670546181:2ufng0dmsos'; ...

Is there a way to modify the text color within the thumb-label of the Vuetify v-slider component?

Lately, I've been facing some challenges and my objective is to change the color of the thumb label on my v-slider to a custom one that is defined in the component's design. Can anyone provide guidance on how to achieve this? Regards, Joost ...

The jquery function is not operating as anticipated

I wrote the following code to toggle a class for a div. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <html> <head> </head> <body> <div class="members-section " id="a ...

Having trouble making a Bootstrap 4 input-group with beta 3 prepend/append function properly

When working with Bootstrap 4 Beta 3, I encountered some challenges with the Beta 3, particularly with the input-group-append and input-group-prepend classes. I struggled with placing these classes at the end of my input group. The last button in my inpu ...

Angular disrupts the functionality of jQuery slideshow

While working on this template, I encountered issues with the functionality after integrating Angular into the application. Although I managed to fix most of them, I'm facing difficulty getting the slideshow to function properly. Here is the HTML cod ...

The HTML Style for implementing HighChart title text does not work when exporting files

I have inserted the <br/> and &nbsp; HTML tags into the HighChart titles. The style changes successfully appear in the chart view, but unfortunately, when exported as PNG or JPEG images, the text style fails to apply in the resulting images. To s ...

Sending Ajax GET request following the first Ajax POST request

Upon completing the initial ajax post, I am attempting to make a second ajax call. The initial call is a POST and the second call is a GET. Even though I am able to retrieve the values from the url file.php in the second call, I am facing difficulties in u ...

CSS - Dynamic triangle separator

I've been working on creating a triangle-shaped CSS divider. Using the code snippet below, I was able to achieve the desired result: border-width: 4vw 75vw 0 23vw; However, this method feels a bit unconventional. Since you can't use percentages ...

vertical alignment problem in dropdown box - compatibility problem with Firefox

I'm encountering an issue with the vertical alignment of a select box caption in Firefox. The CSS for the select element is as follows: select#cities_list { width: 95px; height: 45px; line-height: 45px; background: url('./img/se ...