Alignment customization for Bootstrap 4 dropdown menus

I'm currently working on creating a unique custom drop-down menu design. I had an initial idea in mind which looked like this:

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

However, the final outcome turned out like this:

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

I'm quite puzzled as to why this happened. I experimented with using columns, but it didn't quite fit in the dropdown. I am desperately searching for a solution. Here is the HTML code snippet, unfortunately, it couldn't work in the snippet view. Apologies for the inconvenience.

<li class="nav-item dropdown icondropdown">
  <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="badge badge-danger badge-custom">1</span>
  </a>
  <div class="dropdown-menu dropdown-menu-center z-depth-1 " aria-labelledby="navbarDropdown" style="width: 300px; border-radius: 7px; padding-bottom: 0">
    <a class="dropdown-item text-center">
      <h5>Inbox</h5><span class="badge badge-danger badge-custom2">1</span></a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
      <img src="img/foto.jpg" class="rounded-circle" width="42">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Rainier laan</b> heeft gereageert op je bericht.</p>
    </a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
      <img src="img/johan.jpg" class="rounded-circle" width="42">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Johan Strootman</b> heeft je bericht geliked.</p>
    </a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
      <img src="img/lil-bub.jpg" class="rounded-circle" width="42">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Bill Gates</b> heeft gereageert op je bericht.</p>
    </a>
    <div class="dropdown-divider m-0"></div>
  </div>
</li>

I greatly appreciate any assistance provided. Thank you!

Answer №1

To style the paragraph tag in CSS, you can use the following code snippet:

p{
    display: inline-block;
    width: 200px;
    position: relative;
    word-break: break-all;
    white-space: normal;
}
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>

<body>
<li class="nav-item dropdown icondropdown">
  <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="badge badge-danger badge-custom">1</span>
  </a>
  <div class="dropdown-menu dropdown-menu-center z-depth-1 " aria-labelledby="navbarDropdown" style="width: 350px; border-radius: 7px; padding-bottom: 0">
    <a class="dropdown-item text-center">
      <h5>Inbox</h5><span class="badge badge-danger badge-custom2">1</span></a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
      
  <div class='row'><div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
      <img src="https://www.w3schools.com/html/pulpitrock.jpg" class="rounded-circle" width="50" height="50"></div><div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Rainier laan</b> heeft gereageert op je bericht.</p>
  </div></div>
    </a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
<div class='row'><div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
      <img src="https://www.w3schools.com/html/pulpitrock.jpg" class="rounded-circle" width="50" height="50"></div><div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Johan Strootman</b> heeft je bericht geliked.</p>
  </div></div>
    </a>
    <div class="dropdown-divider m-0"></div>
    <a class="dropdown-item dropdown-item-style" href="#">
      
  <div class='row'><div class="col-lg-2 col-md-2 col-sm-2 col-xs-2">
      <img src="https://www.w3schools.com/html/pulpitrock.jpg" class="rounded-circle" width="50" height="50"></div><div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
      <p style="color: grey; word-wrap: break-word"><b style="color: grey">Bill Gates</b> heeft gereageert op je bericht.</p>
  </div></div>
    </a>
    <div class="dropdown-divider m-0"></div>
  </div>
</li>
</body>
</html>

Answer №2

Remove the property white-space: nowrap; from the .dropdown-menu in order to fix the issue.

These are the default bootstrap styles.

.dropdown-item {
    display: block;
    width: 100%;
    padding: 3px 1.5rem;
    clear: both;
    font-weight: 400;
    color: #292b2c;
    text-align: inherit;
    white-space: nowrap;
    background: 0 0;
    border: 0;
}

Here is the updated style:

.dropdown-item {
        display: block;
        width: 100%;
        padding: 3px 1.5rem;
        clear: both;
        font-weight: 400;
        color: #292b2c;
        text-align: inherit;
        background: 0 0;
        border: 0;
    }

By making these changes, you will be able to resolve the issue.

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

What advantages and disadvantages come with choosing between using vh and vw for responsive text?

My main inquiry is centered around the various techniques for creating responsive text. Is there a particular method that stands out as the best option for general use, or do different methods serve distinct purposes? ...

Is there a way to add the date icon next to the date picker input in Bootstrap 5?

I'm struggling with getting the date icon to display after the date selection input in Bootstrap 5. It keeps showing up below it instead. https://i.sstatic.net/kD2GL.png Here is the code I am using: <form data-toggle="validator" class=& ...

Website route organization tool

Seeking assistance with implementing a route planning feature on my website. The user should be presented with multiple route options upon entering their origin and destination. Take a look at this reference site for inspiration: Any help would be great ...

