What is the best way to make the contents in the left div collide with the right div?

Is there a way to make the left div's content flow around the right one without overlapping?

.class1 {
  background-color: #678e6f;
  width: 80%;
  float: left;
}

.class2 {
  background-color: #00ff34;
  width: 300px;
  float: right;
}
<div class="class">
  <div class="class1">
    <img/><img/><img/>
  </div>
  <div class="class2">
    <li>text</li>
  </div>
</div>

When the divs collide, I want them to align perfectly on the right side.

I am looking for a solution that will allow all elements to be transferred smoothly like in this example:

Can this be achieved?

Answer №1

Your sample has several issues, but if you aim to have text wrapping around an image (or any div) aligned to the right, it would resemble something like this:

.containerClass {
   background-color: #678e6f;
}

.floatClass {
   background-color: #00ff34;
   width: 300px;
   float: right;
   margin: 10px; /* Don't forget about margins! */
}

Next, in the HTML section:

<div class="containerClass">
  <div class="floatClass">
    <img /> <!-- This is where the image that text will wrap around goes. -->
  </div>
  <p>This is the content that will flow around the floated div.</p>
</div>

It doesn't matter whether the elements are text or images, or a combination of both. The type of content is not important. However, having text wrap around images is not very common!

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

What is the best approach to creating a website for a client who needs to incorporate their own Youtube videos?

Welcome to my first post on this platform! I have a new project where I am creating a website for a client who wants to easily embed their own YouTube links. As a beginner in web development, this is my first paid task and I'm curious about how I can ...

Combine the second and third rows into a unified single row

A Python script using BeautifulSoup to scrape a Wikipedia page for a list of Test cricket records and outputting the data into a Pandas DataFrame. From the Python script: import necessary libraries Define the Wikipedia page URL and header Request the pag ...

Is setting the height to 100% a dependable option for container loading during the initial page rendering in CSS?

Upon arrival on the page, I envision the container containing the "search" to expand and occupy the entire screen. Seems simple enough: just set the height to 100%. If the user chooses to scroll down, they will see the rest of the content. It almost fee ...

Discover the secret to showcasing the latest items at the bottom of a scrollable flexbox container (Complete with code example)

Attempting to create a simple instant messaging interface using flexbox, where incoming messages are displayed at the bottom and push older messages upwards has been a challenge. Struggling to find an elegant solution to ensure new elements always appear ...

Alter the hue on the fly

How can I change the color of a div based on whether it is currently red or green? I attempted the following code, but it doesn't seem to be working as expected. if ($(this).css("background-color")=="rgb(34,187,69)"|| $(this).css("background-color") ...

Transform Asp:CheckBox Appearance with CSS Styling

Is there a way to customize the appearance of the standard "3D" look for asp.net checkboxes to have a solid 1px style? When applying styling to the Border property, it simply adds a border around the checkbox itself. I'm looking to change the styling ...

step-by-step guide on showcasing and concealing textbox borders

Within a table, I have a column with a text box for users to edit the text as needed. The edited text is properly being saved using the onkeyup event. However, I want to hide the border of the text box after editing, so only the edited text is visible. If ...

Create a visual representation of an item within a framework using an Angular directive

I am interested in using a directive to draw a triangle above a series of div elements. In my scenario, I have four squares and two values: charge and normal. The value of charge determines the color of the squares, while normal is used for drawing the t ...

Recording Node pathways that begin with the hash symbol #

How can I configure my Node/Express routing to intercept a route like /#/about and send it to /about Is there a way for node to handle routes that start with "/#"? It appears to only cut off at the hash mark. ...

Guide to switching content within a DIV when the up and down buttons are pressed using JavaScript and jQuery

I have a functional code with a timeline where each event is connected to the other. There are buttons to delete and copy data, but I want to implement functionality for swapping elements when the up or down button is clicked. I have provided a sample code ...

Showcasing the values of JavaScript

How can I resolve the issue depicted in the second picture? I need the value of 3 only in the USD column, with all others having a value of zero. <div class="span3"> <ul class="nav nav-tabs nav-stacked" > <?php foreach ( ...

Populating a drop-down menu using Python requests in a select tag

I am attempting to select/enter a value into a dropdown menu using Python Requests, but for some reason it is not working. Here is the HTML code: <select name="hourly_rate" class="default-input" id="hourly_rate"> <o ...

Using Ajax to update multiple text field rows with unique values

I have a question regarding utilizing Ajax to update the second text field based on the input from the first text field. I am looking to create multiple rows using a for loop, with each row having its own set of values. HTML <form style="text-align:c ...

I am creating accordion-style bootstrap tables using data generated from an ng-repeat loop, all without the use of ui.bootstrap or jquery

My attempt at creating a table with rows filled using ng-repeat is not working as expected. I want a collapsible panel (accordion) to appear on click of each row, but only a single row is rendering with my current code. Here is a link to my code: var ap ...

I'm looking to mirror images within the Bootstrap framework - any suggestions on how to achieve this using jQuery

When hovering over the image, it should flip to reveal text or a link: <div class="clearfix visible-xs"></div> <div class="col-md-3 col-sm-3 col-xs-6"> <div class="speaker-item animated hiding" data-animation="fade ...

Finding the Right Spot to Edit HTML Code in Microsoft Dynamics CRM

Is it possible to change the width of a custom iframe in Microsoft Dynamics CRM that is currently set at 1900px? <div id="mainContainer" class="classname_here" style="max-width: 1900px"> I was able to change it to 100% using a browser extension. Ca ...

"Upon refresh, the overflow property of the child element is being applied to the window position

In the React app I'm working on, there's a search results page where users can apply filters. These filter selections update the query params in the URL and trigger a re-mount in React. However, I've encountered an issue across different bro ...

class automatically receives an unwanted display: none attribute

After I added a copy link inside my panel and clicked to open it, an automatic display:none was triggered. To fix this issue in my jQuery code, I included the line: showme.style.display = "none";. This allowed me to open the panel successfully, but now I& ...

What is preventing the 'p:nth-child(1)' from functioning properly in my HTML code?

Even though I used p:nth-child(1){color: white;} in my CSS style tag, it did not produce the expected result. body { background-color: #162b85; } button, p:nth-child(1) { color: white; } <p class="center">Register your account</p&g ...

Get access to a PDF file by simply clicking a button that has a href link without any URL or file

After successfully simulating a click on the "PDF" link on a webpage, I am trying to save the downloaded PDF file to a specific location. However, I am facing difficulty in retrieving the URL for the PDF using the urllib library. Here is an example of the ...