Any links to fully understanding alignment of html via CSS would be helpful. Every online tutorial and their mom explains the box (element, padding, border, margin), but I continue to struggle with display of elements in relation to each other (e.g. display, vertical-alignment, float, etc.)
My current specific question is in reference to my calculator skeleton.
I can’t get the bottom two rows of buttons aligned. Not sure how to best deal with the size differences. Perhaps I need to change the HTML?
They get a lot of hate these days, but you might consider using an HTML table for this. (You can make cells be more than one column wide or more than one row high.)
Thanks for the quick reply! Found the colspan and rowspan attributes for tables (that’s a nifty trick to know!). I’d really love to know how to solve this with CSS, if possible, for the sake of 1. above.
It would indeed make sense to use a table here. A simple CSS solution would be to make the width of .inputs exactly equal to the width that the buttons need and then use margin: auto to center it:
.inputs{
width: 292px;
margin: auto;
}
And the height of #equal should of course be 110px (100 + margin in between two buttons).
Thanks. May I ask how you’re getting the 292? I can only get 280 = (60width +10margin) * 4buttons
Maybe i’ll try all this again later with the table for practice. Seems that’s what everybody thinks I should do (and it makes sense, given it’s naturally a tabular layout)
This is the difficulty I allude to above. Aligning elements with pure CSS in a systematic way sometimes feels close to impossible.
Will check out grid as well. Thanks again to you and @ArielLeslie for your prompt assistance. Big fan of the moderator crew! I’ll do my best to give back to the community when I see a question I can answer!
Hey @bdfoz, what you’ve made is great and works fine. This is however a perfect place for using the new CSS Grid layout. I’ve recreated the calculator input area as a 4x5 grid with gutters. Then all you need to do for the equals and zero button is make them span two cells instead of one. Check it out: https://codepen.io/geddski/pen/LQbQzV
Grid is definitely an easier way to build these kinds of layouts.
table could definitely work, especially if you need to support older browsers. If you’re ok with just the modern ones though (Safari, Edge, Chrome, Firefox) then Grid would be a better way to go.