【问题标题】:I want to join 2 html pages but getting distorted output我想加入 2 个 html 页面,但输出失真
【发布时间】:2022-01-20 06:45:01
【问题描述】:

我有两个 html 页面,一个用于导航栏,另一个用于联系表单,当我尝试加入它们时,我得到一个扭曲的单页。图片将包含在下面。我尝试制作部分,但没有帮助:/ 这是一个 django 项目,所以代码可能略有不同。在此先感谢:)

导航栏的html

    <nav>
        <div class="logo">
            <a class="h4" href="{% url 'home' %}">Nihaal Nz</a>
        </div>
        <ul class="nav-links">
            <li><a href="{% url 'about' %}">About</a></li>
            <li><a href="#">Cool Cloud</a></li>
            <li><a href="{% url 'contact' %}">Contact</a></li>
        </ul>
    </nav>

联系页面的html

<div class="container">
            <form class="shake" action="{% url 'contact' %}" role="form" method="post" id="contactForm"
                  name="contact-form" data-toggle="validator">
                {% csrf_token %}
                <h2>Let me know what you felt.</h2>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="name" required="required">
                            <span class="text">First Name</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="email" required="required">
                            <span class="text">Email</span>
                            <span class="line"></span>
                        </div>
                    </div>
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="subject" required="required">
                            <span class="text">Subject</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox textarea">
                            <textarea name="message" required data-error="Write your message"></textarea>
                            <span class="text">Type your message here...</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <input type="submit" value="Send">
                    </div>
                </div>
        </div>

组合html代码

{% load static %}
<link rel="stylesheet" href="{% static "portofolio/css/contacts.css" %}">

{% block content %}
    <body>
    <section>
        <nav>
            <div class="logo">
                <a class="h4" href="{% url 'home' %}">Nihaal Nz</a>
            </div>
            <ul class="nav-links">
                <li><a href="{% url 'about' %}">About</a></li>
                <li><a href="#">Cool Cloud</a></li>
                <li><a href="{% url 'contact' %}">Contact</a></li>
            </ul>
        </nav>
    </section>
        <div class="container">
            <form class="shake" action="{% url 'contact' %}" role="form" method="post" id="contactForm"
                  name="contact-form" data-toggle="validator">
                {% csrf_token %}
                <h2>Let me know what you felt.</h2>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="name" required="required">
                            <span class="text">First Name</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="email" required="required">
                            <span class="text">Email</span>
                            <span class="line"></span>
                        </div>
                    </div>
                    <div class="col">
                        <div class="inputBox">
                            <input type="text" name="subject" required="required">
                            <span class="text">Subject</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <div class="inputBox textarea">
                            <textarea name="message" required data-error="Write your message"></textarea>
                            <span class="text">Type your message here...</span>
                            <span class="line"></span>
                        </div>
                    </div>
                </div>
                <div class="row100">
                    <div class="col">
                        <input type="submit" value="Send">
                    </div>
                </div>
        </div>
    </body>
{% endblock %}

导航栏的css

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    min-height: 12vh;
    background-color: rgba(93, 73, 84,0.5);
    font-family: 'Poppins', sans-serif;
}
.logo {
    color: rgb(226,226,226);
    text-transform: uppercase;
    letter-spacing: 5px;
    font-size: 20px;
    text-decoration: none;
}
.nav-links{
    display: flex;
    justify-content: space-around;
    width: 30%;
}
.nav-links li{
    list-style: none;
}
.nav-links a{
    color: rgb(226,226,226);
    text-decoration: none;
    letter-spacing: 3px;
    font-weight: bold;
    font-size: 14px;
}
.h4{
    text-decoration: none;
    color: rgb(226,226,226)
}

联系页面的css

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}
body{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #051115;
    font-family: 'Poppins', sans-serif;
}
.container {
    width: 80%;
    padding: 20px;
}
.container h2{
    width: 100%;
    color: #45f3ff;
    font-size: 36px;
    text-align: center;
    margin-bottom: 10px;
}
.container .row100{
    position: relative;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(300px,1fr));
}
.container .row100 .col {
    position: relative;
    width: 100%;
    padding: 0 10px;
    margin: 30px 0 10px;
    transition: 0.5s;
}
.container .row100 .inputBox{
    position: relative;
    width: 100%;
    height: 40px;
    color: #45f3ff;
}
.container .row100 .inputBox input,
.container .row100 .inputBox.textarea textarea{
    position: absolute;
    width: 100%;
    height: 100%;
    background: transparent;
    box-shadow: none;
    border: none;
    outline: none;
    font-size: 18px;
    padding: 0 10px;
    z-index: 1;
    color: #000000;
}
.container .row100 .inputBox .text{
    position: absolute;
    top: 0;
    left: 0;
    line-height: 40px;
    font-size: 18px;
    padding: 0 10px;
    display: block;
    transition: 0.5s;
    pointer-events: none;
}
.container .row100 .inputBox input:focus + .text,
.container .row100 .inputBox input:valid + .text {
    top: -35px;
    left: -10px;
}
.container .row100 .inputBox .line{
    position: absolute;
    bottom: 0;
    display: block;
    width: 100%;
    height: 2px;
    background: #45f3ff;
    transition: 0.5s;
    border-radius: 2px;
    pointer-events: none;
}
.container .row100 .inputBox input:focus ~ .line,
.container .row100 .inputBox input:valid ~ .line{
    height: 100%;
}
.container .row100 .inputBox.textarea{
    position: relative;
    width: 100%;
    height: 100px;
    padding: 10px 0;
}
.container .row100 .inputBox.textarea textarea{
    height: 100%;
    resize: none;

}
.container .row100 .inputBox textarea:focus + .text,
.container .row100 .inputBox textarea:valid + .text {
    top: -35px;
    left: -10px;
}
.container .row100 .inputBox textarea:focus ~ .line,
.container .row100 .inputBox textarea:valid ~ .line{
    height: 100%;
}
input[type="submit"]{
    border: none;
    padding: 7px 35px;
    cursor: pointer;
    outline: none;
    background: #45f3ff;
    color: #000000;
    font-size: 18px;
    border-radius: 2px;
}

【问题讨论】:

    标签: html css django


    【解决方案1】:

    body CSS 上的display:flex 会导致此问题,请将其更改为阻止(或其他内容),它应该按照您的意愿排列:

    body {
        display: block;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        background: #051115;
        font-family: 'Poppins', sans-serif;
    }
    

    【讨论】:

    • 我已将您的 HTML/CSS 粘贴到 codepen 并将正文样式更改为 display: block 并且可以正常工作,唯一的其他区别是 Django 模板内容已被删除
    • 兄弟一定是我的问题,生病了,你问答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-24
    • 2016-05-23
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多