What is the best way to create a dynamic width in CSS while implementing Bootstrap's responsive layout?

Using Bootstrap's responsive design, I am facing an issue with a bubble that needs to fit fluidly but sticks out when the width is narrow. How can I address this problem so that it fits in any width?

Demo http://jsfiddle.net/SAKWb/

HTML

<div class="chat">

<table>
  <tbody>
     <tr>
               <th>Body</th>
     </tr>



    <tr id="comment_617">
            <td><div class="bubble me"><span class="text-error">01-10 03:29</span>:Person A<br>
            bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
            <form action="/shop/walmart/posts/617" class="button_to" data-remote="true" method="post"><div><input name="_method" value="delete" type="hidden"><input data-confirm="Are you sure?" data-disable-with="deleting..." value="destroy" type="submit"><input name="authenticity_token" value="aoLKQnl4M2SWVlOrXGR+qIMLSeY5m1tKiC/PSnYQjmw=" type="hidden"></div></form>
            </div></td>
    </tr>




    <tr id="comment_615">
            <td><div class="bubble me"><span class="text-error">01-10 03:25</span>:Person A<br>
            bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
            <form action="/shop/walmart/posts/615" class="button_to" data-remote="true" method="post"><div><input name="_method" value="delete" type="hidden"><input data-confirm="Are you sure?" data-disable-with="deleting..." value="destroy" type="submit"><input name="authenticity_token" value="aoLKQnl4M2SWVlOrXGR+qIMLSeY5m1tKiC/PSnYQjmw=" type="hidden"></div></form>
            </div></td>
    </tr>
</tbody>

 <div>

CSS

.chat {
    width: 100%;
    min-width: 300px;
}

.bubble{
    background-color: #FFFFFF;
    border-radius: 5px;
    box-shadow: 0 0 6px #B2B2B2;
    display: inline-block;
    padding: 10px 18px;
    position: relative;
    vertical-align: top;
    word-break: break-all;
}

.bubble::before {
    background-color: #FFFFFF;
    content: "\00a0";
    display: block;
    height: 16px;
    position: absolute;
    top: 11px;
    transform:             rotate( 29deg ) skew( -35deg );
        -moz-transform:    rotate( 29deg ) skew( -35deg );
        -ms-transform:     rotate( 29deg ) skew( -35deg );
        -o-transform:      rotate( 29deg ) skew( -35deg );
        -webkit-transform: rotate( 29deg ) skew( -35deg );
    width:  20px;
}

.me {
    float: left;   
    margin: 5px 45px 5px 5px;
    min-width: 250px; 
    width: 100%;      
}

.me::before {
    box-shadow: -2px 2px 2px 0 rgba( 178, 178, 178, .4 );
    left: -9px;           
}

.you {
    float: left;    
    margin: 5px 10px 5px 5px;
    min-width: 250px;
    width: 100%;          
}

.you::before {
    box-shadow: 2px -2px 2px 0 rgba( 178, 178, 178, .4 );
    right: -9px;    
}

Answer №1

The bubbles are extending beyond the gray background due to excessive padding defined in the .hero-unit class.

.hero-unit {
padding: 15px;  /*Reduced from 60px*/
...
}

To address this issue, adjust the width of the bubble by reducing it from 100% to accommodate the 15px padding.

.me {
float: left;
margin: 5px 45px 5px 5px;
min-width: 250px;
width: 85%;  /*Changed from 100%*/
}

If keeping the 60px padding is necessary, ensure that the width of .me is adjusted accordingly to prevent overflow beyond the gray background.

Answer №2

To maintain the padding that is causing the bubbles to shift to the right, adjusting the widths of the .bubble and .chat elements to a smaller percentage prevents them from protruding.

If you prefer not to keep the .chat area at 30% width all the time, consider using media queries.

For instance:

