I have 3 buttons. I would like them to display in a horizontal line, centered in the parent div. I cannot for the life of me get it to work. Every time I put any margin or anything on them, the first one goes to the upper right of the div, and the other two go to the left side and what seems to be the next row down. I have no idea why though. Can anyone explain what is going and help me out?
I can’t replicate that behaviour with that code.
If I can add one thing, maybe you wanted text-align: center; applied to the banner, not the buttons.
The text-align center is to center the text inside the buttons. I did try to put text-align center on the banner, but it did not have any effect. I’m so confused with what this is doing. If I move it over to my laptop monitor, they all sit on the very left side of the banner div. If I put it on my regular monitor, they all shift all the way to the right side of the banner div. I don’t understand why I’m getting this behavior.
Being inline-blocks the buttons will wrap to a new line if there is not sufficient width on the banner.
And by default they align to the left.
I guess the question is: what do you want it to look like on wide and narrow screens?
That’s odd, for me it centres the buttons in the banner and the text within the buttons (inherited from the banner).
A simple media query will do that. You just need to set the query at a safe width value to make the switch from display: block to display:inline-block taking into account any margins you want to add to the buttons.
Right, but that won’t fix what they are doing now. With no margin’s or any placement attributes on it this is what it looks like right now. I want them to be centered, with some space above and below, and space between them. But every time I put any type of margin on there, the My Paystub button goes all the way to the right and the other two go to the next row on the left.
That is quite different to what I’m seeing, here it is in codepen:-
All I changed was to add a margin to the buttons and moved the alignment to the banner.
Obviously there is more (different?) code in your complete page, so that likely accounts for the difference in layout.
And I believe I’m understanding this correctly. I have the MyPaystub button selected and it is showing no margins applied. It also does not show any margins applied for the other button, or the div surrounding it, or anything else surrounding t.
I think it has something to do with my navbar… I commented out the entire thing, and it works fine. For some reason, something in my navbar is overflowing and taking up space on that left side I think.
Evidently You are looking at different code to that you posted (I).
All I can see from you “Inspect” is a rule for box-sizing on the buttons, yet that does not exist in the code you posted.
Did you see the part where I said it has something to do with the navbar? I’ve had endless problems with my navbar, so I’m not surprised that it’s causing me problems yet again.
And from looking at your screenshot in post #10 I would almost bet that it is the sub-ul in your dropdown menu items. I’m assuming that’s what they are from the down arrows.
I’ll bet the sub-list are not absolute positioned, but just hidden with visibility:none; or something else that is still leaving them physically in place.
Try moving them off screen with margin-left:-999em; then margin-left:0; on hover
I can see that the “Monthly Newsletter” button comes back to center when it clears the obstruction.
And your dropdown list items are in the middle on your screenshot, so that explains it.
On your laptop the dropdowns are probably towards the right side.