The inline-table display is not functioning properly when the content width is limited

The challenge I'm facing involves designing CSS for a web application centered around photo uploads displayed as polaroids. Each photo is encased in white padding, with extra padding at the bottom and the design adapts responsively.

If a user adds a caption to their photo, it should appear within the polaroid at the bottom, adjusting the whitespace accordingly to accommodate text length - all managed through CSS.

However: When photos are scaled down, particularly in thumbnail sizes, the polaroid effect breaks down causing text overflow issues. I need assistance in preserving the style integrity for smaller image dimensions. It would be great to have an example illustrating this, preferably using well-supported CSS 2.1 attributes since a significant number of my users rely on browsers like Opera Mini with limited CSS3 or JS support.


Two examples of correct layout:

1) Thumbnail:

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

2) Full-size image:

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


Two examples of incorrect layout:

1) Thumbnail of the full-sized image above:

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

2) Another thumbnail:

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

Note that these thumbnails display correctly without a caption, such as:

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


Here's an excerpt from the CSS styling:

.mbs {
    margin-bottom: 0.5em;
}

.bw {
    word-wrap: break-word;
}

.polaroid {
    text-align: center;
    background-color: #ffffff;
    display: inline-block;
    padding: 10px;
    border-radius: 6px;
}

.sh-l {
    -webkit-box-shadow: -2px 2px 2px #90C0B0; 
    -moz-box-shadow: -2px 2px 2px #90C0B0;
    box-shadow: -2px 2px 2px #90C0B0;
}

