Button placed incorrectly

I am utilizing bootstrap 4, thymeleaf, and datatable

I attempted to place a button on top of the table to the right

<div class="col-sm-12">
     <div class="float-right">
         <button id="newUsers" type="button" th:onclick="@{/newusers}" class="btn btn-primary" th:text="#{user.new}">New User</button>
     </div>
 </div>

I used col-sm-12 to occupy all available space

<table id="usersTable" class="table table-striped table-bordered" width="100%" cellspacing="0">
    <thead>
        <tr>
            <th th:text="#{user.id}">Id</th>
            <th th:text="#{user.login}">Login</th>
            <th th:text="#{user.firstname}">Firstname</th>
            <th th:text="#{user.lastname}">LastName</th>
            <th th:text="#{user.roles}">Roles</th>
        </tr>
    </thead>
</table>

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

The button is not aligned correctly with the text box

Edit: Added code to initialize the table

$(document).ready(function() {
    var url = "/users";
    $('#usersTable').DataTable({
        "bLengthChange": false,
        'processing': true,
        'serverSide': true,
        'pagingType': 'simple_numbers',
        'ajax': {
            type: 'get',
            'url': url,
            'data': function(d) {
                var current = $('#usersTable').DataTable();
                d.page = (current != undefined) ? current.page.info().page : 0;
                d.size = (current != undefined) ? current.page.info().length : 5;
                d.sort = d.columns[d.order[0].column].data + ',' + d.order[0].dir;
            }
        },
        "columns": [{
                "data": "id"
            },
            {
                "data": "username"
            },
            {
                "data": "firstname"
            },
            {
                "data": "lastname"
            },
            {
                "data": "username"
            }
        ]
    });
});

Even with the suggested solution, the button alignment needs adjustment in conjunction with the datatable

Edit 2

To achieve better integration, considering these extensions could provide a viable solution

https://datatables.net/extensions/buttons/examples/initialisation/custom.html

Answer №1

Make sure to place the float-right class on the button...

<div class="col-sm-12">
     <button id="newUsers" type="button" class="btn btn-primary float-right">New User</button>
</div>

Answer №2

When you set the width to 100% and align it to the right, the element will move to the far right of the screen as shown in this example:

.col-sm-12 {
  width: 100%;
  text-align: right;
}
<div class="col-sm-12">
  <div class="float-right">
    <button id="newUsers" type="button" th:onclick="@{/newusers}" class="btn btn-primary" th:text="#{user.new}">New User</button>
  </div>
</div>
<table id="usersTable" class="table table-striped table-bordered" width="100%" cellspacing="0">
  <thead>
    <tr>
      <th th:text="#{user.id}">Id</th>
      <th th:text="#{user.login}">Login</th>
      <th th:text="#{user.firstname}">Firstname</th>
      <th th:text="#{user.lastname}">LastName</th>
      <th th:text="#{user.roles}">Roles</th>
    </tr>
  </thead>
</table>

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

Using Webpack to Compile Sass (and keep class names local)

It's been a long journey trying to configure my Webpack setup to compile Sass, and the process has become quite overwhelming. In my quest for answers, I encountered numerous Github issues, Stackoverflow threads, and blog posts discussing how to integr ...

Match rooms using Socket.io

I am utilizing the opentok and socket.io packages in an attempt to establish 2 distinct "groups". Successfully, I have managed to pair up individual users in a 1-to-1 relationship. However, my goal is to create two separate groups of users. For instance, ...

jQuery class toggle malfunction

I have a series of list items with specific behavior when clicked: Clicking a list item will select it and add the class .selected If another list item is clicked, the previously selected item becomes unselected while the new one becomes selected If a se ...

Having trouble with my PHP index not properly redirecting to the dashboard file after logging in

I have created a login form and implemented some functionalities. One of the key features is redirecting to the dashboard file after successful password validation. I attempted to troubleshoot using chatgpt, but the issue persists. I am reaching out for as ...

