我有一些按键设置与我的HTML,使他们都是一样的高度,利用这个CSS和HTML上<a>标签垂直居中文本在HTML
ul {
\t display: table;
\t padding: 0;
\t width: 90%;
\t margin: 5% auto;
\t list-style-type: none;
\t vertical-align: middle;
\t height: 20vh;
}
li {
\t display: block;
\t float: left;
\t vertical-align: middle;
\t text-align: center;
\t width: 50%;
\t height: 100%;
\t margin-top: 15px;
\t margin-right: 0;
}
li.third {
\t vertical-align: middle;
\t text-align: center;
\t margin: auto;
\t width: 50%;
}
.ghost-button {
\t color: rgb(9, 82, 85);
\t background: rgba(255, 255, 255, 0.01);
\t border: 1px solid rgb(9, 82, 85);
\t padding: 5px 5px;
\t margin: auto;
\t display: inline-block;
\t text-decoration: none;
\t width: 100%;
\t height: 100%;
\t vertical-align: middle;
}
.third a {
\t display: block;
\t margin-left: 50%;
\t vertical-align: middle;
}
.ghost-button:hover, .ghost-button:active {
\t color: #FFF;
\t background-color: rgb(9, 82, 85);
\t text-decoration: none;
}
a {
\t text-decoration: none;
\t vertical-align: middle;
\t color: rgb(9, 82, 85);
}
<ul>
<li><a class="ghost-button" class="ghost-button" href="S1A.php" class="ghost-button" >Check the newspaper classifieds
\t for affordable pieces </a></li>
<li><a class="ghost-button" class="ghost-button" href="S1B.php" class="ghost-button" >Check for garage sales within
\t walking distance </a></li>
<li class="third"><a class="ghost-button" class="ghost-button" href="S1C.php" class="ghost-button" >Do nothing</a></li>
</ul>
在我页面的按钮不重叠,这是我无法弄清楚的代码片段的问题。该片段还必须全页查看,否则不会发生该问题。对不起,这是我第一次使用代码段。
我想使文本垂直对齐,正如你所看到的,除非我错误地使用它,vertical-align: middle
不起作用。在.ghost按钮inline-block的到显示:
看起来垂直居中我的屏幕上。你使用的是什么浏览器?或者,也许我不明白这个问题。 – floor
您是否点击链接在整个页面中打开代码段?按钮变得更高,文本保持在顶部。 – Lordbug
是的,我看到全屏幕,按钮宽度扩大,但文本仍然看起来居中。我在Firefox中查看。我会复制到一个jsfiddle然后看看。 https://jsfiddle.net/srfp2c52/ – floor