Styling buttons of different sizes for proper alignment in CSS

Can someone please help me fix this issue? I'm having trouble getting the buttons to adjust properly so that they don't look misaligned after clicking the equal button. Thank you in advance! calculator button alignment problem

Snippet of my CSS:

body{
    margin:0;
    padding: 0;
}
form{
    width:280px;
    margin: auto;
    
}


button{
    height: 40px;
    width: 60px;
    font-size: 1.5em;
    background-color: #ddd;
    border: none;
    float:left;
    margin: 2.3px;
    
    
    
    
    
}
button:hover{
    background-color: #bbb;
}

button:active{
    background-color:#aaa;
}

input{
    height: 40px;
    width: 246px;
    font-size: 1.5em;
    background-color: beige;
    border: none;
    padding-left: 10px;
}
<!DOCTYPE html>
<html>
<head><title>JavaScript Calculator!</title></head>
    <link rel="stylesheet" type="text/css" href="calccss.css"> 

    
<body>
    <div >
    <form name="calc">
    <input class="inputc" type="text" name="panel" value="0" readonly="readonly"/> 

    
    
    
    
    <span><button type="button" onclick="onMouseClick()" value="C" name="c">C</button></span><span><button type="button" onclick="onMouseClick()" value="/" name="div">/</button></span><span><button type="button" value="X" onclick="onMouseClick()" name="x">X</button></span><span><button type="button" onclick="onMouseClick()" value="-" name="minus">-</button></span>
    
    <span><button type="button" onclick="onMouseClick()" value="7" name="seven">7</button></span> <span><button type="button" onclick="onMouseClick()" value="8" name="eight">8</button></span><span><button type="button" value="9" onclick="onMouseClick()" name="nine">9</button></span><span><button type="button" onclick="onMouseClick()" value="+" name="plus">+</button></span>
    
     <span><button type="button" onclick="onMouseClick()" value="4" name="four">4</button></span> <span><button type="button" onclick="onMouseClick()" value="5" name="five">5</button></span><span><button type="button" onclick="onMouseClick()" value="6" name="six">6</button></span><span><button type="button" style="height:128px" onclick="onMouseClick()" value="=" name="equals">=</button></span>
    
    <span><button type="button" value="1" onclick="onMouseClick()" name="one">1</button></span> <span><button type="button" onclick="onMouseClick()" value="2" name="two">2</button></span><span><button type="button" onclick="onMouseClick()" value="3" name="three">3</button></span>
    
    <span><button style ="width:125px" type="button" onclick="onMouseClick()" value="0" name="zero">0</button></span> <span><button type="button" onclick="onMouseClick()" value="coma" name="coma">,</button></span>
    
    </form></div>
     
<script src="calcjs.js"></script>   
</body>



</html>

Answer №1

To align the equals button to the right, consider floating it with the CSS property float: right.

Make sure to adjust the width of your form element for proper alignment. It's best to use whole pixel values for margin to ensure consistency across different browsers.

You could also experiment with floating the spans or removing them entirely in the CSS styling.

Answer №2

This is the latest HTML code snippet:

<span><button type="button" style="height:128px;float:right;" onclick="onMouseClick()" value="=" name="equals">=</button></span>

Check out the working example on Plunker

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

Building a concealed navigation bar using HTML and Typescript that appears when you start scrolling - here's how!

Seeking guidance on creating a hidden navbar that becomes visible as you scroll the page, using TypeScript. Can anyone provide assistance? <nav class="navbar navbar-expand-lg navbar-dark pb_navbar pb_scrolled-light w3-animate-right navlist-right ...

If an element with a "hidden" display property is loaded in the browser window, will it be visible?

Is an element in a hidden display still using memory when the page is loaded? It's convenient to have many elements on a page, but if 99 elements are hidden and only 1 is displayed, does that impact the loading of the page? I'm curious if the pa ...

Identifying android devices with low resolution

Is there a method to determine if the current user is utilizing a low-resolution device (less than 320px) and then apply a distinct stylesheet specific to that user? ...

Adjusting the line height of an inline-block div causes surrounding inline-block siblings to shift downward

As I venture into exploring the line-height property, I came across information on MDN which stated: For non-replaced inline elements, it determines the height used in calculating the line box height. However, in this scenario, when I set the line-heigh ...

