Why would max-width not work on this?

后端 未结 3 1065
广开言路
广开言路 2021-02-02 12:31

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;
  p         


        
相关标签:
3条回答
  • 2021-02-02 12:33
    button {
      text-align: center;
      max-width: 540px;
      height: auto;
      display: block;
      padding: 10px 0;
      margin: 0 auto;
      border: none;
    
      width:100%; /* you forgot this */
    }
    
    0 讨论(0)
  • 2021-02-02 12:53

    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/

    0 讨论(0)
  • 2021-02-02 12:58

    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!

    0 讨论(0)
提交回复
热议问题