@media (min-width: 500px) {.chat{width:50%} .bubble{width:40%}
@media (min-width: 300px) {.chat{width:30%} .bubble{width:30%}

These specific percentages may not be suitable for your layout, but experimenting with different values can help achieve a visually appealing design across various screen sizes while preserving the existing structure.

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

Tips for perfectly centering a light box and concealing a scrollbar

Hello, I'm a web designer and facing an issue with the alignment of my lightbox. The lightbox is not center aligned on any resolution, which is causing some trouble. I have also added a black overlay for transparency in the background, but it's s ...

I desire to showcase the information in a manner that coincides with the specific button that is being hovered over by

My data is stored in JSON format and I am using ng-repeat in AngularJS. When a specific button on the navbar is hovered over, I want it to display the corresponding details. Any assistance would be greatly appreciated. ...

How to prevent table row from highlighting on hover in Angular Bootstrap

In my project, I have a table that showcases various details and allows users to select certain rows. Some of these rows have child rows which can also be selected. The requirement is for the parent rows to be selectable only if they do not have any child ...

Tips on using b-table attributes thClass, tdClass, or class

<template> <b-table striped hover :fields="fields" :items="list" class="table" > </template> <style lang="scss" scoped> .table >>> .bTableThStyle { max-width: 12rem; text-overflow: ellipsis; } < ...

CSS: Basic yet effective image display showcase

Web development is not my main focus, but when I delve into it, CSS always presents a frustrating challenge. My goal is to create a basic class that combines images with descriptions in a structured manner. Specifically, I aim to display two rows, each con ...

Creating a Visual Presentation with Background Image Transition in HTML, CSS, and JavaScript

Seeking assistance in setting up a basic background image slideshow on my website. I have been unable to locate a suitable tutorial online, so I'm reaching out here for guidance. HTML: <body> <h3>Welcome!</h1> <p>Lorem i ...

The header, main content, and footer sections expand to occupy the entire page

I am in need of HTML structure that looks like the following: <header></header> <div id='main'></div> <footer></footer> I want all elements to be positioned relatively. The header and footer will have fixed h ...

tips for automatically adjusting the height and width of an image within a div

I'm struggling with fitting an image that is 1587*666 into a div that has a height of 600px and width of 300px. Can someone provide me with an example to achieve this?https://i.sstatic.net/4SWi5.jpg Here's the code snippet: <div id="myDiv" s ...

Toggle menu using jQuery to show and hide options

I'm currently working on a menu that should open when the button is clicked once and close when clicked again. I had done this before but I seem to have forgotten how to achieve it. Here is the code snippet that I tried to use: var main = function() ...

`Web scraping with BeautifulSoup presenting an issue with href tags`

I've been working on a web scraping project, but I'm facing challenges extracting href links from a particular webpage. The URL in question is . My goal is to gather all the article links using the href attribute. Below is an example of the link ...

The issue with CSS right alignment not functioning as expected

My attempt to align text to the right using a CSS rule is not working as expected when applied to a font within a cell. Can anyone help me troubleshoot this issue? Take a look at my code snippet below: CSS: .font1 { font-size: 60px; text-align: ...

Parent div's overflow due to its flexbox properties

I am currently facing a dilemma with my nested flexbox setup. The primary objective is to create two responsive columns: .ColWrap, { width: 100%; box-sizing: border-box; background-color: #fff; padding: 50px 10px 50px 25px; display: fl ...

What is the best way to adjust the footer width to match the sidebar using Bootstrap 5?

Currently working on a Bootstrap 5 template for my website, but being new to it makes it a bit challenging. Specifically struggling with aligning the footer to fit the full width of the sidebar. <!DOCTYPE html> <html lang="en"> <head&g ...

Designing CSS for devices with specific aspect ratios below a defined threshold

My mind is malfunctioning. Is there a way to target devices with a device aspect ratio less than 16/9, meaning wider than 16/9? I can't seem to get this code working correctly. This is specifically for portrait mode within an iOS/Android cordova app ...

Eliminating the border around a textarea in HTML

Currently, I am dealing with the textarea tag in HTML and am trying to eliminate the border surrounding the box. Additionally, I am aiming to position the text at the bottom of the textarea. ...

Turn off smooth scrolling in Bootstrap 5 using HTML and CSS techniques

On my website, I have implemented anchor links that activate smooth scrolling when clicked, thanks to the Bootstrap feature. However, the unique layout of my website requires me to turn off smooth scrolling in either the HTML or CSS code. I appreciate an ...

Swapping link positions with jQuery

Is it possible to rearrange links using jQuery? Under the navigation menu, there will be content div for each tab. The selected link should always be positioned next to the first "sixrevision" link. The code snippet is shown below: <ul id="crumbs" ...

Create a layout with three columns, each containing four list items

My unordered list (ul) has 4 li's and I'm trying to create 3 columns. However, when I have 4 li's, it only displays as 2 columns. How can I achieve a layout with 3 columns and 4 li's? Additionally, I want the li elements to be arranged ...

Preventing image rotation in an Angular 4 application: Strategies and Solutions

My Angular application allows users to choose a profile picture. During testing, I discovered that when I upload images from an iPhone in portrait mode, they appear rotated in my app. However, when the photos are taken in landscape mode, they display corre ...

Problematic rendering of Bootstrap Navbar Toggle

As I work on creating a WordPress theme using Bootstrap 3, I encountered an issue with the navbar toggle when reducing the screen width for testing. The image displayed doesn't align with what I expected. While I suspect it might be a WordPress-relate ...