What could be the reason for the button not properly aligning on a mobile device?

I've been working on a webpage for my mother's students, and I'm facing some challenges. When I view the page on mobile, everything adjusts except for the buttons. They end up overlapping each other, creating a messy layout. Additionally, I'm relatively new to web development.

Here is the code snippet related to the buttons on my homepage:

const showMenu = (toggleId, navId) =>{
    const toggle = document.getElementById(toggleId),
    nav = document.getElementById(navId)

    if(toggle && nav){
        toggle.addEventListener('click', ()=>{
            nav.classList.toggle('show')
        })
    }
}
showMenu('nav-toggle','nav-menu')

/*===== ACTIVE AND REMOVE MENU =====*/
const navLink = document.querySelectorAll('.nav__link');   

function linkAction(){
  /*Active link*/
  navLink.forEach(n => n.classList.remove('active'));
  this.classList.add('active');
  
  /*Remove menu mobile*/
  const navMenu = document.getElementById('nav-menu')
  navMenu.classList.remove('show')
}
navLink.forEach(n => n.addEventListener('click', linkAction));
.button{
  display: inline-block;
  background-color: var(--first-color);
  text-align:center;
  color: #fff;
  padding: .75rem 2.5rem;
  font-weight: var(--font-semi);
  border-radius: .5rem;
}

#but0{
  display: inline-block;
  background-color: var(--first-color);
  text-align:center;
  color: #fff;
  padding: .75rem 2.5rem;
  font-weight: var(--font-semi);
  border-radius: .5rem;

}

#but1{
  display: inline-block;
  background-color: var(--first-color);
  text-align:center;
  position:absolute; right: 42%;

  color: #fff;
  padding: .75rem 2.5rem;
  font-weight: var(--font-semi);
  border-radius: .5rem;
}

#but2{
  display: inline-block;
  background-color: var(--first-color);
  text-align:center;
  position: absolute; right: 10%;
  color: #fff;
  padding: .75rem 2.5rem;
  font-weight: var(--font-semi);
  border-radius: .5rem;
}
 <a target="_blank" href="#" class="button" id="but0">Online Regulations
                        <p id="settings-note">*Download here</p></a>
            
                    <a target="_blank" href="https://docs.google.com/forms/d/e/1FAIpQLSdZ5dzDCllrRvxbugJOvGCzka4T92vBmaNizDaIVY6uYSzGVQ/viewform?usp=sf_link"
                       class="button" id="but1">Attendance
                        <p id="settings-note">*Link here</p>

                    <a target="_blank" href="#"  class="button" id="but2">Schedules
                        <p id="settings-note">*Download here</p></a>

Answer №1

By specifically setting the position to absolute, you are removing the elements from the normal flow of the webpage and positioning them based on the properties assigned. The use of the right property on the second and third buttons ensures they are placed at specified distances from the right edge without concern for overlapping content.

To improve the layout, try adjusting the CSS and markup as shown below. Flex is used to create proper spacing between the buttons.

#buttonWrapper {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.button {
  display: inline-block;
  background-color: var(--first-color);
  text-align: center;
  color: #fff;
  padding: .75rem 2.5rem;
  font-weight: var(--font-semi);
  border-radius: .5rem;
}
<div id='buttonWrapper'>
  <a target="_blank" href="#" class="button" id="but0">
    Online Regulations
    <p id="settings-note">*Download here</p>
  </a>

  <a target="_blank" href="https://docs.google.com/forms/d/e/1FAIpQLSdZ5dzDCllrRvxbugJOvGCzka4T92vBmaNizDaIVY6uYSzGVQ/viewform?usp=sf_link" class="button" id="but1">
    Attendance
    <p id="settings-note">*Link here</p>
  </a>

  <a target="_blank" href="#" class="button" id="but2">
    Schedules
    <p id="settings-note">*Download here</p>
  </a>
</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

A guide on loading theme JavaScript files in Next.js

I am planning to incorporate a theme from themeforest into Next.js Despite my attempts, I encountered issues with loading jquery core and certain plugins in Nextjs. import { useEffect } from "react" import { SessionProvider } from "next-aut ...

Update the page content once the popover is closed. Working with IONIC 3

In my application, there are 4 tabs, each displaying different data based on a specific configuration. The header of the page includes a popover component with settings options. When a user adjusts the settings and returns to a tab page, the content on th ...

Insert HTML content into an iframe with a callback function

We are receiving information from the backend server and need to transfer it to an iframe. In order to accurately set the height of the iframe to match the content, we must wait for the content to be loaded into the iframe. However, this process may not ha ...

