我一直试图获得一个带有背景的按钮,我终于实现了,但现在我遇到了另一个问题,我似乎无法得到任何解决方案,因为文本是正确的位置,但带有图像的按钮在其上方偏移。我想要做的就是将按钮和图像放在文本下面。
html {
overflow: hidden;
-webkit-font-smoothing: antialiased;
}
body {
background-image: url(screenshots/main.png);
background-repeat: no-repeat;
background-size: 100% 110%;
height: 100%;
width: 100%;
position: fixed;
box-shadow: 0 0 2px rgba(0, 0, 0, 0.06);
color: #545454;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 16px;
line-height: 1.5;
margin: 0;
padding: 0;
text-align: center;
font-weight: 100;
}
html,
body {
height: 100%;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #222;
font-weight: 600;
line-height: 1.3;
}
h1 {
text-align: center;
vertical-align: middle;
margin-top 100px;
}
h2 {
margin-top: 1.3em;
}
a {
text-decoration: none;
color: #0083e8;
}
b,
strong {
font-weight: 600;
}
samp {
display: none;
}
img {
animation: colorize 2s cubic-bezier(0, 0, .78, .36) 1;
background: transparent;
display: inline-block;
margin: 0;
max-width: 100%;
height=125px width=222px white-space: nowrap;
}
.buttons a {
display: inline-block;
margin: 60px 20px 0;
height: 125px;
width: 222px;
border-radius: 7px;
border: 4px solid;
border-color: rgb(216, 216, 216) rgb(209, 209, 209) rgb(186, 186, 186);
padding: 0;
font-size: 11px;
color: #000;
line-height: 125px;
text-align: center;
}
.dust2 {}
@keyframes colorize {
0% {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
}
100% {
-webkit-filter: grayscale(0%);
filter: grayscale(0%);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>CS:GO Interactive Tools</title>
<meta name="description" content="Raisaga's interactive CS:GO map and tools.">
<link rel="stylesheet" href="main.css">
</head>
<body>
<h1>Rai's CS:GO <br /> Interactive Tool</h1>
<div class="buttons">
<a href="dust2.html"><img src="screenshots/MapBGs/Dust2.jpg">DUST 2</a>
<a href="mirage.html">MIRAGE</a>
<a href="cache.html">CACHE</a>
<a href="overpass.html">OVERPASS</a>
<a href="inferno.html">INFERNO</a>
<a href="train.html">TRAIN</a>
<a href="cobblestone.html">COBBLESTONE</a>
<a href="office.html">OFFICE</a>
</div>
</body>
</html>
答案 0 :(得分:0)
你想要达到这样的目标吗?
我所做的就是改变你的按钮样式
.buttons a{
display: inline-block;
height: 125px;
width: 222px;
border-radius: 7px;
border: 4px solid;
border-color: rgb(216, 216, 216) rgb(209, 209, 209) rgb(186, 186, 186);
text-align: center;
margin: 60px 20px 0;
overflow: hidden;
}
.buttons a img{
width: 100%;
height: auto;
}
我还切换了html中的图像和文字
<a href="dust2.html">
<span class="heading">DUST 2</span>
<img src="screenshots/MapBGs/Dust2.jpg" />
</a>
看一下plunkr,让我知道这是否正确
- UPDATE -
你可以做的一种方法是给每个按钮一个背景图像而不是内嵌图像
OR
你可以绝对定位你的文字。像这样:
CSS
.heading{
color: #fff;
position: absolute;
z-index: 100;
top: 50px;
left: 85px;
}
HTML
<a href="dust2.html">
<span class="heading">DUST 2</span>
<img src="screenshots/MapBGs/Dust2.jpg">
</a>