Incorporate the child's width into the parent's content

Struggling to come up with a title, but my jsfiddle should clear things up:

https://jsfiddle.net/1btr7mkq/

<div class="blabla">
  Bla bla bla blalblabl bla bla bla bla bla
  <div class="questionMark">?</div>
</div>

When resizing the output window, I noticed that the question mark sometimes falls onto the second line, while the "blablas" remain on one line.

https://i.sstatic.net/RTZf8.png

How can I prevent this from happening? I've thought of two potential solutions: The first involves setting a "reserved" width on the right side for the question mark. This way, if the text gets too close to the edge, it will drop down. The second, more ideal solution eliminates the need for reserved width on the right side. The lines above the last one can use the full width and won't break prematurely. In this scenario, the page would need to detect when the question mark has jumped lines and add a blank line below its own content.

I've attempted a few strategies but none have achieved the desired outcome.

Answer №1

-If you're searching for this, simply delete Float:right and include display:inline -After the completion of the Question, the Question mark will consistently appearhttps://i.sstatic.net/T9Hsd.jpg

Answer №2

To position the image in the upper right corner of the container, place the DIV with the question mark at the beginning of the container DIV and use float: right. This allows the text to flow left and below it:

<div class="content">
  <div class="questionMark">?</div>
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

Learn more about this technique.

Answer №3

This is the primary reason behind the development of flexbox.

.title {
  display:flex;
  background:beige;
  }
.blabla{
  flex-shrink:1;
  flex-grow:1;
  }
.questionMark{
  background:blue;
  color:white;
  border-radius:10px;
}
<div class="title">
  <div class="blabla">Bla blabla bla</div>
  <div class="questionMark">?</div>
</div>

  • flex-grow empowers the element to utilize more space if accessible.
  • flex-shrink empowers the element to utilize less space if not available.

Answer №4

Are you looking for this? click here

.questionMark{
    background-color: green;
    border-radius: 50px;
    display:inline-block;
    color: black;
    padding: 5px 10px;
    cursor:pointer;
}

Answer №5

  .blabla{
       border: 1px solid #888;
       background-color:#ffffef;
       border-top-left-radius: 10px;
       border-top-right-radius: 10px;
       font-size: 2em;
       padding: 3px 30px;
       position:relative;
       padding-right:50px;
   }
 .questionMark{
      background-color: blue;
      border-radius: 100px;
      clear: both;
       color: white;
      padding: 0 8px;
      cursor:pointer;
      position:absolute;
      right:20px;
     top:3px;   
    }

This solution is perfect for your needs

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

The carousel top position in Bootstrap 4 is not functioning properly

I am struggling to get the teal rectangle to move to the top of the carousel. I have set my carousel to have a position relative and my teal rectangle to have a position absolute with top="0", but it doesn't seem to be working properly. Instead of mov ...

The styles from the base.css file are not being implemented in the Django project

I currently have a folder structure that looks like this: https://i.sstatic.net/a4nYD.png My goal is to import base.css into base.html so that it is applied globally: Here is my HTML: <!DOCTYPE html> {% load static %} <html> <head> ...

How can PHP be used to display a varying number of items in a slider depending on the size of the screen?