Reduce the size of the profile picture in the Facebook like box

I have a Facebook like box on my site but in some resolutions the profile pictures goes to next line after 2 pictures instead of 3 so I want to make the profile pictures width and height 49 instead of 50 because that would fix the problem. Here's how ...

Issue with ellipsis not functioning correctly on dynamic placeholders when they are in focus

When I focus on my dynamic placeholder input, the text-overflow: ellipsis property is lost for some reason. However, it is regained when blurred. Can anyone explain why this is happening? If you want to experiment with it, I have set up a stackblitz: htt ...

The right-floating div element is not displaying horizontally; instead, it is breaking into a new line

My issue is the dynamically added div elements are not displaying horizontally within a container div element with a specific width. They always break into a new line. Below is the code snippet I am using: var i=1; $(document).ready(function () { ...

Exploring the process of creating a personalized breakpoint for a responsive toggle menu in Bootstrap 4

Is there a way to set a custom breakpoint for a responsive toggle menu in Bootstrap 4? I want the toggle menu to appear when the screen size is less than a certain width, regardless of the specific size. Does anyone have an example that they could share? ...

Revamping the pre-existing css of Firefox 11

Is there a way to remove the 8px margin from the body tag? I've attempted a few different solutions: * { padding:0; margin:0; } as well as html, body { padding:0; margin:0 !important; } and body { margin:-8px; } and even <body style="m ...

Enhance the styling of elements generated through JavaScript in VueJs with custom CSS

I need help applying CSS to elements that I dynamically created using JavaScript. buttonClicked(event) { console.log(event); let x = event.clientX - event.target.offsetLeft; let y = event.clientY - event.target.offsetTop; let ripples = document.cre ...

Switch the visibility of an HTML input styled as a "spinner"

I have managed to create a CSS-based method for toggling the visibility of span or input elements depending on whether a radio button is checked. I got inspired by this insightful question on Stack Overflow. However, I encountered an issue where this togg ...

The presence of the `class` attribute on the `td` element

Is there a reason why the rows with the "odd" td class in this script do not toggle to blue like the rows without the "odd" class? EDIT: When you click on a row (tr), it is supposed to turn blue (.hltclick) and return to its original color when clicked ag ...

Animate failed due to the appending and adding of class

$('#clickMe').click(function() { $('#ticketsDemosss').append($('<li>').text('my li goes here')).addClass('fadeIn'); }); <link href="http://s.mlcdn.co/animate.css" rel="stylesheet"/> <script ...

Is there a way to specifically load a CSS file in Meteor for only one individual page?

Is there a way to load three specific css files only on certain pages or templates in Meteor? I attempted appending the css files to the head area upon template creation, but they ended up staying loaded even when navigating away from the page. Any sugge ...

Stop the Bootstrap navbar from breaking into separate lines when resizing the screen by ensuring it collapses into an icon

I have a straightforward Bootstrap Navbar that contains just a few items. When the width is less than 768, it displays in two rows. How can I make both items display in a single row at all widths without using the collapse feature? <nav class="na ...

When the section comes into view on the screen, the CSS animation will play only one time

While browsing through , I found some fantastic animations that inspired me. The animations at the header seem to be standard CSS animations with delays. However, as you scroll down and other sections become visible, the animations reappear only once. Can ...

Will the rel attribute work in all web browsers and with all HTML tags?

Confirming that it is compatible for use with JQuery scripting. ...

Is the Bootstrap SASS custom button invisible within tables or cards?

I recently revamped the btn-default style in Bootstrap 3 by adding some SCSS code. When I apply this button directly on a page, it looks fine. However, when I use it inside a table or a card, all I see is the border and text with a transparent background a ...

At smaller desktop resolutions, the 1px border thickness for tables may fluctuate

The border thickness of my table is inconsistent at 1px. This issue only occurs in smaller desktop breakpoints and works fine on higher resolutions. Attached below is a screenshot for reference. https://i.sstatic.net/gPsaT.png Below is the code I used to ...

Remove underlining from a Custom Link when hovering over it

Is there a way to remove the blue underline from my custom donate button? I created it by going to Appearance -> Menus -> Custom Link. The issue is that this custom link (donate button) is inheriting the same CSS as the navigation menu items, which I ...