首先,我对HTML很新,所以这可能很简单。
<div class="btn-group pull-center" style="text-align:center">
<button class="btn btn-large btn-primary" type="button">Home</button>
<button class="btn btn-large btn-primary" type="button">Forum</button>
<button class="btn btn-large btn-primary" type="button">Bans</button>
<button class="btn btn-large btn-primary" type="button">Store</button>
<?php
if($_SESSION['isLogged'] == true) {
$username = $_SESSION['username'];
?> <a href="logout.php"><button class="btn btn-large btn-primary" type="button">Hello, <?php $username ?></button></a>
<a href="logout.php"><button class="btn btn-large btn-primary" type="button">Log out</button></a>
<?php }else {
?> <a href="login.php"><button class="btn btn-large btn-primary" type="button">Log in</button></a><?php
}
?>
</div>
一般来说,btn-group类是有效的,并且它们是分组的。但是,如果我将A标签添加到按钮,则该按钮不会分组。
以下是一些截图
答案 0 :(得分:4)
这适用于Bootstrap。我这里没有按钮:
<div class="btn-group">
<a class="btn">Home</a>
<a class="btn">Forum</a>
<a class="btn">Bans</a>
<a class="btn">Store</a>
<a href="logout.php" class="btn">Hello username</a>
<a href="logout.php" class="btn">Log out</a>
<a href="login.php" class="btn">Log in</a>
</div>
答案 1 :(得分:2)
您将.btn类放在<a>
标记内。但是,仅当.btn
元素是.btn-group
的直接子元素时,twitter-bootstrap框架组才会按下。实际上,规则可能是用.btn-group > .btn
写的。
将.btn
课程放在<a>
标签上,甚至删除此uselss按钮标签,它也会起作用。例如:
<div class="btn-group pull-center" style="text-align:center">
<a class="btn btn-large btn-primary" type="button">Home</a>
<a class="btn btn-large btn-primary" type="button">Forum</a>
<a class="btn btn-large btn-primary" type="button">Bans</a>
<a class="btn btn-large btn-primary" type="button">Store</a>
<a href="" class="btn btn-large btn-primary" type="button">Hello, Username</a>
<a href="logout.php" class="btn btn-large btn-primary" type="button">Log out</a>
</div>
答案 2 :(得分:1)
而不是使用按钮,只需将btn
类添加到a
标记即可。例如:
<div class="btn-group pull-center" style="text-align:center">
<a class="btn btn-large btn-primary">Home</a>
<a class="btn btn-large btn-primary">Forum</a>
<a class="btn btn-large btn-primary">Bans</a>
<a class="btn btn-large btn-primary">Store</a>
<a href="logout.php" class="btn btn-large btn-primary">Hello, Username</a>
<a href="logout.php" class="btn btn-large btn-primary">Log out</a>
<a href="login.php" class="btn btn-large btn-primary">Log in</a>
</div>
<强> Demo 强>