I am currently utilizing media queries to adjust the layout of my website. My query is: How can I display a different number of items in a slider based on the screen size? For small screens, I have included the following code: <?php if($i == 4) {echo ...

Convert the image presentation to be inline

I am currently working on an image slider and I'm having issues with displaying the images inline. I have applied CSS but unfortunately, it's not working as expected. The images are not being displayed inline. Can someone please advise on what pr ...

What could be causing my content to disappear behind the header while in compatibility mode?

Is there a solution to prevent content from disappearing behind a fixed header when running a layout in compatibility mode? To see the issue, visit the jsfiddle here and switch to compatibility mode in Internet Explorer. The layout behaves properly in Chr ...

The image slideshow on W3 Schools displays images in a stacked formation

Utilizing this code snippet from W3 Schools to incorporate an image slideshow into my web project. However, upon page load/reload, the images appear stacked vertically rather than horizontally (one above and one below). The slideshow functions properly aft ...

What is the best way to create a responsive design that positions an element between two others?

There are two types of elements in my project: Type "A" - a text block Type "B" - a graphical block I am looking to create a responsive layout for these elements. On small resolution screens, I want them to be arranged like this: "A" "A" "B" ...

Tippy.js tooltips are not adapting to CSS styling as expected

My experience with tippy.js in my browser had been smooth until this morning. All of a sudden, they stopped responding to any CSS styling and simply defaulted to a dark grey background with border radius. However, they still respond to changes in the scrip ...

Create a bokeh plot and save it as an HTML file without displaying it

Currently, I am utilizing Bokeh to generate HTML code that contains figures by employing the show method. However, this method automatically opens the default browser with the HTML displayed in it. My goal now is to save the HTML code without displaying i ...

Sending a value to CSS using a selector

Can CSS be instructed to implement a selector with a specific value that acts as a variable? For example: -- HTML -- <div class-name="div-3"></div> -- CSS -- .div-(x) { width: 100px * x; } ...

Hovering over the Laravel Breeze dropdown will activate a dropdown feature

Recently, I've been working on a project with Laravel Breeze and have been utilizing some default components. The dropdown component used in the navigation bar caught my attention. By default, it requires a click for the menu to drop down below. Howev ...

Incorporating .txt files into a static webpage using only HTML and JavaScript

Exploring the realm of web page creation for the first time has left me in need of some guidance. I have successfully added an upload feature for text files on my web page, but I am struggling to embed a text file directly into the page source. With Java s ...

Hide the footer DIV in CSS by making it disappear with a height of 100%

I'm currently facing an issue with my CSS layout. Despite managing the problem in IE and seeing everything work well, the footer container has mysteriously disappeared! I've attempted to recode the CSS without success, even after trying for days ...

Verify the status of the internet button and display a message indicating whether it has been selected or not

I’ve been attempting to complete this task: opening this particular page in Python, and observing the outcome when the "Remote eligible" button is enabled; do any job positions appear or not? Here's the code I have so far, but it keeps throwing thi ...

Rearrange the order of items on mobile devices

I currently have a row in Bootstrap with two columns that stack on top of each other for larger screens. However, the order of the columns is reversed on desktop, with 'one' appearing before 'two'. Is there a simple way to rearrange the ...

Shades of Grey in Visual Studio Code

Whenever I use VSC, I notice these odd grey boxes that appear in my editor. They seem to be dynamic and really bother me. Interestingly, switching to a light theme makes them disappear. However, I prefer using a dark theme and haven't been able to fin ...

Issue with Modal Box: Datepicker not Displaying Correctly

I have implemented a modal box in my webpage. When I click on a text field where a datepicker is added, it does not display anything. However, when inspecting the element using Chrome's developer tools, I can see that the 'hasDatepicker' cla ...

Why is this strange red dot character 🔴 appearing in the URL in FireFox?

While browsing the web, I came across a website with a strange red blob in the URL. It's something I've never seen before. What could possibly be the reason for this unique feature?! Note that you have to visit the page to see it for yourself. T ...

Attempting to align three images in a row on a webpage with clickable links placed below using HTML and CSS

Shown below is a snippet of the HTML code I am currently working with: div.Navbar { margin-left: 10px; margin-right: 10px; } .icons { height: 300px; } <div class="NavBar"> <img src="images/ThumbNails/Conflict.jpg" class="icons" style="f ...

The display of prime numbers is not functioning in this JavaScript code

I've been diving into JavaScript lately and I'm currently working on displaying prime numbers. However, I'm encountering an issue where the output is not showing up. Can someone lend a hand? I seem to be stuck. Here is my initial code snipp ...