因此,我试图创建一个带有小徽标图像,背景较暗,文本较浅的按钮。我设法做到了这一点,但是当我使用不同长度的不同文本时会出现问题。
我的问题是由于填充,文本未在中心对齐。但是,如果没有填充,文本将在图像后面滑动。有人可以帮我吗?
.is-button {
background-color: #1ea3ce;
border-radius: 4px;
color: #ffffff;
display: inline-flex;
font-weight: bold;
height: 100%;
margin-bottom: -20px;
width: 85%;
font-size: small;
line-height: 20px;
min-height: 80px;
padding: 1% 2% 1% 20%;
position: relative;
text-decoration: none;
text-transform: uppercase;
text-align: center;
align-items: center;
}
.is-button:hover {
filter: brightness(85%);
color: #ffffff !important;
-webkit-animation: none;
-webkit-transform: scale(1.01);
animation: none;
transform: scale(1.01);
}
.is-button .logo-button {
background-color: #1b88b3;
border-radius: 4px 0px 0px 4px;
display: inline;
height: inherit;
padding: 4% 5px;
position: absolute;
left: 0;
top: 0;
}
<p style="text-align: center;">
<a class="is-button" href="#"><img class="logo-button aligncenter" src="https://www.securityacademy.nl/wp-content/uploads/2019/12/seco-logo-klein.png" />Information Security Foundation</a>
</p>
答案 0 :(得分:3)
使用flex-box
css属性并使您的html语法更正确实际上很容易创建您想要的响应式内容:
.is-button {
display: flex;
background-color: #1ea3ce;
border-radius: 4px;
color: #ffffff;
height: 100%;
width: 85%;
position: relative;
text-decoration: none;
align-items: center;
}
.is-button:hover {
filter: brightness(85%);
color: #ffffff !important;
}
.is-button .logo-button {
background-color: #1b88b3;
border-radius: 4px 0px 0px 4px;
padding: 0 5px;
}
.is-button span {
width: 100%;
text-align: center;
text-transform: uppercase;
font-size: 1.5em;
font-weight: bold;
}
<p style="text-align: center;">
<a class="is-button" href="#">
<img class="logo-button aligncenter" src="https://www.securityacademy.nl/wp-content/uploads/2019/12/seco-logo-klein.png" />
<span>Information Security Foundation</span>
</a>
</p>
检出JsFiddle。
答案 1 :(得分:0)
使用CSS伪类:before
.is-button:before {
background-image:url('https://www.securityacademy.nl/wp-content/uploads/2019/12/seco-logo-klein.png');
background-size: 80px;
background-repeat:no-repeat;
content:"";
width:80px;
height:80px;
background-color: #1ea3ce;
border-radius: 4px 0px 0px 4px;
position:absolute;
top:10px;
left:10px;
}
.is-button {
background-color: #1ea3ce;
border-radius: 4px;
color: #ffffff;
font-weight: bold;
display:inline-block;
width: 85%;
font-size: small;
line-height: 20px;
position: relative;
text-decoration: none;
text-transform: uppercase;
text-align: center;
align-items: center;
padding-top:35px;
padding-bottom:35px;
padding-left:90px;
}
.is-button:hover {
filter: brightness(85%);
color: #ffffff !important;
-webkit-animation: none;
-webkit-transform: scale(1.01);
animation: none;
transform: scale(1.01);
}
<p style="text-align: center;">
<a class="is-button" href="#">Information Security Foundation</a>
</p>