html - 为什么将 Bootstrap 按钮放入 DIV 后会停止工作?

标签 html css django twitter-bootstrap

我有 2 个按钮,我试图将它们放在页面的中心位置并排放置。最简单的方法是将它们放在一个 div 中,但是当我这样做时,按钮变得没有响应。他们失去了悬停和点击功能。我试过更改我的背景 div、包装 div 和按钮的 z-index,但这没有做任何事情。这是我的代码:

<!DOCTYPE html>
<html>
{% load staticfiles %}
{% load rest_framework %}
<head>
    <link type="text/css" rel="stylesheet" href="https://bootswatch.com/yeti/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="{% static 'app/index.css' %}">
<title>Home</title>
</head>

<body>
{% if messages %}
    {% for message in messages %}
        {{ message }}
    {%endfor%}
{%endif%}
{% verbatim %}
<div id="background"></div>
<div id="wrapper">
    <a href="/signup" class="btn btn-primary">Sign Up Now!</a>
    <a href="" class="btn btn-info">Learn More</a>
</div>

<div id="topwrapper">
    <a href="/login">
        <div id="login">Log in</div>
    </a>
    <a href="/signup">
        <div id="signup">Sign Up</div>
    </a>
</div>
<h1>Catchy Interesting Hook.</h1>
<p>Lorem ipsum stuff blah blah blah</p>
<h2>What is this website?</h2>
{% endverbatim %}
</body>
</html>

topwrapper div 中的链接有效,但它们不是 Bootstrap 按钮。注意:{% %} 中有趣的代码是 Django 的东西,我已经安装了各种 django-bootstrap 插件所以也许这就是我的按钮的问题?但我是 django 的新手,所以我真的不知道如何去调查它。然后我的 CSS 是:

#background {
    background-color: #5f6273;
    height: 500px;
    position: absolute;
    padding: 0px 0px 0px 0px;
    border-width: 0px;
    margin: 0px 0px 0px 0px;
    top: 0px;
    left: 0px;
    right: 0px;
    z-index: -30;
}
#wrapper {
    text-align: center;
    margin: 0 auto;
    margin-top: 300px;
    background: none;
    width: 320px;
    display: inline;
    z-index: -1;
}
#topwrapper {
    width: 300px;
    display: inline;
    background-color: none;
    margin: auto;
    height: 100px;
    margin-right: 0;
    z-index: 0;
    padding: 20px;
}
#login {
    border-radius: 2px;
    border-color: #ffffff;
    height: 30px;
    width: 140px;
    left: 30%;
    margin: auto;
    padding-top: 10px;
    text-align: center;
    font-family: sans-serif;
    color: #ffffff;
    z-index: 30;
}
#signup {
    left: -50%;
    font-family: sans-serif;
    color: #ffffff;
    height: 30px;
    width: 70px;
    z-index: 30;
    margin: auto;
}
.btn-primary {
    float: left;
    margin-left: auto;
    z-index: 31;
}
.btn-info {
    float: right;
    margin-right: auto;
    z-index: 31;
}
h1 {
    font-family: sans-serif;
    text-align: center;
    color: #ffffff;
    padding-top: 160px;
}
h2 {
    font-family: sans-serif;
    text-align: center;
    color: #000000;
    padding-top: 275px;
    z-index: 30;
}
p {
    font-family: serif;
    text-align: center;
    color: #ffffff;
    padding-top: 0px;
}

最佳答案

我保持你所有的 css 相同,但在删除 django 内容的同时在 html 中做了一点改动......并且链接正在工作。尝试将您的 Django 代码添加到此:

<body>
    <div id="background"></div>
    <div id="wrapper">
        <button class="btn btn-primary"><a href="/signup">Sign Up Now!</a></button>
        <button class="btn btn-primary"><a href="/login">Learn More</a></button>
    </div>

    <div id="topwrapper">
        <a href="/login">
            <div id="login">Log in</div>
        </a>
        <a href="/signup">
            <div id="signup">Sign Up</div>
        </a>
    </div>
    <h1>Catchy Interesting Hook.</h1>
    <p>Lorem ipsum stuff blah blah blah</p>
    <h2>What is this website?</h2>
</body>

关于html - 为什么将 Bootstrap 按钮放入 DIV 后会停止工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37795141/

相关文章:

Javascript 和 HTML 似乎无法正常工作

html - iPad 上可滚动 div 的问题

css - Canvas 底部有空白,滚动得太远

django - 如何应用 Django 补丁

javascript - 在选择选项中更改颜色 - HTML/CSS/JQuery - Mac

html - 为什么我不能在 ASP.NET 的 HTML 属性中使用 ContentPlaceholder?

jquery - SharePoint 搜索和搜索范围框相互堆叠

python - Django-oscar 错误 - django.core.exceptions.ImproperlyConfigured : Application labels aren't unique, 重复项:静态文件

django - 如何将单个参数的多个值传递到 Django Rest Framework 中的 API url?

javascript - 仅将 CSS 应用于与父级同一类的最内层元素