Tips for causing a single span tag within a group of multiple tags to overflow its parent element

Is there a way to make the highlight span sit just after the to without affecting the width of the parent, and without using absolute positioning? I would like the span to be aligned with the example "to" and overflow outside of the parent container.

Thank you for
your interest 
to Sign up to today's deals

.outer {
  width: 100%;
  height: 100%;
}
.parent {
  width: 260px;
  border: 1px solid #ccc;
  overflow: visible;
  font-size: 45px;
  line-height: 60px;
}

.overflowing-span {
  white-space: nowrap;
  display: inline-block;
}

.highlight {
  padding: 8px;
  background-color: gray;
  border-radius: 6px;
  font-size: 35px;
}
<div class="outer">
 <div class="parent">
  <span>Thank you for your interest to </span>
  <span class="overflowing-span">
    <span class='highlight'>Sign up to today's deals</span>
  </span>
 </div>
</div>

Answer №1

One way to handle the situation if there is no further content after the <span> is to set its width: 0, although this approach is quite similar to using position: absolute:

.outter {
  width: 100%;
  height: 100%;
}
.parent {
  width: 260px;
  border: 1px solid #ccc;
  overflow: visible;
  font-size: 45px;
  line-height: 60px;
}

.overflowing-span {
  white-space: nowrap;
  display: inline-block;
  width: 0;
}

.highlight {
  padding: 8px;
  background-color: gray;
  border-radius: 6px;
  font-size: 35px;
}
<div class="outter">
 <div class="parent">
  <span>Thank you for your interest to </span>
  <span class="overflowing-span">
    <span class='highlight'>Sign up to today's deals</span>
  </span>
 </div>
</div>

If you are open to making slight adjustments to your HTML, here's a more appropriate method using the HTML entity &NoBreak;. Additionally, you need to change the display property of your span to inline:

.outter {
  width: 100%;
  height: 100%;
}
.parent {
  width: 260px;
  border: 1px solid #ccc;
  overflow: visible;
  font-size: 45px;
  line-height: 60px;
}

.overflowing-span {
  white-space: nowrap;
  display: inline;
}

.highlight {
  padding: 8px;
  background-color: gray;
  border-radius: 6px;
  font-size: 35px;
}
<div class="outter">
 <div class="parent">
  <span>Thank you for your interest to</span>&NoBreak;<span class="overflowing-span">
    <span class='highlight'>Sign up to today's deals</span>
  </span>
  <span>right NOW.</span>
 </div>
</div>

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

Error: The PDFJS variable is not recognized when trying to load a PDF file

I've been experimenting with pdf.js to load PDFs into a web application in order to extract information in real-time. However, I keep encountering an error even with a simple example. I've attempted enclosing the code in $(document).ready() as a ...

Utilizing window.matchMedia in Javascript to retain user selections during page transitions

I am encountering difficulties with the prefers-color-scheme feature and the logic I am attempting to implement. Specifically, I have a toggle on my website that allows users to override their preferred color scheme (black or light mode). However, I am fac ...

The width of the unordered list is not what I defined

when I set this line: <ul style="width:100px; height:100px; background-color:green"> <li style="width:100px; height:100px; border:1px solid blue"> 1 </li> </ul> The ul ends up wider than my specified 100px width. Any thoughts ...

Bootstrap component malfunctioning and not performing as expected

Currently, I am learning how to use Bootstrap and attempting to replicate the example themes found on their official website. The specific theme I am focusing on is available at this link: https://getbootstrap.com/docs/4.3/examples/pricing/ Unfortunately, ...

Need assistance posting on Twitter? Utilize PHP for a solution!

I'm attempting to share a user-generated and dynamic URL on Twitter, but I'm having trouble with the encoding... <a href="http://twitter.com/?status=[urlencode('I'd like to borrow this item @neighborrow')].">TWEET THIS REQUE ...

CSS slider thumb with visible track behind it

Looking at the images below, or visiting , you can notice that the slider track is visible behind the slider thumb. Check out the images here: Image 1 and Image 2. The CSS for my slider looks like this: input[type=range] { appearance: none; backgro ...

Can you override CSS background image styles to ensure both images are loaded?

Suppose there are 2 CSS styles that assign background images to an element, and one style overrides the other. In this scenario, will both images be downloaded by the browser or just the overriding one? I am asking this because I recently participated in ...

The list style of Bootstrap Select Drop Down isn't vertical

Has anyone encountered an issue with bootstrap-select where the options in a drop down box are not vertically listed? <script src="{% static 'risk_parity/js/jquery-3.2.1.min.js' %}"></script> <script src="{% static 'r ...

The Masonry Grid is leaving empty spaces unfilled

I've been experimenting with Sveltekit and SCSS to create a Masonry grid. However, I'm facing an issue where the items in my grid are not filling in the empty space as expected. Instead, they seem to be following the size of the largest image, le ...

A useful Javascript function to wrap a string in <mark> tags within an HTML document

I have a paragraph that I can edit. I need to highlight certain words in this paragraph based on the JSON response I get from another page. Here's an example of the response: HTML: <p id="area" contenteditable> </p> <button class="bt ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

Ensure that the central section of the slider remains illuminated

Looking for help with customizing my "product" slider, lightSlider. I want the middle div to always be highlighted when navigating through the slider. Here's what it looks like currently: Link to screenshot - current. My goal is to achieve this look: ...

Is it possible for a website to be compromised by incorporating CSS within HTML code?

I'm currently working on developing a shopping cart component in React, but my supervisor has advised against using CSS directly in the HTML markup due to security concerns. While I understand the importance of good coding practices, I fail to see how ...

What could be causing my button to be elongated in a vertical direction when a logo image is present

I am currently utilizing tailwindcss for my project. Within a flexbox container, I have placed a login button which appears to be stretched out. <nav font-am class="m-6 text-xl"> <div class="flex flex-row justify-between conta ...

Unexpected behavior observed when animating CSS transform in IE

I am currently facing an issue with a CSS animation on my website that animates an arrow back and forth. The animation is working perfectly on all browsers except for Internet Explorer, where there seems to be a glitch causing the Y position of the arrow t ...

Issue with CSS background color not extending to full screen in webkit browsers when using 960.gs grid system

When using 960.gs, I have created a login screen with a div for the login form that has a background image. This div is positioned below a header, which centers it in the browser window. In my CSS, I am setting the body color as follows: body { backgr ...

What is the best way to set the z-index for elements within CSS containers that are utilized for container queries?

I am thrilled about the introduction of container queries in CSS. It's great to see this feature now available across all browsers. However, I have encountered an issue when working with multiple consecutive containers and placing an absolutely positi ...

Events Unavailable for Viewing - Full Calendar - Database Error Encountered

I am currently developing a calendar application. While I have managed to successfully display the calendar and add events, I am facing an issue with displaying events on the monthly view. Here is a snippet of the HTML code being used: <head> &l ...

Is it possible to use the same identifier for both the name and id attributes in HTML?

In the world of coding, the "name" attribute is often used in server-side programming to send name/value pairs in requests. On the other hand, the "id" attribute is commonly utilized in client-side programming such as Javascript and CSS. However, both att ...

Tips on extracting code differences from code inspector

Utilizing the Chrome code inspector is extremely valuable, but I often find it challenging to track the modifications made to CSS and HTML live. This becomes particularly cumbersome when there are multiple tags being modified. Are there any Chromium exten ...