What is the most effective way to format text so it wraps around an image from both sides in two separate paragraphs?

It took a significant amount of time, but I finally achieved the following:

window.onload = () => {
  const fimg = document.querySelector('#first img')
  const fimgWidth = fimg.getBoundingClientRect().width

  const simg = document.querySelector('#second img')
  const simgWidth = simg.getBoundingClientRect().width

  fimg.style.left = `${fimgWidth/2}px`
  simg.style.right = `${simgWidth/2}px`
}
div {
  display: flex;
}

p {
  flex: none;
  width: 50%;
}

img {
  shape-outside: url("https://openclipart.org/download/318603/hand-written-circle-04.svg");
  position: relative;
}

#first img {
  float: right;
}

#second img {
  float: left;
}
<div>
<p id="first">
<img src="https://openclipart.org/download/318603/hand-written-circle-04.svg">
<span>Sed ut perspiciatis... [content truncated for brevity]</span>
</p>
<p id="second">
<img src="https://openclipart.org/download/318603/hand-written-circle-04.svg">
<span>Sed ut perspiciatis... [content truncated for brevity]</span>
</p>
</div>

The design concept is clear: positioning two paragraphs horizontally with an image in between, ensuring smooth text wrapping around the image.

Although the current solution works as intended, doubts linger regarding its optimal approach:

  • Is obtaining the image width through Javascript indicative of overlooking simpler CSS methods?
    • Given my aim to use random images from a pool, avoiding hardcoded widths seems essential
  • Involving two stacked copies of the image raises concerns. Could single-image placement options be explored further?
    • Potential alignment discrepancies due to computational nuances and sub-pixel issues might arise. Is there a more precise alternative to prevent such misalignments?

What alternatives exist for a more streamlined implementation?

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 causes external CSS to take precedence over embedded CSS in my webpage?

As per a certain source, conflicting CSS styles on the same element should be overridden by embedded styles over external styles, but my observation proves otherwise. My HTML code (simplified version) is as follows: <html> <head> <link r ...

Ways to effectively incorporate Bootstrap into Lit?

Currently, I am in the process of converting a website from Polymer to Lit. I have made good progress with it, but I have encountered a roadblock when it comes to styling. In order to simplify development and focus on functionality, I have been following t ...

Error encountered while trying to upload a file using PHP on a hosting platform

Hey everyone, I'm feeling really frustrated right now because I'm facing a file upload error in my PHP code. The issue is that the file is not getting uploaded to my folder and no error messages are being displayed. I've been working on cr ...

Proper alignment of Child Elements within a 3D Transform is crucial for optimal visual

I have a DIV containing an image and 2 child elements, structured as follows: <div id="main"> <div id="left"></div> <div id="right"></div> <img ... /> </div> A 3D transform is being applied to #main in t ...

What is the best method for positioning 2 buttons at the bottom of a card using Bootstrap?

I need help with adjusting the position of two buttons in my bootstrap design. I would like both buttons to be located at the bottom of the card and have a slight gap between them, perhaps around 5 pixels. Below is the snippet of code: <div class=" ...

Animate hovering over a specific element within a group of similar elements using jQuery

Hi there! I recently started exploring Js and jQuery, and I was able to create a cool width change animation on a div when hovering over another. However, I ran into an issue when trying to implement this with multiple sets of similar divs. Whenever I hove ...

Execute JavaScript/AJAX solely upon the selection of a button

Currently, my script is being executed immediately after the page loads and then again after a button click. Is there any way to modify it so that the script waits until I click the button before running? As far as I understand, this code runs asynchronous ...

Outputting HTML from a function

As a beginner, I have a question about best practices. Is it more effective to return HTML from a function like the following: function displayHtml($userName) { $htmlMsg = " <html> <head> <title>Displaying HTML</title&g ...

Tips for customizing the appearance of the "Read More" button on an Elementor card

I'm new to the world of wordpress and I'm struggling to customize the CSS for a button on a card. My goal is to center the "Read more" button on the post card and give it a border, but I'm not having any luck in Elementor. I tried tweaking t ...

I am experiencing issues with React Bootstrap's responsive mode not functioning as desired

As a new developer for bootstrap, I created a product that collapses automatically from either the right or left side of Chrome in a responsive manner. However, when I manually choose an absolute width using the inspect tool, it does not display the same a ...

Is there another way to align the image in the frame without adjusting the size

Is there a method to prevent the HTML <img> tag from squeezing an image when the specified size using the width or height attributes is smaller than the image itself, and instead make it crop the image? ...

jQuery checkbox toggles multiple divs instead of targeting specific ones

I have set up my page to display divs containing posts using a specific format. The divs are structured as follows (replacing # with the postID from my database): <div id="post_#> <div id="post_#_inside"> <div id="like_#"> ...

Perform an AJAX request to an encrypted URL with an unverified certificate

I'm experiencing an issue with my site that makes AJAX JSONP calls to a secured (SSL) web server. Everything works smoothly when using an unsecured (HTTP) web server, but once I switch to the SSL version, the call never returns. After checking with Fi ...

Interactive JQuery plugin for scrolling through thumbnails with customizable buttons

I am attempting to create a jQuery thumbnail scroller with buttons that respond to mousedown and mouseup events. I have successfully implemented the scrolling functionality, but I am facing issues when trying to refactor it into a reusable function. Below ...

What is the reason behind the incompatibility of css background-size/position with the shorthand background url?

I had been working on a concept for a slideshow or single-page website and reached a good stopping point. Since I had outlined my idea on a JSFIDDLE, I decided to tidy up my CSS. Each of the 5 tabs used similar lines of CSS except for the background image. ...

Creating a dynamic table inside a flex-grow container without disrupting the layout: A step-by-step guide

Currently, I am in the process of designing a responsive layout using Bootstrap 5.3 which consists of a NavBar, SideBar, ContentPanel, and StatusBar. The goal is to ensure that the application always occupies 100% of the view-height and view-width, display ...

Correctly showcasing image text

I am currently experiencing difficulties with the orientation of elements in the react app. Specifically, I am trying to align the elements in a horizontal line. Any assistance with achieving this would be greatly appreciated. ...

Maintaining header and footer while calling a PHP form on the same page

I have a straightforward PHP form, named home.php, that submits to itself: <form action="home.php" method="post" enctype="multipart/form-data" id="AddImageForm"> The issue arises when home.php is accessed from the index.php file (located below). Up ...

Merge ReactCssTransitionGroup with React-route's Link to create smooth page transitions

React.js I'm facing an issue with the React.js code provided below. My goal is to set up the animation before transitioning to a new page using "React-router.Link" and ReactCSSTransitionGroup. Version: react: '15.2.1' react-addons-css-trans ...

CSS Overflow Properties - Emulate the Input of a Lengthy Equation in a Calculator

Creating a calculator project with the challenge of handling long mathematical equations that exceed the display width. The goal is to have the left side of the equation scroll off the screen when it becomes too lengthy. For instance: 50+200x25/43-500x60 ...