.inner-img {
    display: block;
    margin: 0 auto;
    margin-bottom: 20px;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.img-caption {
    display: table-caption;
    caption-side: bottom;
    width: 100%;
}

.cgy {
    color: grey;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
    margin-bottom: 0.5em;
}

Below is a section of the HTML code:

<div class="mbs polaroid sh-l" style="padding:5px">
    <div style="display: inline-table;">
        <img src="{{ img_url }}" height="38" class="mbs inner-img" style="border-radius:4px;margin-bottom: 8px;" alt="photo">
        {% if img_caption %}<div class="cgy bw img-caption"><bdi>{{ img_caption }}</bdi></div>{% endif %}
    </div>
</div>

Please disregard {{ and {%, as they are part of the Django template syntax. While this code has been effective so far, I am open to making adjustments if necessary.

Answer №1

The browser is set to word-wrap: break-word, meaning it only breaks lines at word boundaries. For your desired effect, use word-break: break-all instead, which allows words to be split as needed.

Answer №2

When styling text, it's important to use word:break: break-all instead of word-wrap:break-word;. One option breaks the string at a word level while the other breaks it at the letter level, which may not be desired. This error is common among developers working with CSS. I must admit, I've made this mistake myself too :)

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

Why is my output getting mixed up with the header on the navigation bar page?

output capture image https://i.sstatic.net/BYJnk.jpg here is the code snippet //ui.r library(shiny) navbarPage(theme = "style.css",img(src="logo.jpeg", width="300px"), tabPanel("Dashboard"), tabPanel("Products"), tags$head( t ...

Why is the label on my styled checkbox shifting position?

While custom styling a checkbox, I'm facing an issue where the label next to it keeps shifting. When unchecked, it aligns itself at the bottom of the box, but upon checking, it moves to center align with the box. .check { width: 100%; font-we ...

The height of the div is set to zero within the $(document).ready() function

From what I understand, when we write JQuery code inside $(document).ready(), the code will only be executed after the DOM has finished rendering. I encountered an issue where I was trying to calculate the height of a div inside $(document).ready() but it ...

Can this functionality be accomplished using only HTML and CSS, without relying on JavaScript?

Image for the Question Is it possible to create a zoom functionality using only HTML and CSS, without relying on JavaScript? I need this feature for a specific project that doesn't support JavaScript. ...

Adjusting the heights of all elements with identical ids simultaneously

I found the following code: <div xmlns="http://www.w3.org/1999/xhtml" style="z-index: 1; position: absolute; top: 90px; left: 90px; background: none repeat scroll 0% 0% black; width: 800px;" id="mainDiv"> <div style="width: 405px;" class= ...

Experience full-screen viewing by double-clicking without the distraction of video controls (WordPress/HTML5)

I've been tasked with creating a video thumbnail that, when clicked, will lead the user to a new page where a single autoplaying and looping mp4 video will be shown. The issue arises when I can't interact with the video because the controls are h ...

Update the CSS appearance? (Redraw page)

I recently ran into a strange issue while working on an app using Cordova (Phonegap). The styling of many elements in the app depends on the class I set on the body element. For example: .gray .background{ background: gray; } .gray .title{ color: ...

Using jQuery to apply CSS with relative percentage values (+=/-=/)

Today, I experimented with using relative values in jQuery's .css() function. $block.css({'margin-left': '-=100%'}); This resulted in the following style for the div: <div class="block" style="margin-left: -100px;"> I not ...

Ensure that the footer is always positioned at the bottom of the page according

I've been struggling to get my footer to stay at the bottom of the page based on content. I've tried several CSS techniques and strategies, but I'm still encountering one issue. footer { width: 100%; padding: 25px 0 25px; backgr ...

Set the CSS table to have a width of 100% and ensure that the table data cells have hidden

My table has a 100% width, and some of the td elements have overflow hidden. I want to make their text appear as ellipsis when it's too long. I can achieve this with fixed td sizes, but I need them to be relative to the content. This question was fi ...

Animate CSS Grid to dynamically fill the viewport on top of current grid elements

Please note that I am specifically seeking vanilla JS solutions, as jQuery is not compatible with this project I have a grid structure that is somewhat complex: body { margin: 0; height: 100vh; text-align: center; } .grid-container { ...

Developing a Dynamic Table Featuring Information Pulled from a phpmysql Database

I am exploring ways to make the table below, which displays data from a MySQL database, responsive so that it can adjust to smaller devices without compromising the image quality. Currently, I am delving into Bootstrap to understand its capabilities bett ...

How to style 1 out of every 3 div elements using absolute positioning in CSS

Imagine a setup where there is a banner at the top, with 3 divs placed side by side underneath it. The interesting part is that when you scroll down, only the center and right div should move along. #banner { background:blue; color:white; position ...

"Integrating backgrounds into divs disrupts the overall design aesthetic

One of the challenges I faced was trying to space out the three columns in my Bootstrap row while also splitting each column into two parts. After doing some research, here's the solution I came up with: <div class="container row h-100 mx-auto ...

Exploring CSS Shapes: Unveiling the secrets behind the star. What's the mechanism at

https://i.stack.imgur.com/0BgQr.png Take a look at the code snippet below showcasing The Shapes of CSS. I'm interested in delving into the intricacies of these CSS properties. How exactly do shapes in CSS function? This includes pseudo CSS, borders, ...

Express Node + Styling with CSS

I am in need of a single EJS file (configuration includes Express and Request). app.get('/space', function(req, res){ res.render('space.ejs'); }); The file successfully renders, but only two out of three CSS stylesheet links work ...

Is there a way to keep my fixed footer container from moving while zooming in and out on a webpage

Is there a way to prevent the bottom text from shifting when zoomed in or out on the page? The rest of the content remains stable, but due to using position:absolute for this section to stay at the bottom of another div (content), it causes movement. #con ...

Tips for achieving a similar stroke and shadow effect using CSS

I'm struggling to achieve the desired effect with strokes, so I need some CSS advice. I also experimented with adding shadow to text: body { color: #000; -webkit-text-fill-color: #030303; -webkit-text-stroke-width: 0px; -webkit-text-stroke- ...

Positioning a Safari browser relative to a flex container

Seeking assistance with positioning elements in Safari 602.1 on iOS 10 using Bootstrap 4.1. The text isn't positioned correctly, even after auto-prefixing Bootstrap. The issue only occurs in Safari; everywhere else, it works fine and I'm at a lo ...

Hide the accordion panel that is not actively being viewed as another one opens

Looking for a way to collapse an accordion panel when another one opens using vanilla JavaScript? Specifically, the solution needs to work in IE11. I am a JavaScript beginner and would greatly appreciate any help or guidance you can offer. Thank you. va ...