Delete the float attribute from the image when the inline-block is shifted to the bottom of the image

I have three elements in my design - a title, a paragraph, and an image. I want the image to float to the right, with the title and paragraph floating to the left and bottom, resembling "Image 1."

To prevent the title from wrapping when narrowing the outer div (the blue frame), I used display:inline-block on the title.

However, I encountered an issue: When I narrow the width of the outer div causing the title to move to the bottom of the image, the image still aligns to the right, similar to "Image 3." What I actually need is for the image to align itself to the left like "Image 2."

Is there any way to remove the float property of the image if the inline-block title moves to the bottom of the image?

https://i.stack.imgur.com/7audQ.png

#div0{
  width: 1000px;
}

#div1{
  width: 550px;
}


.outer{
  margin: 20px 0;
  border: 1px solid blue;
}

.image{
  float: right;
}

.title{
  display: inline-block;
}

.paragraph{
}
<div id="div0" class="outer">
    <img src="http://www.w3school.com.cn/i/eg_tulip.jpg" class="image" />
    <h1 class="title">This Is the Title...</h1>
    <div class="paragraph">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.This is some text.</div>
</div>

<div id="div1" class="outer">
    <img src="http://www.w3school.com.cn/i/eg_tulip.jpg" class="image" />
    <h1 class="title">This Is the Title...</h1>
    <div class="paragraph">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div>
</div>

Answer №1

Utilize media queries to adjust styling based on screen size.

@media only screen and (max-width:768px) {
    .header{
      font-size: 14px;
    }
}

You have the flexibility to modify the "768px" value to cater to your desired width adjustment.

Answer №2

Using CSS alone is not sufficient to achieve this task. It is necessary to insert a @media query, but determining the breakpoint size requires knowing the exact widths at runtime, which can vary due to different factors.

Therefore, employing JavaScript to create the media query is the way to proceed. The max-width is calculated as the sum of the title width, image width, border width, and outer margin (assumed as 18px).

document.head.innerHTML += '<style>\n'+
  '@media (max-width: '+(document.querySelector('h1.title').offsetWidth+
        document.querySelector('img.image').offsetWidth+18)+'px) {\n'+
  ' .image {float:none}\n'+
  '}\n</style>\n';
.outer{
  margin: 20px 0;
  border: 1px solid blue;
}

.image{
  float: right;
}

.title{
  display: inline-block;
}
<div id="div0" class="outer">
    <img src="http://www.w3school.com.cn/i/eg_tulip.jpg" class="image" />
    <h1 class="title">This Is the Title...</h1>
    <div class="paragraph">This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div>
</div>

Answer №3

Examine the width value in the Inspect Element feature of web browsers.

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

Is it possible for me to create an HTML script that can transfer data from the script to a cell within Qubole?

Is it possible to create an HTML script that allows user interaction, pass the data back to a zeppelin cell, and trigger a rerun of the data? Thank you! Update: I have made some progress in rerunning the cell with an HTML click. The cell I want to rerun ...

Unable to modify the border radius of the carousel indicators in Bootstrap 5

