Using plain old CSS, why won't 'max-width' not work on the following:
button {
text-align: center;
max-width: 540px;
height: auto;
display: block;
padding: 10px 0;
margin: 0 auto;
border: none;
}
The wrapper for this element:
#wrapper {
max-width: 1024px;
overflow: hidden;
position: relative;
margin: 0 auto;
padding: 0 50px;
text-align: center;
}
EDIT
Code added to jsfiddle: http://jsfiddle.net/BXdrG/
The max-width property defines the maximum width of an element. If the content is larger than the maximum width, it will automatically change the height of the element. If the content is smaller than the maximum width, the max-width property has no effect.
1280px and 1920px are the two standard widths for web design. A 1280px website will look great on laptops and mobile devices but not so great on large monitors. To ensure your site looks just as good on big screens as it does on small screens, set your max site width to 1920px or more.
max-width overrides width , but min-width overrides max-width .
To convert it to a fixed-width layout, simply add a fixed with to the #wrapper and set the margins to auto. Setting the margins to auto will cause the left and right margins to be equal no matter how wide the browser window is, which will cause your fixed-width layout to be positioned in the center of the browser.
For max-width
to work correctly, your element first needs a certain width
. Use 100% to achieve what you want. See here:
http://jsfiddle.net/QsHa9/
Ah ok, I misunderstood its use. To get a fluid button that won't stretch to massive sizes I added the following:
width:100%;
max-width: 540px;
Thanks commenters!
button {
text-align: center;
max-width: 540px;
height: auto;
display: block;
padding: 10px 0;
margin: 0 auto;
border: none;
width:100%; /* you forgot this */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With