我遇到了一些用于样式按钮的CSS,我正在使用这些按钮效果很好。但是我的代码根据按钮文本创建了一个自扩展宽度按钮。
我想把两个按钮放在一起,让它们具有完全相同的宽度,无论按钮文字如何。
任何人都可以告诉我如何调整现有的CSS以实现此目的吗?
/*-- MY CSS READ MORE BUTTON --*/
a.btn,
.btn,
.btn:focus,
input[type="submit"],
a.more-link {
padding: 13px 30px;
line-height: 1;
color: #000000;
border: 1px solid #d9d9d9;
border-radius: 3px;
text-align: left;
text-shadow: none;
text-decoration: none;
vertical-align: middle;
cursor: pointer;
background: #ffffff;
filter: none;
box-shadow: none;
text-align: center;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 2px;
}
a,
a.btn,
.btn,
.btn:focus,
input[type="submit"],
.btn:hover,
input[type="submit"]:hover,
{
-webkit-transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
/*-- EDIT HERE FOR COLOUR CHANGE ON HOVER --*/
.btn:hover,
input[type="submit"]:hover,
a.more-link:hover {
background: #7acfd6;
border-color: #cccccc;
color: #fff;
}
/*-- EDIT HERE FOR ACTIVE BUTTON COLOUR --*/
.btn:active,
.btn-primary,
.btn-primary:focus {
color: #ffffff;
background: #000000;
box-shadow: none;
}
.btn-primary:hover,
.btn-primary:active {
background: #000000;
}
.btn.alt {
background: #9BA78A;
border-color: #9BA78A;
color: #ffffff;
}
.btn.alt:hover {
background: #000000;
color: #ffffff;
border-color: #000000;
}
<p style="text-align: center;"><a class="btn" href="#">Learn more</a>
</p>
答案 0 :(得分:0)
你只需要通过给他们一个CSS规则&#34; display:block&#34;来制作按钮块元素。然后你可以使用&#34;宽度:200px&#34;给它们一个固定的宽度,如200px。有关工作示例,请参阅下面的代码。
/*-- MY CSS READ MORE BUTTON --*/
a.btn,
.btn,
.btn:focus,
input[type="submit"],
a.more-link {
padding: 13px 30px;
line-height: 1;
color: #000000;
border: 1px solid #d9d9d9;
border-radius: 3px;
text-align: left;
text-shadow: none;
text-decoration: none;
vertical-align: middle;
cursor: pointer;
background: #ffffff;
filter: none;
box-shadow: none;
text-align: center;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 2px;
display: block;
width: 200px;
margin: 10px auto;
}
a,
a.btn,
.btn,
.btn:focus,
input[type="submit"],
.btn:hover,
input[type="submit"]:hover,
{
-webkit-transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
/*-- EDIT HERE FOR COLOUR CHANGE ON HOVER --*/
.btn:hover,
input[type="submit"]:hover,
a.more-link:hover {
background: #7acfd6;
border-color: #cccccc;
color: #fff;
}
/*-- EDIT HERE FOR ACTIVE BUTTON COLOUR --*/
.btn:active,
.btn-primary,
.btn-primary:focus {
color: #ffffff;
background: #000000;
box-shadow: none;
}
.btn-primary:hover,
.btn-primary:active {
background: #000000;
}
.btn.alt {
background: #9BA78A;
border-color: #9BA78A;
color: #ffffff;
}
.btn.alt:hover {
background: #000000;
color: #ffffff;
border-color: #000000;
}
&#13;
<p style="text-align: center;"><a class="btn" href="#">Learn more</a>
</p>
<p style="text-align: center;"><a class="btn" href="#">Click here</a>
</p>
&#13;
答案 1 :(得分:0)
为您的问题做一个简单的调整。。刚刚将min-width:130px
添加到.btn
/*-- MY CSS READ MORE BUTTON --*/
a.btn,
.btn,
.btn:focus,
input[type="submit"],
a.more-link {
padding: 13px 30px;
line-height: 1;
color: #000000;
border: 1px solid #d9d9d9;
border-radius: 3px;
text-align: left;
text-shadow: none;
text-decoration: none;
vertical-align: middle;
cursor: pointer;
background: #ffffff;
filter: none;
box-shadow: none;
text-align: center;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 2px;
}
a,
a.btn,
.btn,
.btn:focus,
input[type="submit"],
.btn:hover,
input[type="submit"]:hover,
{
-webkit-transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
min-width:130px
}
/*-- EDIT HERE FOR COLOUR CHANGE ON HOVER --*/
.btn:hover,
input[type="submit"]:hover,
a.more-link:hover {
background: #7acfd6;
border-color: #cccccc;
color: #fff;
}
/*-- EDIT HERE FOR ACTIVE BUTTON COLOUR --*/
.btn:active,
.btn-primary,
.btn-primary:focus {
color: #ffffff;
background: #000000;
box-shadow: none;
}
.btn-primary:hover,
.btn-primary:active {
background: #000000;
}
.btn.alt {
background: #9BA78A;
border-color: #9BA78A;
color: #ffffff;
}
.btn.alt:hover {
background: #000000;
color: #ffffff;
border-color: #000000;
}
<p style="text-align: center;"><a class="btn" href="#">Learn more</a>
</p>
<p style="text-align: center;"><a class="btn" href="#">Learn</a>
</p>
<p style="text-align: center;"><a class="btn" href="#">More More More</a>
</p>
答案 2 :(得分:0)
这是一个建议:
p
元素显示为inline-block
p {
display: inline-block;
}
.btn {
display: flex;
flex-direction: column;
margin: 2px 0;
}
/*-- MY CSS READ MORE BUTTON --*/
a.btn,
.btn,
.btn:focus,
input[type="submit"],
a.more-link {
padding: 13px 30px;
line-height: 1;
color: #000000;
border: 1px solid #d9d9d9;
border-radius: 3px;
text-align: left;
text-shadow: none;
text-decoration: none;
vertical-align: middle;
cursor: pointer;
background: #ffffff;
filter: none;
box-shadow: none;
text-align: center;
font-size: 10px;
text-transform: uppercase;
letter-spacing: 2px;
}
a,
a.btn,
.btn,
.btn:focus,
input[type="submit"],
.btn:hover,
input[type="submit"]:hover,
{
-webkit-transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
transition: color 0.2s ease, background 0.6s ease, border-color 0.2s ease;
}
.btn {
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.42857143;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
}
/*-- EDIT HERE FOR COLOUR CHANGE ON HOVER --*/
.btn:hover,
input[type="submit"]:hover,
a.more-link:hover {
background: #7acfd6;
border-color: #cccccc;
color: #fff;
}
/*-- EDIT HERE FOR ACTIVE BUTTON COLOUR --*/
.btn:active,
.btn-primary,
.btn-primary:focus {
color: #ffffff;
background: #000000;
box-shadow: none;
}
.btn-primary:hover,
.btn-primary:active {
background: #000000;
}
.btn.alt {
background: #9BA78A;
border-color: #9BA78A;
color: #ffffff;
}
.btn.alt:hover {
background: #000000;
color: #ffffff;
border-color: #000000;
}
<p style="text-align: center;">
<a class="btn" href="#">Learn more</a>
<a class="btn" href="#">Learn more and more</a>
<a class="btn" href="#">Learn more and more and more</a>
</p>
<hr>
<p style="text-align: center;">
<a class="btn" href="#">Learn more</a>
<a class="btn" href="#">Learn more and more</a>
<a class="btn" href="#">Learn more and more and more and more again</a>
</p>