[英]Bootstrap <a> tag button with Icon and Text vertically align middle
我想垂直中间对齐Bootstrap <a>
标签按钮的图标和文本,我的样式片段仅适用于<button>
标签,但<a>
标签失败。
在下面的代码片段中:
<button>
执行(我的愿望风格!) <a>
标签执行。 请注意:
.btn-giant { display: inline-block; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; margin-bottom: .3em; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a class="btn btn-giant btn-primary" href="/Mail"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Mail </a>
.btn-giant { display: flex!important; flex-direction:column; justify-content: center; align-items: center; float: left; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; margin-bottom: .3em; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a class="btn btn-giant btn-primary" href="/Mail"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Mail </a>
试试此代码
.btn-giant { display: inline-block; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; } #mail span { position: relative; top: 25px; } .mail-text{ position:relative; top:30px; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a id="mail" class="btn btn-giant btn-primary" href="/Mail"> <span class="glyphicon glyphicon-envelope mail" aria-hidden="true"></span><span class="mail-text">Mail</span> </a>
您需要在span glyphicon
添加上边距。
工作片段
.btn-giant { display: inline-block; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; margin-bottom: .3em; } #link { margin-top:0.45em ; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a class="btn btn-giant btn-primary" href="/Mail"> <span id="link" class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Mail </a>
.btn-giant { display: inline-block; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; margin-bottom: .3em; } .glyphicon-envelope{ margin : .5em; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a class="btn btn-giant btn-primary" href="/Mail"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Mail </a>
.btn-giant { display: inline-block; width: 120px; height: 120px; margin-bottom: 8px; margin-right: 5px; padding: 10px 15px; font-size: 12px; text-align: center; color: white; border-radius: 0; white-space: normal; } .btn-giant .glyphicon { font-size: 36px; display: block; margin-bottom: .3em; } .ver-mid { align-items: center; display: flex; height: 100vh; text-align: center; }
<link href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.2.3.min.js"></script> <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"></script> <div class="ver-mid"> <button class="btn btn-giant btn-primary" onclick="location.href='/Users';"> <span class="glyphicon glyphicon-user" aria-hidden="true"></span> Users </button> <a class="btn btn-giant btn-primary" href="/Mail"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span> Mail </a> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.