Escaping from its container, text breaks free with the power of CSS

Experiencing difficulties with CSS flex layout that are proving challenging to resolve.

HTML:

<div class="image-view">
    <div class="info">
        <span class="label title">d37ci4x.jpg</span>
        <span class="label scale">100%</span>
    </div>
    <img src="http://i.imgur.com/rfcsACA.png" />
</div>

CSS:

.image-view {
    display: inline-block;
    border: 1px #000 solid;
}

.image-view .info {
    display: flex;
    border-bottom: 1px #000 solid;
}

.image-view .info .title {
    overflow: hidden;
    white-space: nowrap;
    flex: 5 1 100%;
}

.image-view .info .scale {
    flex: 1 0 1em;
    padding-left: 2em;
    border-left: 1px #000 solid;
}

Result:

Access the live version at http://jsfiddle.net/omhaohyd/

Facing an issue where the "100%" text is unexpectedly shifting towards the right, extending beyond its container. Attempts to adjust padding have not resolved the issue - although shrinking the container moves the text closer to the left edge, it ultimately becomes too small, causing the text to overflow. Expanding the space allocated to .scale does solve the problem, but introduces excessive whitespace around the "100%", which is not the desired outcome.

This issue has been encountered in Firefox 30.0 on Lubuntu x64.

Answer №1

The reason behind this issue is the specific flex property being used for the .scale element: flex: 1 0 1em;. This property limits the width of the element to a maximum of 1em. When combined with the 2em left padding applied to the text, it causes the text to overflow the container.

To resolve this issue, consider removing the flex-basis property and setting it to auto, like so: flex: 1 0 auto: http://jsfiddle.net/examplelink

Answer №2

Here is a solution that should give you the desired result.

.image-view .info .scale {
    flex: 1 0 3em;
    padding-left: .5em;
    border-left: 1px #000 solid;
}

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

Steps for setting a background image behind radio buttons

I am currently facing a challenge in adding a background image to a div that contains some radio buttons and updating it dynamically with Angular based on the current page. app.controller('thingCtrl', function ($scope, $rootScope, $routeParams ...

Using the .each() method in jQuery to dynamically assign an attribute to a parent element in JavaScript

I'm new to JavaScript and jQuery and I need help transitioning my code from jQuery to pure JS. Within my HTML, there are multiple parent divs each containing a child div. My goal is to assign a class to both the child and parent elements, with the p ...

Toggle Form Section Visibility

I am working on a table with five rows that have upload buttons. Each time I submit a row, the page refreshes, but I want to hide all but one row at a time. When the first submit button is clicked, it should show the next row and hide the previous ones. Th ...

Located at the lower section of the parent container

In my flex container, I have two boxes arranged side by side (collapsing into one column on smaller screens). I've ensured that these boxes have the same height when displayed together, as shown in the image below: https://i.sstatic.net/ZjsfW.png No ...

What is the best way to delete the pipe separator from the initial item in a list on the line?

I have a list of items separated by pipes that spans multiple lines. I am looking to use jQuery to remove the pipe separator for the first item on each line. Example: Red | Green | Blue Purple | Black | White Violet | Yellow | Magenta Here is the code ...

How can I display a button (hyperlink) on a new line using CSS or jQuery?

I am looking to create a new line after the last input of my form. On this new line, I want to add a "remove-link". This is my HTML: <div class="subform dynamic-form"> <label for="id_delivery_set-0-price"> Price: </label> <inp ...

PHP comment form failing to process complete field inputs

Having some issues with a PHP comment form on my website. It's not sending all the inputted information from the fields. Any help would be greatly appreciated. This is the HTML code I'm using: <form method="post" action="assets/php/mail.php" ...

Use CSS bracket attribute to conceal link with no HTML access

I am unable to modify the HTML code, but I need to find a way to hide the link (#wall). <td class="status_value"><span class="online"> - <a href="#wall"> Leave a Comment </a> <a href="#today"> ...

Click event triggers the loading of a page

Recently, I found a simple jQuery event that loads a page into an iframe within the corresponding div when clicked. You can check out the JS Fiddle example here Now, my goal is to achieve the following: Instead of using separate codes for #fra ...

An issue has been identified where the checked selection feature is not functioning correctly for CSS selections

Is there a way to change the border color of a label when a checkbox is checked using CSS selectors? Here's an example of what I have tried: label{ width:36px; height:36px; padding:9px; border:1px solid gray; border-radius:36px; } #check ...

To fill the remaining white space, add an underline after the last line of text

I'm struggling to implement a SCSS/CSS styling concept where I need to add a solid line before or after the last line of a heading. The challenge is that the width of the last line varies based on the screen size. I am open to any suggestions. Here&a ...

Having trouble getting your Raspberry Pi web server to display the background image?

Recently, I successfully set up a LAMP server on my raspberrypi which was quite exciting. One of the first things I did was configure an FTP server to transfer webpage files to the Pi. I managed to create a basic form of the final webpage and transferred i ...

Why have the bars been positioned on the left instead of the right, and why does the mobile version require sliding instead of simply accessing the menu through a function?

Hello everyone, I'm currently working on designing a mobile-friendly header menu with the bars positioned on the right side of the screen. The goal is to utilize JavaScript to allow users to click either an 'X' icon or the bars to open the m ...

Turn off HTML display for Internet Explorer users

I am looking to implement code that will block certain pages for Internet Explorer users, making it accessible only for Google Chrome and Firefox users. Do you have any suggestions on how I can achieve this or if there are existing solutions available? I& ...

Recreate a null reference exception in a textbox following the action of clicking the Add button

How can I intentionally trigger a NullReferenceException in a textbox by changing its ID after clicking the Add button on the page? I have attempted to modify the textbox ID using developer tools before clicking the Add button, but the error is not thrown ...

Struggling to Collaborate with External PHP File Leads to Garbled Results

Recently started learning PHP and I'm pretty sure I have it set up correctly with my local IIS as I was able to use it in a form on another local website. For this particular project, I have a basic HTML file structured like this: <!doctype html&g ...

Style the CSS exclusively to the expanded menu section

I need help with applying CSS rules to my navbar menu without affecting the collapsed menu. I came across a solution here and tried using this code: @media (min-width: 980px) { /* your conditional CSS*/ } However, the issue arises when my browser win ...

Error message in Angular js: Unable to load file using XMLHttpRequest

Encountering an error while debugging an Angular JS application in the WebStorm IDE. The error message states: "XMLHttpRequest cannot load file:///C:/Users/../list.html. Cross origin requests are only supported for HTTP." Provided Javascript code : var a ...

Displaying the Selected Value from the DropDown in the Menu

I am working with Bootstrap5 and have the following dropdown menu in my code. Instead of displaying "Year," I would like to show which member was selected. How can I achieve this? <div class="dropdown"> <button class="btn btn- ...

Matching Figures to their Descriptions

I am currently working on a website and looking to include images with captions that display the price of each item underneath. The issue I'm facing is that the captions are aligning horizontally instead of vertically. Can anyone provide assistance wi ...