Align the button in the middle vertically

How can I center the <form> tag containing the <button>?

This is what my View looks like:

  • The <p> tag and the '' are displayed in a flex layout.
  • The <p> tag is vertically aligned in the center.
  • The button is positioned at the bottom of the form.

Here's what I've tried:

  • Adding class="align-middle" to the <form> tag.

I'm aware that setting a pixel-based bottom margin may work, but it feels like a messy solution as it would require readjusting if elements within the <p> tag were added or removed later.


<div class="d-flex align-items-center">
    <p>some random text placeholder</p>

    <form class="align-items-center" asp-controller="Dashboard" asp-action="Remove" asp-route-ParticipantId="@mmLeagueParticipant.child.ParticipantId" method="POST">
        <button class="btn btn-outline-danger mt-5 bg-light">remove</button>
    </form>
</div>

Bootstrap 4.6 is being used for styling.

Answer №1

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4-rtl/4.6.0-2/css/bootstrap.min.css" rel="stylesheet"/>

<div class="d-flex justify-content-center align-items-center">
    <span class="d-flex align-items-center">some unique text goes here</span>

    <form class="" asp-controller="Dashboard" asp-action="Remove" asp-route-ParticipantId="@mmLeagueParticipant.child.ParticipantId" method="POST">
        <button class="btn btn-outline-danger bg-light">remove</button>
    </form>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-v4-rtl/4.6.0-2/js/bootstrap.min.js"></script>

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

Stop Chrome from highlighting the canvas section

One interesting feature of our whiteboard application is that Chrome users have the ability to highlight the entire canvas by dragging their mouse in a specific manner: Do you have any suggestions on how we can prevent this behavior? Thank you! ...

What is the best way to position a label in conjunction with wrapping tags?

I have a label and multiple tags that might span multiple lines: .container { background-color: #ddd; display: flex; width: 200px; margin-bottom: 50px; } .label { margin-right: 10px; } .boxes-container { display: flex; flex-wrap: wrap; } ...

Issue with h2 tag within JQuery's read more feature

How can I modify my jQuery code to wrap the middle text in an h2 tag? I am currently using a code snippet from code-tricks. You can find the original code snippets here: $(document).ready(function() { var showChar = 100; var ellipsestext = "..."; ...

"Utilizing React's useState feature to dynamically update numerous dropdown components

Here is a React component snippet: const [show, setshow] = useState(false); const handleShow = () => { setshow(!show); }; Accompanied by the following CSS styles: .show { display: block; } .dropdown_content { padding: 3px; display: none; po ...

Position a grid item in the center

Can someone help me with centering my container's item? I am struggling to align the third item to the center using display: grid. Previously, I attempted to use flexbox but found it to be less effective for a responsive layout. .projetos { f ...

Creating a visually appealing website with Bootstrap 3

Looking to create a unique HTML design using Bootstrap. So far, this is what I've come up with: Plunker Any suggestions or assistance would be greatly appreciated. ...

After every refresh, Next.js dynamically applies unique and quirky styles to Bootstrap components

Let's address the issue at hand: Upon opening the page or performing a hard refresh, all components load correctly except for certain buttons and form controls from Bootstrap 4. This leads to an unconventional styled form and icons. I have opted to ...

Issue with AngularJS bug in Internet Explorer when using regular style attribute compared to ng-style

While working with Angular JS v1.1.5, I came across an interesting issue related to Internet Explorer. In IE 9, 10, 11, and Edge, the following code snippet doesn't work as expected, even though it works fine in Chrome: <div style="width: {{progr ...

I prefer to have the div element on its own line without using <br>, as I find it neater that way

I am currently working on a website layout that includes a header with a menu option on the left, a title in the center, and a link to the logIn/signUp page. You can view an image of this layout here: https://ibb.co/z6R1h6w Unfortunately, the login and sig ...

striving to showcase components in a horizontal layout

My goal is to have 'Forgot your password?' appear on the same line as 'Remember me', similar to the image. I am using the simple_form gem, but it's causing some issues. Normally, I would use 'display: inline' in my ' ...

Adjusting the display of HTML elements depending on geolocation authorization

I am currently facing an issue with my HTML code where I want to show an element only if the user declines to share their location with the browser. However, my code is not functioning as expected when the user rejects the location request. On the other ha ...

Resolving the Persistence Problem of Navigation Bar Fading In and Out

I've been struggling for hours trying different methods to achieve the desired outcome, but unfortunately, none of them have worked as expected. My goal is simple: I want the fixedbar to fade in when the scroll position exceeds the position of the ph ...

Trouble getting CSS to load in Webpack

I'm having some trouble setting up Webpack for the first time and I think I might be overlooking something. My goal is to use Webpack's ExtractTextPlugin to generate a CSS file in the "dist" folder, but it seems that Webpack isn't recognizi ...

What are some strategies for effectively utilizing GitHub's primer and octicons?

Utilizing GitHub's primer and octicons. Upon installation with npm, I incorporated the css classes provided by GitHub through the inclusion of the build.css file in my HTML document. How can I direct the project to access all the SVG icons offered by ...

Utilizing multiple class names in Material UI with identical definitions

When working with traditional CSS, it is common to define shared properties between classes like this: .classA,.classB{ background-color: black; } In Material UI and using theming, the equivalent would be: styles = (theme)=>({ classA:{ ba ...

Connecting images and text from a distance

After days of researching this topic, I have not found any solutions that align exactly with what I am trying to achieve. I believe it should be a simple task using just HTML and CSS, but I seem to be facing some difficulties. Initially, my goal was to ma ...

Text in Bootstrap Carousel shifting during transition to active item

I'm encountering a problem similar to the one discussed in this thread about Bootstrap Carousel Caption movement after transition. Despite reading and attempting the solutions provided, I still haven't been able to resolve my issue... In my case ...

Design a square confined within an adjustable rectangular container

Looking to fill a rectangular area on my page with a square positioned in the center, regardless of whether the rectangle is horizontal or vertical. Many existing solutions focus solely on creating a square from the width of a containing box, which doesn&a ...

Issue encountered when attempting to retrieve dimensions of a div element

Using Vue and facing an issue with a div setup that I have: <div :style="'width:' + imageSize.width + 'px; height:' + imageSize.height + 'px'" id="image-container"></div> The dimensions are sto ...

Is it recommended to place the styles created by material-ui for child components after the styles generated for the parent component?

Utilizing material-ui, which utilizes JSS for styling a website. I have a component named Layout that applies margin to all its children (using the all children selector & > * in its style). This functionality works, but I would also like the child ...