Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
91 views
in Technique[技术] by (71.8m points)

html - How to change button size depending on device?

I have got a button on my website, which becomes tiny, when you visit it from mobile. I have tried a few things to fix this, but they failed to complete my objective.

#generate {
  background-color: #FFAF19;
  outline: none;
  border: none;
  color: white;
  border-radius: 10px;
  width: 200px;
  height: 50px;
  font-family: 'Cabin', sans-serif;
  font-weight: bolder;
  font-size: 25px;
  position: fixed;
  top: 50%;
  left: 50%;
  margin-top: -50px;
  margin-left: -100px;
}

#generate:hover {
  transition: .5s;
  background-color: #e59d16;
  box-shadow: 0 12px 16px 0 rgba(0, 0, 0, 0.24), 0 17px 50px 0 rgba(0, 0, 0, 0.19);
}

#generate:active {
  transition: .1s;
  background-color: #e59d16;
  transform: translateY(4px);
}

@media screen and (min-width: 601px) {
  #generate {
    width: 200px;
    height: 50px;
  }
}

@media screen and (max-width: 600px) {
  #generate {
    width: 200px;
    height: 50px;
  }
}
question from:https://stackoverflow.com/questions/65882604/how-to-change-button-size-depending-on-device

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The size of the button actually needs to be different on smaller screen sizes if you want it to increase in size. So change it in @media screen and (max-width: 600px).

Here is an example:

#generate {
    background-color: #FFAF19; outline: none; border: none; color: white; border-radius: 10px; width: 200px; height: 50px; font-family: 'Cabin', sans-serif; font-weight: bolder; font-size: 25px; position: fixed; top: 50%; left: 50%; margin-top: -50px; margin-left: -100px;
  }
  #generate:hover {
    transition: .5s;
    background-color: #e59d16;
    box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
  }
  #generate:active {
    transition: .1s;
    background-color: #e59d16;
    transform: translateY(4px);
  }
  @media screen and (min-width: 601px) {
    #generate {
      width: 200px; height: 50px; 
    }      
  }
  @media screen and (max-width: 600px) {
    #generate {
      width: 300px; height: 75px;  
    }
  }
<button id="generate">Generate</button>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...