html - 使按钮变大,但保持文本大小不变

标签 html css

html 中的按钮完美运行。但是我无法使用 CSS 为其设置正确的样式。

目标是让按钮看起来像这样: enter image description here

当我向按钮添加宽度或填充/边距时,它会破坏按钮样式。它也应该是响应式的。同样出于某种原因,我无法更改颜色/边框半径。 也尝试使用 anchor 标记来制作一个漂亮的按钮,但效果甚至不如这个按钮。

我还将 bootstrap 作为 CSS 单独运行。

片段:

#background-log {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #ffffff;
    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
.button-login {
    justify-content: center;
    align-items: center;
    margin: 10px;
    background-color: #6441a4;
}

.twitch {
  text-transform: uppercase;
  width: 100px;
}
<div id="background-log">
  <div class="button-login">
    <button class="twitch">Sign in with Twitch</button>
  </div>
</div>

最佳答案

首先为按钮设置 display:block; 使其成为 block 级元素,您可以在其上正确应用宽度和填充/边距。在按钮上使用 width 使其更宽,使用 padding 增加文本和按钮边框之间的空间并覆盖默认按钮值,如 borderbackground 包含您想要的值。

要使按钮具有响应性,您还可以使用百分比值作为宽度。您还可以添加 border-radiusbox-shadow 使其看起来更像您的图像。请参见下面的示例。

#background-log {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #ffffff;
  box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
}
.button-login {
  justify-content: center;
  align-items: center;
  margin: 10px;
}
.button-login button {
  display: block;
  text-transform: uppercase;
  width: 300px;
  color: #fff;
  border: none;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 2px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
}
.twitch {
  background-color: #6441a4;
}
.hitbox {
  background-color: #98cb01;
}
<div id="background-log">
  <div class="button-login">
    <button class="twitch">Sign in with Twitch</button>
    <button class="hitbox">Sign in with Hitbox</button>
  </div>
</div>

关于html - 使按钮变大,但保持文本大小不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38984348/

相关文章:

css - 在 h2 标签中跨度。自动调整宽度

css - 导入 typekit url 时使用字体显示

c# - 如何将此字符串转换为普通字符串以便将其放入 HTML 文档中?

javascript - jQuery 移动对象

javascript - 如何将滚动条附加到 div 部分?

html - bootstrap4 中网格/列之间的空间

html - CSS 字体大小细节

css - 在移动设备中加载时,我的网站右侧出现奇怪的边距

angularjs - 如何保持内容 div 的标题固定?

html - 可调整大小的固定页脚,其中包含绝对元素