[英]Vertically Center Text
我的代码中的某些CSS出现问题。 使用引导程序,我创建了一个高度为400px的正方形,我想在其中放置垂直居中的文本。 我在悬停时使用JavaScript更改文本,这里的问题是,如果文本更改为两行,那么CSS将无法正常工作。
JSfiddle: https ://jsfiddle.net/Ljprxkrq/3/由于某种原因,Hover似乎在小提琴中不起作用。
<div class="col-xs-offset-1 col-xs-10 col-sm-offset-0 col-sm-4">
<div class="navigation-links">
<h2><a href="#" id="text-display" class="network"
onmouseover="changeText('More network information here')"
onmouseout="defaultText()">Network</a></h2>
</div>
</div>
.navigation-links {
height: 400px;
}
h2 {
font-family: 'Open Sans', sans-serif;
font-size: 40px;
text-align: center;
-webkit-font-smoothing: antialiased;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: white;
text-decoration: none;
}
尝试这个:
.navigation-links { background: #eee none repeat scroll 0 0; display: table-cell; height: 100px; vertical-align: middle; }
<div class="col-xs-offset-1 col-xs-10 col-sm-offset-0 col-sm-4"> <div class="navigation-links"> <h2><a href="#" id="text-display" class="network" onmouseover="changeText('More network information here')" onmouseout="defaultText()">Network</a></h2> </div> </div>
更新:
你可以添加类vertical-center
与navigation-links
像class="navigation-links vertical-center"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.