带<a> tag don&#39;t group together</a>的引导按钮

时间:2013-08-14 17:18:45

标签: html css twitter-bootstrap

首先,我对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标签添加到按钮,则该按钮不会分组。

以下是一些截图

http://imgur.com/a/G1d6C

3 个答案:

答案 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