Positioning text too far to the left causes it to become disorganized and difficult

I am looking to achieve the following result:

LEFT THING, not fixed    here comes a text that spans 100% width of this "column"
width (content itself    but my issue is that when it gets too long, this column drops below
determines that)         the left column instead of staying next to it. I also want the text to wrap 
                         neatly downwards without extending under the left column, which creates an 
                         undesired effect. It's similar to a table element, but not ideal for this situation :/

the DIV structure:

<div style="float: left">LEFT THING</div>
<div style="float: left">here comes a text, which...</div>

What could be a possible solution?

Answer №1

Elements that are floated with a width: auto property are automatically sized using the shrink-to-fit algorithm, meaning they will expand to fit their content.

To prevent this automatic expansion, it is recommended to set a limit on the width by either specifying an explicit value using width or setting a maximum width using max-width.

In order for the next block element to occupy the remaining space after the floated item, it should have default properties of float: none and width: auto. Additionally, establishing a Block Formatting Context (BFC) can ensure that there is no overlap with the floated element.

.wrapper, .main {
  overflow: hidden; /* Establish Block Formatting Context */
}
.left {
  float: left;
  max-width: 30%; /* Limit maximum width */
}
<div class="wrapper">
  <div class="left">...</div>
  <div class="main">...</div>
</div>

.wrapper, .main{
  overflow: hidden; /* Establish Block Formatting Context */
  text-align: justify;
}
.left {
  float: left;
  max-width: 30%; /* Limit maximum width */
  border: 1px solid blue;
}
.main {
  border: 1px solid red;
}
<div class="wrapper">
  <div class="left">LEFT THING LEFT THING LEFT THING LEFT THING</div>
  <div class="main">here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which... here comes a text, which...</div>
</div>

Answer №2

Try adding width to your elements so that you can float them, which should give you the desired outcome.

Check out this demo: http://jsfiddle.net/q8SfB/1

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

Executing a JavaScript function upon page load without the need for an onclick event

I have a footer.php file that contains JavaScript code and functions which I use on all of my pages. While I usually call the function MyFunc() using onclick event when clicking buttons, there are some pages where I need to call it without any user interac ...

What is the best way to personalize the icon for this navigation button?

I'm interested in making some changes, especially to the border. I've already figured out how to adjust the color of the 3 bars like so: .navbar-default .navbar-toggle .icon-bar { background-color: #fff; } Modification RESOLUTION .navbar- ...

The use of the <span class="blinking"> element is not functioning properly within the JavaScript

<body class="container-fluid"> <div class="panel panel-primary"> <div class="panel-heading"> <h3>Body Temperature</h3> </div> <div class="panel-body"> <p>Your body temperature is hig ...

Formatting Specific Labels in HighCharts: A Guide

I'm trying to display the label values within a Highcharts bar chart by utilizing the dataLabels.Formatter function. However, I've noticed that when the bar size is inconsistent, the labels are sometimes displayed inside the bar, which looks goo ...

jQuery .CSS is not working for positioning the element at the bottom right corner!

I am struggling to create a basic Modal Box that can be minimized to the bottom right corner of the screen. I want to turn it into a plugin, but I'm having trouble getting the simple CSS to cooperate and position itself correctly at the bottom right. ...

Problem encountered when implementing multiple filters in Vanilla JavaScript

I am facing an issue with my HTML page that contains multiple filters using Vanilla JavaScript (no jQuery). The filtering process involves counting matches of filter selections against the data attributes of each element. However, I'm puzzled as to w ...

Stack the text on top of each other beside an image

Here is some HTML code that I am working with: <div class="row"> <div col-md-9> <div> <img class="img-valign" src="an image"> <span class="text1" Style="font-size: 8 ...

Utilize Java Spring Boot to enable file uploads and send additional data through AJAX by submitting a form

I am currently in the process of developing an application that requires me to upload a file and also send an additional parameter along with it. The following is the code I have written for the client side. $.ajax({ url : "/uploadFile", ...

What are the tips for aligning this button perfectly on the page, despite being centered in a computer's resolution?

Dealing with Responsive Design Hey there! I'm having an issue with my Bootstrap layout. I managed to center a button, but when I adjust the resolution or make it smaller, the button wraps and shifts to the right. Can anyone help me figure out what we ...

I am in need of a efficient loader for a slow-loading page on my website. Any recommendations on where to find one that works

I'm experiencing slow loading times on my website and I'm looking to implement a loader that will hide the page until all elements are fully loaded. I've tested several loaders, but they all seem to briefly display the page before the loader ...

What is the best way to include multiple <p> elements in a row using Bootstrap?

What is the best way to display multiple <p> elements inline using Bootstrap? This is the code I have currently: <div className="container d-inline-flex"> <p className="text-nowrap"> This is sent ...

Design an unordered list containing a text input field and a clickable button

I need assistance with creating a feature where text input is converted into a list when a button is clicked. Here's what I currently have: <!doctype html> <html> <head> <meta charset="UTF-8"> <title>3-2</title> & ...

`Is there a way to conceal a div class when the input id value is not filled in?"`

I've hit a roadblock with this issue that's been troubling me for days. I would greatly appreciate any assistance in solving it. Working on a Wordpress theme, I have an options panel where users can input their Twitter username. My goal is to di ...

The input element captures the exact x and y coordinates of where the mouse was clicked

I have a requirement to submit a page, and I have opted to utilize the <input> element for this purpose with an image that zooms slightly when hovered over. Due to the unusual nature of my query, I was unable to find any relevant information about t ...

Adjust the background color of the panel heading when it is toggled in a Bootstrap collapsible panel group

I'm currently working on a collapsible panel group design using Bootstrap. I want the panel heading to have a different background color when the panel group is expanded versus when it is collapsed. I initially attempted to use the :active selector, b ...

Arranging multiple Label and Input fields in HTML/CSS: How to create a clean and

I'm struggling with HTML and CSS, trying to figure out how to align multiple elements on a page. I've managed to line up all the rows on the page, but for some reason, the labels are appearing above the input fields when I want them to appear be ...

Tips for focusing on a background image without being distracted by its child elements

I am trying to create a zoom effect on the background-image with an animation but I am encountering issues where all child elements are also animated and zoomed. When hovering over the element, I want only the background part to be animated and zoomed, and ...

Tips for passing a page as an argument in the function parameter of the page.evaluate() method?

I keep running into this issue when I pass the page as an argument: TypeError: Converting circular structure to JSON --> commencing at object with constructor 'BrowserContext' | property '_browser' -> object with const ...

Newbie Query: How can I apply various font weights to a single font within the same stylesheet?

Twice I have inserted the font Acumin Pro Condensed, once with a weight of 400 and again with a weight of 700. I attempted to use both weights separately; assigning the 400 weight to an h3 tag and the 700 weight to an h2 tag. However, only the 700 font we ...

The label element in a CSS form is not displaying correctly

After clicking submit on the form located at this link: I am experiencing an issue where the validation messages are not displaying as intended. I would like them to appear next to the input elements, inline with the form. I suspect that there may be a p ...