What is the best way to implement multiple ternary operators within HTML code?

Consider the following code snippet: It currently applies CSS classes up to red4, but I want to apply CSS classes up to red11. Additionally, the variable "size" in myData should be dynamic. For example, size could range from 0-20 // 0-100 // 0-10000, etc., ...

Referencing a JavaScript source in the vendor file in Rails 4: Tips and Tricks

After realizing that my GMaps for Rails setup needs amendment, I've decided to insert javascript files directly into my app. Rails 4 - Gmaps4Rails - map won't render I've downloaded the infobox and markerclusterer repositories and now find ...

Using AJAX to submit a form to a CodeIgniter 3 controller

I am working on adding a notification feature and need to run an ajax query through the controller when a button is clicked. Here's the script I'm using: $('#noti_Button').click(function (e) { e.preventDefault(); ...

Is it possible to include a relative URL with a different port number in a hyperlink?

Is it possible to link to a different port number on the same server without using Javascript or server-side scripting, especially if the hostname is unknown? For example: <a href=":8080">Check out the other port</a> (Note that this example ...

Node.js Azure Functions: My route parameters are not included in context.bindingData as the documentation implies

I'm currently working on a function that needs to retrieve 2 route parameters (first required, second optional), but I'm encountering some difficulties despite following the Documentation provided. I am specifically referring to this set of inst ...

React dynamic dropdown selection based on previous dropdown values

I have implemented 3 react input fields that are populating data to a useState Hook <FormControl fullWidth> <InputLabel>Primary Goal</InputLabel> <Select ...

Material UI - sending an icon as a property

I need help with inserting a material-ui icon into my component using props. Can you please advise on what I might be doing wrong? I am struggling with passing the icon down in JSX, and here is the attempt that is not working: This code snippet shows me t ...

Achieving the ideal positioning of content within the flex property

I am facing an issue with my containers, specifically .grid.left and .grid.right. The images within each of these grids are dynamic and enclosed within another div called .gallery. The problem arises when I apply margins to the image boxes, causing gaps w ...

Problem with loading images from class in IE7

Encountering issues with IE7 and images in my CSS. .dot-preview { background: url("../images/bola02.png") no-repeat scroll 0 0 transparent; display: block; height: 12px; margin: 3px; width: 13px; } .navi-active .dot-preview { back ...

Is it possible to use the HR tag to span the entire page width

When I use the HR tag in my HTML page, I notice that the horizontal line does not extend all the way across the X axis of the page. There are gaps on both the left and right sides. How can I fix this issue? Here's an example of the code I'm usin ...

Arrays in Javascript (correlating)

I'm having trouble figuring out what needs to be included in this code (I apologize that it's in German, it's an array corresponding to images for JavaScript.) function namenZuBildern(){ var bilder = new Array( "000227", "000228", " ...

Changing the main directory name in a Three.JS project triggers an unexpected aliasing glitch

Creating a new stackoverflow account just to ask a question is not my usual style, but I am completely baffled by this issue. For months, I have been struggling with a strange bug that causes a glitch in my three.js VR projects on Android. My usual method ...

animations are not triggering when using ng-click inside ng-repeat, is there a reason why the event is not firing?

Check out the code in jsFiddler here After reviewing the code, it's clear that when the add button is clicked, a new item is pushed to the $scope.p. Each item in the ng-repeat loop has an event-binding and everything functions correctly. However, onc ...

How can I send an array of objects to a PHP server using axios?

let dataArray = [ { fname: 'name #1', choice: 'choice #1', }, { fname: 'name #2', choice: 'choice #2', }, // more data could be appended here ]; I'm looking for guidance on how to send ...

Having trouble sending form data using the jQuery AJAX POST method?

I am facing an issue with a simple form that is supposed to send data to PHP via AJAX. However, when I submit the form, the data does not get sent across. Here is the JavaScript code: $(document).ready(function(e) { $('#update').submit(func ...

Understanding the Usage of FormData in NextJS

I'm trying to read fetch's body contents. Here's the code I'm using: fetch('/api/foo', { method: 'POST', body: new FormData(formRef.current), }); https://i.sstatic.net/6YB1V.png Now I need to parse the body dat ...

What is causing the resistance in changing the color of my current navigation items?

I've encountered a small challenge with my header section. Despite multiple attempts, I'm struggling to change the color of the 'current' menu item. It seems that overriding Bootstrap's default color is proving to be more difficult ...