The mysterious button that reveals its text only when graced by the presence of a

The text on the button (Remove in this case) will only show up when the mouse is hovered over it. This issue is occurring in an angular project and despite trying to apply CSS for .btn, it does not get overridden. background-color: blue; Button's ...

Immediately Invoked Function Expression in Javascript

const user = { name: "John", age: 30, lastName: "Smith" } (({name, lastName}) => { console.log(name); console.log(lastName); })(user); An error occurred: {(intermediate value)(intermediate value)(intermediate value)} is not function ...

What purpose does the "invert" attribute serve on an HTML tag?

Recently, I came across something intriguing in the YouTube html source code: <!doctype html><html invert style=... Can anyone enlighten me on the purpose of the invert attribute in this code? ...

Overflow of content within a rectangular element

One challenge I'm facing is creating HTML/CSS code that automatically adjusts the website layout (blocks and content) when I resize the browser window. For example: I encounter text overflow issues in a block I've created when I minimize the brow ...

Issue with idangero.us swiper: resizing problem occurs when image exceeds window size

Having an issue where resizing my window causes the image to become larger than anticipated. As a result, the current image is partially cropped on the left side while the previous image starts to show through. Here's a description of what's happ ...

Creating a webpage that utilizes varying headers for each section can help to

When trying to print a multi-page webpage, I encounter an issue with the headers. How can I ensure that different headers appear on each page after the first one? Specifically, my problem arises when a label on the first page spans across to the second pa ...

Retrieve information from a separate controller in Angular

Working within Angular 4, I've set up a navbar and menu component that lists various tasks pulled from a web service. Clicking on a task in the menu component opens up the edit task component, which displays a form for editing the task. The form fiel ...

I keep getting an error saying "wallet.connect() is not a function," even though it was working perfectly just a few

`` I'm currently working on the FCC solidity course and I've reached the 7:45 mark. Everything was running smoothly until I encrypted the RPC url, private key, and password. Now, when trying to connect my wallet variable to the provider variable ...

Display clickable buttons beneath the Material-UI Autocomplete component

I want to place buttons ("Accept" and "Cancel") below the MUI Autocomplete element, and I am trying to achieve the following: Limit the Autocomplete popover height to display only 3 elements. To accomplish this, pass sx to ListboxProps Ensure that the b ...

Utilizing checkboxes to toggle the visibility of a div element with varying headings

By toggling a checkbox, I aim to show or hide the same div with a different heading. $('#cbxShowHide').click(function() { this.checked ? $('#block').show(1000) : $('#block').hide(1000); }); #block { display: none; bac ...

HTML/CSS flowchart illustration

Is there a user-friendly method to create a flow or swimline diagram without relying on scripting or tables? Specifically, I'm looking for a way to display different hosts sending packets (with hosts along the X axis, time along the Y axis, and arrows ...

Updating AngularJS views based on window resizing

I've been working on an Angularjs application and everything is running smoothly, but I'm facing challenges when it comes to implementing a mobile version of the site. Simply using responsive styles won't cut it; I need to use different view ...

Vue.js and axios causing an empty array after the page is refreshed

As a newcomer to coding and using vue cli, along with my limited English skills, I apologize if I am unable to articulate the issue clearly. However, I am reaching out to the community for assistance. The code snippet below is from store.js where I fetch ...

Sending data to server using Ajax and jQuery

Hey there, experiencing a little hiccup in the back-end of my system when I try to submit my form. It keeps showing me an error saying Unidentified index: file1 . Can't seem to pinpoint where the issue lies in my code. Even though I'm no beginner ...

Establish a set distance between list items

I recently incorporated a Material UI list component into my project. Take a look at the code snippet I used: <List> <ListItem button> <ListItemText disableTypography primary={<Typography>Hello</Typography ...

What is the best way to assign various classes to individual elements depending on their content?

HTML <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-401 dt-mega-menu mega-auto-width mega-column-3"> <a href='#' data-level='1'> <i class="logo-png dnld-logo"></i> ...