Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGiuseppe Ardito
14,130 PointsCentering "submit" and "reset" button with attribute selector
I wanted to center the buttons "submit" and "reset".
I used the text-align property to do it as the class .inln is set with "display: inline-block;" :
@media (min-width: 769px) {
.inln {
width: auto;
display: inline-block;
}
}
but I noticed that it won't work if I use the attribute selectors and the "margin: auto" property:
input[type="submit"],
input[type="reset"] {
margin: auto;
}
Is "margin:auto" compatible with "inline-blocks" elements? Is there any other way to center these two elements?
3 Answers
Chris Whiteley
1,680 PointsAdd text-align:center to a containing element.
Antonio Jaramillo
15,604 PointsI added a p tag around the buttons and then set p to text-align: center on my selectors.css style sheet. It worked. I'm not sure if that is the best way of going about this, though.
Adrian Cacoveanu
4,275 PointsI was pondering at the same problem (I know this is a late reply) This is what i did to resolve the issue: First I set the div to max-width: 40%, after that I applied the following rules to the media query:
@media (min-width: 769px) {
.inln {
display: inline-block;
}
.default {
width: 45%;
}
.error {
width: 45%;
float: right;
}
}
this will make the buttons display inline with a 10% gap between them (it looks better).