How to Align an Icon to the Right in a Bootstrap 4 Modal Title

I'm attempting to position two icons next to the close button within a Bootstrap 4 modal. Unfortunately, I am struggling to remove some unwanted margin-left that persists despite my best efforts. While inspecting the element, I was successful in achieving the desired layout, but applying those changes to the .close or button class did not have the intended effect!

DEMO: https://jsfiddle.net/x2m3kfzu/

HTML:

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
  Launch demo modal
</button>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&copy;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
    </div>
  </div>
</div>

CSS:

.close, button {
  margin-left: 0 !important;
}

Answer №1

Simply place the buttons within a div container.

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
    Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                <div>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&copy;</span>
                    </button>
                </div>
            </div>
            <div class="modal-body">
                ...
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

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

The hover functionality fails to activate when a z-index is applied

My issue revolves around 2 divs: one containing a link and the other a box-shaped container. The link is set with position:fixed; causing it to fly over the container div. To resolve this, I attempted to assign a negative z-index value to the link, but unf ...

Analyzing comma-separated values file and transforming the information into a modifiable format

Need advice on parsing CSV and using foreach loop.. <?php //output Array ( [0] => Array ( [company] => A Company [address] => A Address [telephone] => A Telephone ) [1] => Array ( ...

Ensure that all elements with the :hover event have a text color of #fff in CSS

 Troubleshooting problems with block's child elements during the :hover event. Specifically, I have a pricing block where I want all texts to be of color #fff when hovered over. Currently, when hovering over the <h3> and <p> elements ...

The child elements will take up the entire space within the parent element

I need to display N child divs with varying widths inside a parent div of unknown width. I want the child divs to fill and align side by side in the parent div, similar to a td - tr relationship. Can you help me achieve this layout? ...

The jQuery .accordion() feature is not functioning properly due to the failure to load jQuery into the HTML document

I have exhaustively researched online and visited numerous resources, including Stack Overflow. Despite making countless adjustments to my code, it still refuses to function properly. The frustration is mounting as I struggle with jQuery - a technology tha ...

The screen reader fails to recognize the <h1> element upon entering the webpage

Here is the snippet of HTML code I am currently working with: <h1><span>Main Menu</span></h1> <div> <button tabindex="0">New Customer</button><br> <button tabindex="0">Existi ...

Troubleshooting Vue.js and Laravel: Having trouble loading new image files, while the older ones load just fine

Currently, I am working on a project that involves Vue.js and Laravel. In this setup, Vue is located inside the resources/js directory of the Laravel project. My current issue revolves around loading an image from the resources/js/assets directory. While ...

Would it be practical to use a 1kb .png image on repeat as a background image?

I recently created a PNG image from the website . This image is only 1kb in size and I am currently using it as the background-image on the body tag of my webpage. Now, I am contemplating using another image that is significantly larger at 500kb (with dim ...

Guide on playing two HTML5 videos simultaneously once they have been loaded

Is it possible to make two HTML5 videos autoplay simultaneously? Is there a way to delay the playback until both videos have fully loaded? I'm looking to ensure that neither video starts playing before the other has finished loading. Does that clarif ...

Utilizing CSS styling in PHP as a functional approach

In my journey of learning CSS, HTML5, and jQuery, I have found a unique way to organize my CSS code into different chapters. I simply call them into the head section when needed. This method allows me to have only the necessary CSS on each page, making it ...

Setting div HTML as an attribute in jQuery

I am facing an issue with assigning a div content (barcode) from my database as an attribute to my select option. Whenever I assign it, the option ends up getting distorted. Can anyone provide some guidance on how I can achieve this successfully? I have al ...

Is there a method in bootstrap that reveals the elements with the hidden class?

Currently, I am loading data into a bootstrap table on my JSP. The table class is hidden at the moment. After successfully uploading the data into the bootstrap table, I have implemented the following code: $(function() { var table = $('#Table') ...

Concerns with textbox placement while scrolling with an absolute position style

I have an ASP:textbox on a page with various controls and divs, where I am setting the style to position:absolute on the "onkeyup" event. The height of the textbox increases dynamically based on the characters entered, but the issue is that the textbox alw ...

Implementing full-width responsive background images with srcset and lazy loading for optimal performance

I'm currently developing a website with a striking layout featuring 'hero' panels that cascade down the home page, showcasing text overlaid on captivating background images. My goal is to utilize inline images with srcset and sizes attribut ...

How to toggle the display of a div by its id using index in Javascript

Currently, I am encountering a problem with toggling the div containers. When I click on the video button, I want the other divs to close if they are already open. However, due to the toggling mechanism, if a div is closed and I click on the corresponding ...

The scrollbar remains unresponsive and fixed until the screen size is adjusted

Need some assistance with a website project for a client. The scrollbars on each page are not loading or changing height until the window is resized. I have a jQuery scrollbar in place, but disabling it does not solve the issue as the normal scrollbar beha ...

Ways to eliminate the .html extension when someone accesses your static website

My current setup involves a static website being served by nginx. For example, when visiting www.mydomain.com, it displays as www.mydomain.com/index.html. Is there a way to avoid the trailing .html and have www.mydomain.com/index displayed instead? I&ap ...

I am encountering an issue where the key is not located in the response array in PHP, causing my JavaScript chart to remain

Hey there! I'm currently working on a school project and could really use some assistance. The task at hand involves creating a web interface that can interact with an endpoint in order to: - Authenticate a registered user to retrieve an authenticati ...

Let us know when the information on a different tab is updated

I have multiple tabs and I want to indicate when a change occurs on another tab that the user hasn't clicked. For example, if the user hits the run button while on the Data pane, I would like the Errors tab to change to red to show that there was a ch ...

Identifying Internet Explorer version through CSS functionality and feature detection

As of IE10, browser detection tags are no longer supported for identifying a browser. In order to detect IE10, I am utilizing JavaScript and a technique that tests for certain ms prefixed styles like msTouchAction and msWrapFlow. I would like to do the s ...