What is the best way to fill the gap between a left and right float element without causing the right float to break onto a new

I am trying to make sure all the elements are on the same line, but if the paragraph in the middle is wider than the available space, I want the text to truncate with an ellipsis. If the paragraph isn't wider, the right float should remain on the same line.

Check out the Codepen example here

HTML:

<div id="outer">
  <div id="left"></div>
  <div id="middle">
    <p>Can this paragraph fill the space between the left and right floats without making the right float wrap?</p>
  </div>
  <div id="right"></div>
</div>

CSS:

#outer {
  background-color: #222;
  height: 100px;
  width: 100%;
}

#left {
  background-color: #555;
  width: 100px;
  height: 100px;
  float: left;
}

#right {
  background-color: #777;
  width: 200px;
  height: 100px;
  float: right;
}

#middle {
   background-color: #999;
   height: 100px;
}

#middle > p {
   line-height: 100px;
   color: #eee;
   text-overflow: ellipsis;
   white-space: nowrap;
   overflow: hidden;
   font-family: monospace;
}

Answer №1

Apply a

float: left;

to the element located in the center. Additionally, experiment with specifying a width to prevent the central block from expanding to 100%.

Answer №2

To achieve the desired layout, it is recommended to utilize a reliable grid system. Twitter Bootstrap offers two excellent options: the Default Grid System and the Fluid Grid System. Alternatively, you can customize the Bootstrap package from their official website by selecting only the necessary modules.

Another approach could involve correcting the typo in #middle and using float: left on #middle to prevent #right from wrapping. It may be essential to employ JavaScript to dynamically adjust the width of #middle based on the screen size to avoid text overflow pushing #right downwards. Employing a grid system simplifies this process!

I have included JavaScript within window.onload to handle this functionality, which could alternatively be triggered on resize events.

For reference, here is the modified code: http://codepen.io/anon/pen/xfwJi

Answer №3

Here is a possible answer:

#main-content {
   background-color: #999;
   height: 100px;
   float:left;
   width:1364px;
}

Answer №4

You may want to consider floating the middle div to the left, too. That might be a solution worth trying.

     #middle {
         background-color: #999;
         height: 100px;
         float:left;
            }

Answer №5

If you're looking for a solution, I have created a JSFiddle that may help with your problem.

Additionally, I recommend using a grid system to simplify the website creation process and minimize potential issues.

Here is an example of CSS code:

#outer {
  background-color: #222;
  height: 100px;
  width: 100%;
}

#left {
  background-color: #555;
  width: 100px;
  height: 100px;
  float: left;
}

#right {
  background-color: #777;
  width: 200px;
  height: 100px;
  float: right;
    margin-top: -100px;
}

#middle {
   background-color: #999;
   height: 100px;
    width: 72%;
    float:left;
}

#middle > p {
   line-height: 100px;
   color: #eee;
   text-overflow: ellipsis;
   white-space: nowrap;
   overflow: hidden;
   font-family: monospace;
}

For more information on CSS grid systems, check out this site that offers a list of 10 popular options: click here!

Answer №6

When styling the element with ID #middle inside a paragraph tag, apply the CSS property float: left;

#middle > p {
 line-height: 100px;
 color: #eee;
 text-overflow: ellipsis;
 white-space: nowrap;
 overflow: hidden;
 font-family: monospace;
 float: left; /* update this style */
}

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

Display the item for which the date is more recent than today's date