Can Highchart dynamically adjust color choices based on the quantity of data points available?

I am trying to figure out how to import a specific color palette into my column graph. I want to use different color palettes based on the number of data points in my graph - for 3 or fewer points, I want to use the top row colors, for 4 points I want to u ...

Using a color as a substitute for a background image on mobile devices

Is there a way to create a fallback in my CSS for changing the background image to a color when viewed on a mobile browser once the pixels reach the max-width? In the snippet below, the media query "only screen and (max-width: 600px)" works if the top bod ...

Using JQuery to eliminate the current div in an image slider

I currently have an image slider that allows users to switch between images. There are two buttons - one adds a new item to the slider, while the other is supposed to remove the current image from the slider, but it doesn't seem to be working properly ...

Jquery doesn't immediately hide an element after the first click.TabPage.getSelection().extentNode rectangular_HTML

I'm experiencing a peculiar issue with an event listener $(document).on('click', '.suggested-location-item', function(event) { event.preventDefault(); $('#IDsuggestedLocationsList').html(''); $(&apo ...

What is the best way to handle an array (or manually loop through ng-repeat)?

AngularJS Version: 1.3.15 Confession: While I have limited knowledge of AngularJS, I am required to utilize it due to its integration in the framework I am working with. I aim to make changes to some HTML/AngularJS code that currently appears as follows: ...

A dynamic Java web framework that combines RESTful JSON services with the power of HTML5 and jQuery AJAX functionality

As we approach the year 2013, the era of HTML5, jQuery has solidified itself as the go-to standard for web Javascript development. Back in 2010, this link was quite popular: I am searching for a Java web framework that can expose domain classes through R ...

The CSS overlay effect refuses to shut down

Greetings everyone, I'm new around here so please bear with me. I am encountering an issue wherein the overlay only works in one direction - it appears when the button is clicked, but nothing happens when attempting to close it. I have tried adjustin ...

Stop form from submitting on bootstrap input, still check for valid input

Encountering a dilemma here: Employing bootstrap form for user input and utilizing jQuery's preventDefault() to halt the form submission process (relying on AJAX instead). Yet, this approach hinders the input validation functionality provided by boots ...

There seems to be an issue with the item display page when clicking on the 'view details' button within the Bootstrap tab

Encountering a problem with displaying the product details page. There are four bootstrap tabs, each containing some Product Items with a Quick View link button. The issue arises when clicking on the link button, as all tab items with the same ID are displ ...

CSS - Maximizing One Column's Width While Allocating Percentage Space for Two Columns?

It's been quite some time since I delved into the world of web development and I seem to have forgotten how to tackle this particular issue. Despite hours spent searching online, I've gained knowledge about flex-boxes and other useful tools, but ...

Implementing a video background within a dynamic two-column layout, accompanied by text within a separate column

While viewing on a large screen with Bootstrap 5, everything looks good: https://i.sstatic.net/Vm6bH.png However, when I resize the screen, the text in the first column overflows onto the sections below instead of adjusting properly. https://i.sstatic.n ...

I customized the navbar in Bootstrap by centering it with custom CSS, but whenever I click on it, it suddenly shifts to one side. I'm puzzled as to why this is happening and

I attempted to center my navbar-toggler element, but was only successful in centering the navbar-contend using Bootstrap. I then took it a step further by trying to center the navbar-toggler icon with custom CSS, however, it now shifts to the left when cli ...

Tabulator filter - Enhancing CSS elements for a unique touch

Is there a way to customize the CSS elements of filters used in tabulator.js? Specifically, I am looking to: Apply different background colors to text filters Add a down arrow on the right side of each drop-down filter box I have included a screenshot ...

Group input with segmented buttons (Bootstrap 4 alpha version)

In Bootstrap 4's input-group dropdown arrow is displayed under action button: https://i.sstatic.net/eGzcb.png <div class="container"> <div class="input-group"> <input type="text" class="form ...

Numerous intersecting lines on display within Google Maps

Currently, I am working on displaying multiple flight routes on Google Maps. I have implemented polylines with geodesic to achieve this functionality successfully. However, a challenge arises when more than two flights intersect the same route, causing o ...

Error: PHP syntax error occurred due to unexpected double-quote mark

As a beginner in php, I've been encountering an error in my code echo "<a href=\"PHadmin_deletePatient.php?id=<?php echo $row["PatientID"]; ?>\" class='delete' title='Delete' data-toggle= ...

Using jQuery to create animated effects for hidden input fields

The struggle to smoothly animate and fade in a hidden text field can be witnessed in this example. The goal is to seamlessly move all elements around the text field and button while fading in/out the hidden element. However, it appears that towards the en ...