Unable to contain Bootstrap 4 dropdown text within a div

I have spent countless hours trying to solve this issue and I am feeling quite desperate at this point. The task at hand is creating a notification dropdown in Bootstrap 4. Despite trying numerous approaches, none seem to be effective. The dropdown should resemble the following:

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

However, I am encountering difficulties with the text and date placement. They are overflowing outside the dropdown like so:

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

I experimented with line breaks, but they proved ineffective. Unfortunately, I encountered issues getting Bootstrap to function in the snippet, so I apologize for that.

.heading {
    color: #747F8B;
    font-size: 14px;
}

.highlight {
    font-weight: bold;
}

.dropdown-item-style {
    background-color: #e9eff2;
    padding: 15px;
}

.dropdown-item-style:hover {
    background-color: lightgrey;
    color: #ffffff;
}

.triangle {
    position: absolute;
    top: -8px;
    left: 134px;
    height: 15px;
    width: 15px;
    border-radius: 6px 0px 0px 0px;
    transform: rotate(45deg);
    background: #FFF;
}

.dropdown-title {
    color: #747f8b;
    font-weight: bold;
    border-radius: 10px 10px 0 0;
    padding-left: 15px;
    padding-right: 15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

<li class="nav-item dropdown icondropdown " id="notification-dropdown">
  <a href="#" class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    <i class="fa fa-bell-o navbar-icons" aria-hidden="true"></i><span class="noti-navbar-badge">3</span>
  </a>
  <div class="dropdown-menu dropdown-menu-center z-depth-1" aria-labelledby="navbarDropdown" style="width: 300px; padding-bottom: 0; top: 70px; border: none; padding-top: 5px;">

    <span class="triangle"></span>
    <a class="dropdown-item dropdown-title">
      <span class="heading">Notifications</span><span class="float-right" style="font-size: 14px;">Settings</span>
    </a>

    <div class="dropdown-divider m-0" style="border-color: lightgrey"></div>

    <div class="dropdown-item dropdown-item-style" href="#">
      <div class="row">
        <div class="col-md-2">
          <img src="img/johan.jpg" class="rounded-circle" width="32">
        </div>
        <div class="col-md-10">
          <a href="">
            <span class="highlight" style="line-break: auto">Bill Gates</span> liked your post.
          </a>
          <small class="text-muted">5 days ago</small>

        </div>
      </div>

    </div>

    <div class="dropdown-divider m-0" style="border-color: lightgrey"></div>
  </div>
</li>

Answer №1

One issue is that the .dropdown item has a style of .white-space: nowrap; which prevents the words from breaking into new lines. To solve this, I will place the notification in a span and set white-space: normal for it, adding a new class 'more-info'. Additionally, I will remove the flex-wrap: nowrap; from the row containing the notification to ensure the text is positioned close to the image:

.heading {
    color: #747F8B;
    font-size: 14px;
}

.highlight {
    font-weight: bold;
}

.dropdown-item-style {
    background-color: #e9eff2;
    padding: 15px;
}

.dropdown-item-style:hover {
    background-color: lightgrey;
    color: #ffffff;
}

.triangle {
    position: absolute;
    top: -8px;
    left: 134px;
    height: 15px;
    width: 15px;
    border-radius: 6px 0px 0px 0px;
    transform: rotate(45deg);
    background: #FFF;
}

.dropdown-title {
    color: #747f8b;
    font-weight: bold;
    border-radius: 10px 10px 0 0;
    padding-left: 15px;
    padding-right: 15px;
}
.dropdown-item .more-info {
    white-space: normal;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

<li class="nav-item dropdown icondropdown " id="notification-dropdown">
  <a href="#" class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    <i class="fa fa-bell-o navbar-icons" aria-hidden="true"></i><span class="noti-navbar-badge">3</span>
  </a>
  <div class="dropdown-menu dropdown-menu-center z-depth-1" aria-labelledby="navbarDropdown" style="width: 300px; padding-bottom: 0; top: 70px; border: none; padding-top: 5px;">

    <span class="triangle"></span>
    <a class="dropdown-item dropdown-title">
      <span class="heading">Notifications</span><span class="float-right" style="font-size: 14px;">Settings</span>
    </a>

    <div class="dropdown-divider m-0" style="border-color: lightgrey"></div>

    <div class="dropdown-item dropdown-item-style" href="#">
      <div class="row">
        <div class="col-md-2">
          <img src="img/johan.jpg" class="rounded-circle" width="32">
        </div>
        <div class="col-md-10">
          <a href="">
            <span class="highlight" style="line-break: auto">Bill Gates</span> <span class="more-info">liked your message.</span>
          </a>
          <small class="text-muted">5 days ago</small>

        </div>
      </div>

    </div>

    <div class="dropdown-divider m-0" style="border-color: lightgrey"></div>
  </div>
</li>

Answer №2

insert

.yourclassname{
       overflow:visible;
       white-space:normal;
}

adjacent to the '.col-md-10' class within the '.dropdown-item' element

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

When a click event triggers, use the .get() method in jQuery to retrieve the content of a page and then update

I am currently facing an issue with a div class="contentBlock", which is acting as the container for updating content. <div class="contentBlock"></div> Unfortunately, the script I have written does not seem to be working properly :c $(docume ...

Item 'unreachable' displayed in Firefox console

I am working with several divs that have the class='class_name'. I have also defined var A = document.getElementsByClassName('class_name'); console.log(A[0]); Upon checking in the Chrome console, it displays: <div class="class_n ...

jQuery Mobile is experiencing page height inaccuracies

My web application, built with jQuery Mobile 1.2.0, is encountering an issue with page height calculations on Windows Phone. While iOS and Android display correctly, there is a gap at the bottom of the page on Windows Phone. Is there a CSS-only solution t ...

Access within the identical window (PHP file) as opposed to an Iframe

I am currently working with a PHP file that retrieves data from my database. <?php $cdb = new PDO('mysql:dbname=xxx;host=localhost', 'xxx', 'xxx'); foreach ($cdb->query("SELECT * FROM images ORDER BY posted DESC LIMIT ...

The lovely border image vanished mysteriously from Safari on both OS and iOS

My border image is no longer appearing in Safari on OS and iOS. I am using Safari 10 on my Mac and the latest version of iOS on my iPad and iPhone. However, it still displays correctly in Firefox. You can view the website URL here: #sidebar .inner{ bor ...

Using HTML z-index to apply filter effects

I am currently utilizing images as radio buttons, but I am encountering an issue with CSS filter effects impacting the z-index properties. Here is a sample fiddle that I have created to demonstrate the problem: https://jsfiddle.net/iambong/2kcvv3bL/1/ C ...

Creating a combined Email and Password form field in a single row using Bootstrap

Recently, I decided to explore bootstrap. I am looking to implement email/password validation in one row on my rails app: email? | password? | OK Currently, I have a functioning code for displaying only an email field and an OK button in one row: email? ...

Can you explain the contrast between img.height and img.style.height?

I'm currently in the process of resizing a series of images by iterating through an array and adjusting their sizes. if(items[0].height > 700 || items[0].width > 700){ items[0].style.height = "700px"; items[0].style.width = "700px"; } As ...

HTML embedded multi-line Python code (PyScript)

I'm having trouble implementing pyscript in my HTML code. I can only seem to get it to work on a single line of code. Is there anyone who can assist me in making it work with the following block of code? def vpn(website): from selenium import webdriv ...

Issue encountered when utilizing FontAwesome in xhtml file in jdeveloper

Attempting to integrate font-awesome into my .xhtml page is proving to be a challenge, resulting in errors as shown in the image below. My development environment is Jdeveloper 12.2.1. Despite researching various topics, I have yet to find a solution. An ...

Trouble with loading external JavaScript file dynamically in Angular version 6

I have been working with Angular 6 and attempting to incorporate Bootstrap Multiselect into my project. However, I am encountering an issue where the bootstrap-multiselect.js file is not loading on the page. As a solution, I am trying to dynamically add t ...

Issue with locating image source in Angular 4

I'm struggling to source an image using angular 4. It keeps giving me an error message saying that the image cannot be found. Here is my folder structure: app_folder/ app_component/ - my_componenet - image_folder/ - myimage I am trying to ...

"Streamlining data entry with an uncomplicated HTML form input that accepts multiple values from a

As I understand it, a barcode scanner functions as nothing more than a keyboard that transmits keycode 13 after each scan. My task is straightforward: I have a basic form with only one input field and I want the ability to scan numerous barcodes and then c ...

Use jQuery to toggle one div at a time

On my webpage, I have two divs with a toggle function implemented. However, I need to update the JavaScript code to ensure that when one div is open, the other one closes. JavaScript Code: jQuery( "div.bk-toggle-header" ).click(function(){ jQuery(thi ...

Div vanishes once SVG Gaussian blur is applied

I'm attempting to add a Gaussian blur effect to an element that contains some child nodes with content. In Chrome, I successfully applied the blur using the following style: -webkit-filter: blur(2px); Unfortunately, Firefox does not support thi ...

Creating a cascading select menu based on the selected value of another select menu

I am in the process of creating a menu that displays two lists for regions: one <select> for selecting the region and another <select> for choosing from available municipalities within that region. I have set up a <form> and I utilize Jav ...

Tips for creating a static background when displaying a modal popup in AngularJS

Incorporating a modal popup to modify a row within a grid view has been my recent task. Leveraging the row.getProperty() function, I successfully extracted the row values within the modal. However, an inconvenience emerged when attempting to edit a value ...

Styling a Pie or Doughnut Chart with CSS

I am working on creating a doughnut chart with rounded segments using Recharts, and I want it to end up looking similar to this: Although I have come close to achieving the desired result, I am encountering some issues: Firstly, the first segment is over ...

Top tips for optimizing HTML and utilizing div elements

Could you please provide some insights on how to effectively utilize HTML5 in conjunction with div tags? Below is the snippet of my HTML code. I am incorporating the article tag and have segmented sections, which seem to be in order. However, I am also ...

Get the Bootstrap download that includes CSS files rather than the LESS files

What is the reason behind bootstrap switching to only having LESS files instead of the traditional bootstrap.css file? Is there a way to download the bootstrap framework that includes the CSS files instead of just the LESS files? ...