Is there a way to display only upcoming 'events' on my page based on their event_date? <% for (let event of events){%> <div class="card mb-3"> <div class="row"> <div class="col ...

Display hidden text upon clicking using React Material UI Typography

I have a situation where I need to display text in Typography rows, but if the text is too long to fit into 2 rows, ellipsis are displayed at the end. However, I would like to show the full text when the user clicks on the element. I am attempting to chang ...

Tips for modifying the border of an entire column in react-table

My goal is to adjust the style according to the screenshot below. This is what I expect: However, this is what I currently have: As you can see, the border bottom of the last column is not applied as expected. I have tried using the props provided by r ...

Magnific Popup displaying only the initial item

As someone new to using jQuery and Magnific Popup, I am working on a grid of images. When an image is clicked, I want Magnific Popup to display a specific div containing information relevant to that particular image. <div class="grid"> <div c ...

Showing error messages in Angular when a form is submitted and found to be invalid

My form currently displays an error message under each field if left empty or invalid. However, I want to customize the behavior of the submit button when the form is invalid. <form #projectForm="ngForm" (ngSubmit)="onSubmit()"> ...

What strategies can we implement to reduce the gutter width in Bootstrap 3?

Is there a way to decrease the gutter-width in Bootstrap 3? Since Bootstrap uses a 12-grids system, using col-sm-* creates a gap between elements of around 30px (15px on each side of the grid-column). However, my theme requires less space between columns ...

How can I launch an application using an .html file on a Linux operating system?

I'm currently involved in an image processing project and have limited knowledge of HTML. Here's how I envision it working. In my C++ application, I have the capability to read an image, process it, and then save the processed image to a file. T ...

Creating a central navigation menu for a website

Currently, I am working on incorporating a menu in the center of a webpage (please note that this is not a top navigation menu). Here is the initial setup: https://i.sstatic.net/3arql.png Users are able to click on various menu items to access different ...

What could be causing this addEventListener to fail when I am assigning elements to a class?

I've encountered an issue with my code where I have two text inputs and two date inputs. I tried to select all of them using QuerySelectorAll with a class, added a click listener that should change the textContent of a div element to "", but it's ...

Alignment problem with the text on the left

Utilizing remodal.js from the repository found at https://github.com/VodkaBears/Remodal to develop a modal interface: http://jsfiddle.net/j4wnov5z/. In essence, I am trying to align certain elements to the left, but encountering difficulties. For instanc ...

Interactive data visualization with hover-over details

I am utilizing datamaps to showcase the countries of the world, however, I want the graph to be centered. The issue arises when I hover over a country and the pop up appears all the way to the left, aligned with where the country would be if it wasn't ...

output a portion of the present operational folder

Currently, the directory I am focusing on is C:\xampp\htdocs\example\profile\john_doe I am curious about how I can display john_doe in this scenario. My coding language of choice is PHP. ...

If you press Ctrl + F, the browser will disable the form search function

How can I prevent the form find browser functionality when pressing Ctrl+F, and instead focus on the element html? <div id='demo'> <form class="id5-text-find-form" id="id5-text-find-form"> <input class="search" placeho ...

Displaying a Bxslider inside a modal window

Attempting to launch a popup div that will include a bx slider. The link triggering the popup div works correctly. However, the images inside the bxslider are not displaying, even though the loading and direction control images are visible. Initially thoug ...

How come my primary content is always spilling onto the header section?

Whenever I try to insert my header (after adding my context), it ends up getting placed below the context, making it invisible. I have attempted adjusting the padding and other sizes, but nothing seems to resolve the issue. https://jsfiddle.net/L30trdfn/ ...

What is the best way to calculate the pixel height of an element when the height is specified in vh units?

element lies this inquiry: In my JavaScript code for developing Windows 8 apps, I have set the max-height of an element to 65vh. I now require a method to convert this value into pixels in order to determine if an image can adequately fit within this spac ...

CSS Styles Only Apply to the Initial Column on the Website

It seems like the css is only working on the first column to display the item-meta. Everything appears to be in place when inspected, but for some reason, the opacity does not change back to 1. It's strange because it works fine in the first column ev ...

Struggling to link CSS file to HTML

I've been attempting to link my CSS file to HTML using PHP, but I'm hitting a roadblock. Despite checking similar topics, I can't seem to find the right solution. Any assistance you could provide would be greatly appreciated. This is what ...

Pressing the button results in no action

I am currently developing a program that randomly selects 5 words from a database and inserts them into an array. Although the page loads correctly initially, nothing happens when the button is clicked. None of the alerts are triggered, suggesting that the ...

Issues arising from the combination of a grid system in Bootstrap and WordPress

There seems to be an alignment issue on my webpage where the div.col-4 inside div.col-9 is not aligning properly. To provide a better explanation, here is the code snippet and a screenshot of my webpage: <div class="col-12 col-lg-9"> < ...