Currently, I am working with the carousel component in Bootstrap 5.1. I have encountered an issue where I am unable to add border-radius to the carousel indicators, despite trying various methods. Even though the inspector shows that the indicators (HTML ...

What is the process for implementing hover transitions on link elements?

I am trying to incorporate a transition effect for my links. Essentially, I want the text-decoration (which is currently set to underlink) to gradually appear. Unfortunately, my previous attempt at achieving this has been unsuccessful: #slink{ transit ...

Issue with CKEditor within a ColorBox dialog box

Could someone please assist me? I am facing an issue with my HTML page where I have incorporated a ColorBox modal popup. Inside the ColorBox popup, there is a CKEditor. The problem is as described below: In Internet Explorer, the CKEditor functions proper ...

What is the best way to adjust the height of an IFrame to match the size of its content?

I attempted to set the height of an IFrame to 100% (similar to setting a <div> to height:auto). I specified the height attribute in the <iframe> tag as 100% and also set the height in the style to 100%, but it doesn't appear to be functio ...

Tips for effectively applying an image as a border

Just starting out with HTML and CSS here, and I'm trying to figure out how to use an image as a border for a div element. Can someone help point out my mistake? div { width: 240px; height: 510px; background-color: lightblue; border-image ...

Can a different div or HTML element be used in place of the text "Hello World"?

<body onload="myfunction('target')"><div id="target"> "Hey there!" </div></body> Can we replace the text "Hey there!" with another HTML element or div? This is currently a left-to-right marquee text. <script language= ...

Achieve perfect alignment of Bootstrap checkboxes

Is there a way to vertically align checkboxes in a column with their labels? My goal is to have these elements centered on the page, but I want the checkboxes themselves to be aligned vertically. <div class="row"> <div class="span12 paginatio ...

Verify the password by checking each character as you type

Currently, I am trying to implement a real-time password matching feature. Is there anyone who can provide me with the code that verifies whether the entered passwords match character by character as they are being typed, and also checks the length upon ...

Having issues displaying the & symbol in HTML from backend data

I recently worked on a project using express handlebars, where I was fetching data from the YouTube API. However, the titles of the data contained special characters such as '# (the ' symbol) and & (the & symbol). When attempting to render the ...

How come inactive links are still able to be clicked on?

I have been experimenting with various methods to disable links, but I seem to be unable to prevent them from being clickable. While I was successful in changing the cursor to 'not-allowed' when hovering over the disabled link, it still remains c ...

Bootstrap - Utilizing a boxed grid within a div located in the .fluid-container

Can you please review these two images? I'm trying to place ".myDivInTheGrid" inside a boxed bootstrap div. Any ideas on how to do this? This is what I currently have... <div class="fluid-container"> <div class="col-md-6"></d ...

I keep encountering an issue when trying to load the website <a href="linktext.com">linktext.com</a> using SQL and PHP

I recently encountered an issue while trying to retrieve data from an SQL database on a webpage using PHP. The process was interrupted whenever there was a hyperlink present in the SQL text data, such as linktext.com. I attempted to use HTML special chara ...

Creating a dynamic animation for a navigation bar's underline

I'm attempting to add a smooth underline effect to the links in my navbar when they are hovered over. Unfortunately, the entire ul element is being underlined instead of just the selected link. Is there a way to resolve this issue? a { text-deco ...

Conceal the element if the output of express is void

I am currently developing an app using nodejs and express. I am retrieving JSON data from an endpoint and displaying it on the page based on the values received. The issue I am facing is that if I receive a null or undefined value from the JSON data, how ...

Top methods for incorporating whitespace on both sides of the page

Currently working on a ReactJS/MaterialUI webapp and looking to enhance the layout. Seeking advice on whether it's best practice to add padding or margin to create space on the left and right side of the page, similar to popular websites like Stack Ov ...

How to keep a window/tab active without physically staying on that specific tab

Whenever I'm watching a video on a website and switch to another tab, the video stops playing. But when I switch back to the original tab, the video resumes. Is there a trick to prevent the video from stopping? I've already tried using scrollInto ...

Why is a <script> tag placed within a <noscript> tag?

Lately, I've been exploring various websites with unique designs and content by inspecting their source code. One site that caught my attention was Squarespace, which had blocks of <script> tags within a <noscript> tag: <!-- Page is at ...

Give a radio button some class

<input id="radio1" type="radio" name="rgroup" value="1" > <label for="radio1"><span><span></span></span>1</label> <input id="radio2" type="radio" name="rgroup" value="2" > <label for="radio2"><span ...

Transfer text from one form to a text field on a different website

I've created a form that allows users to input numbers in a field and then directs the page to a specific URL. Here's the code snippet: <html> <head> <meta charset="utf-8"> <title>Tracking</title> </head& ...