Styling buttons using CSS for proper alignment

Struggling to center align two buttons on my website, none of the common methods seem to work. It's becoming a headache as nothing else is overriding it. Perhaps I'm missing something.

This is my CSS button code:

.btn {
    border-radius: 10px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
}

.btn-primary {
    background-color: #346cfc !important
}
.btn-secondary {
    background-color: #346cfc !important;
} 

And this is my HTML code:

</nav>
<div class="heading">
<h1 class="display-5 title"></i>Ricky</h1>
<p class="subtitle">Ricky is a multi purpose bot with features like Music, Economy, Utility, and more!<br />Check out the <a href="https://docs.partywumpus.com">docs</a> or get started below.</p>
<a class="btn btn-primary btn-lg text-center"href="https://discord.com/oauth2/authorize?client_id=778817321640394762&scope=bot&permissions=2147483647" target="_blank" role="button">Invite</a>
<a class="btn btn-secondary btn-lg text-center"href="https://discord.gg/XXBpY2v6AU" target="_blank" role="button">Support Server</a>
<br /><br /><br /><br /><br /><br />

I did manage to make it work by setting position relative, but it doesn't look good on mobile depending on the top and left % values.

.btn-primary {
  position: relative;
  top: 50%;
  left: 50%;
  background-color: #7289DA !important
} 

Any suggestions for a better way to achieve proper alignment without sacrificing appearance on PC or mobile?

Answer №1

The best practice is to enclose your button within a div tag

<div class="button-wrapper">
  <a class="btn btn-primary btn-lg text-center"href="https://discord.com/oauth2/authorize?client_id=778817321640394762&scope=bot&permissions=2147483647" target="_blank" role="button">Invite</a>
  <a class="btn btn-secondary btn-lg text-center"href="https://discord.gg/XXBpY2v6AU" target="_blank" role="button">Support Server</a>
</div>

.button-wrapper {
  display: "flex";
  align-items: "center";
}

https://css-tricks.com/almanac/properties/a/align-items/

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

Achieving a Sticky Scrolling Element on the Same Side with Bootstrap 4

Seeking assistance with creating a fixed category bar for blogs on scroll, which should always remain on the right side of the screen. The issue I'm facing is that the current setup causes the bar to switch sides and shrink in size when scrolling past ...

Ensure that the URL is updated correctly as the client navigates between pages within a Single Page Application

Seeking a solution for maintaining the URL in a Single Page application as the client navigates between pages, with the URL changing in the background. I attempted using @routeProvider but it doesn't seem to be suitable for my situation. Any suggestio ...

Instructions on saving an aspx page content type on the server side as an HTML page and displaying this HTML on the client side

The Table I'm working with includes a header and footer, but unfortunately it lacks browser compatibility. My solution is to save the table in HTML format on the server side and display it on the client side without using print preview. It's ess ...

Choosing a Webpage Navigation Tab with Excel VBA

Having trouble selecting one of the navigation tabs on a webpage, even after coding for ID, password, and other screens. I've tried various combinations of "GetElementBy" without success. The tabs don't seem to be in their own frame. Here is the ...

Why does HTML validation matter after the webpage has finished loading?

After coming across an article recommending a workaround for a method that isn't considered strictly valid (using target="_blank") by using JavaScript to apply the rules after the page has loaded, I began contemplating if this approach is ethical. It ...

Steps to gather all the images within a directory

Take a look at this demo When you click on the "next" button, new images are loaded from the internet. In my application, all the images are stored in the img/image folder with names like 1.jpg, hi.png, etc. My question is, how can I display these image ...

Is there a way to make the navigation menu collapse only on mobile devices and not on desktop?

I have been attempting to create a collapsible nav menu that only collapses on mobile devices, and not on desktops. When I include the code data-toggle="collapse" data-target="#navbarResponsive", it successfully collapses on mobile, but then the nav items ...

Tips for maintaining the parent's width during a resize operation

I have a query: I am facing an issue with an image inside a div. The image is larger than the div, so I set its height to 100% to make it appear correctly. When I resize the image, it adjusts well and looks fine. However, when I resize the browser to make ...

Creating a log-out script in Parse (JavaScript) can be achieved by following these steps

I'm facing an issue with logging out from my website. Despite browsing through Parse's documentation, I couldn't find a detailed explanation on how to log out the user, especially since I'm not well-versed in JavaScript. Whenever I cli ...

What is the best way to keep an image fixed at the bottom, but only when it's out of view in the section

There are two buttons (images with anchors) on the page: "Download from Google Play" and "Download from App Store". The request is to have them stick to the bottom, but once the footer is reached they should return to their original position. Here are two ...

Include a "Click for more" and "Click to collapse" button on all thumbnails, not limited to just one

I am struggling to make the toggle script below work for all thumbnails in the gallery, not just the first thumbnail. Each card is filled with paragraphs, bullets, and links, making the page overwhelming. That's why I need the "Read More" and "Read Le ...

Create a vibrant PNG image background that changes dynamically based on the dominant color of the

Is it possible to dynamically set the background color of a PNG image, either white or black, based on the dominant color in the image? For example, this image should have a dark background: https://i.stack.imgur.com/cerjn.png And this one should have a ...

How can you use ui.router to set up one controller as the child of another controller?

To create a nested controller in html, you can simply write the child controller inside the parent controller like this: <div ng-controller="parentCtrl"> <div ng-controller="childCtrl"> When using ui.router, you can specify one state as a c ...

Angular and WEB API experiencing issues with the update function synchronization

Currently, I'm developing a CRUD example using dotnet core and Angular. In the backend, I have implemented a function in the CarController.cs as shown below: CarController.cs [Route("UpdateCar")] [HttpPut] public IActionResult Put([ ...

How to Remove onFocus Warning in React TypeScript with Clear Input Type="number" and Start without a Default Value

Is there a way to either clear an HTML input field of a previous set number when onFocus is triggered or start with an empty field? When salary: null is set in the constructor, a warning appears on page load: Warning: The value prop on input should not ...

Add HTML content to a common div in every loop iteration

Within the success function of my AJAX call, I have a for loop that iterates through the results array. On each iteration, I create a new div element. My goal is to append all the div elements generated during the iterations to a common div. For Loop in A ...

Create a video player in your HTML code using the class "afterglow", and also link a separate class to it for additional styling

I'm encountering some challenges with a project that involves a JS file for a Bootstrap modal popup and an HTML5 video player. The issue I'm facing is that I am unable to link the class for the video player theme. Can anyone here assist me in ide ...

Using variables in Javascript to manipulate the Date object

Here is my JavaScript code snippet: var earlierdate = new Date(2012, 09, 22); alert(earlierdate.getDay()); var date2 = new Date('2012, 09, 22'); alert(date2.getDay()); The issue I am facing is that the first alert displays 1 or Monday (incorr ...

Update the component with the current route and state synchronization with react router dom

Is there a method to synchronize the active route in the browser with the component state? When I click on "Route 2" in the navigation bar, it gets highlighted as the active route and the browser URL shows "/route2". However, upon refreshing the page, "Ro ...

PHP: Transferring data between MySQL tables and Excel files

I am encountering an issue while attempting to transfer a table from a MySql database to Excel using PHP. The error message I receive states that the file format or file extension is not valid. Below is my current code snippet: $db = JFactory::getDBO(); $ ...