如何将按钮放在框的底部?

问题描述 投票:0回答:1

我最近开始使用 html 为我的项目创建一个网站。我计划制作这个包含介绍页面的网站,该页面有一个按钮,可显示更多内容。 这是我当前的html代码:

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #24576c;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

#box {
    width: 80%;
    background-color: #D5C6EE;
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: auto;
    
}

#title {
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
}

#underline {
    border: none;
    height: 2px;
    background-color: #131E62;
    width: 100%;
    margin-bottom: 20px;
}

#content {
    font-size: 20px;
    text-align: justify;
    line-height: 1.6;
    flex-grow: 1;
}

.button {
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

#know-more-button {
    text-decoration: none;
    background-color: #AABFEF;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;

}

#know-more-button:hover {
    background-color: #0056b3;
}

body {
    background-image: url("https://c.wallhere.com/photos/c6/5c/chemistry_science_laboratories-1697571.jpg!d"); 
    background-size: cover; 
    background-repeat: no-repeat; 
    background-position: center; 
    height: 100vh;
    margin: 0; 
}
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chem project</title>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
</head>

<body>
    <div id="box">
        <h1 id="title">Brief Introduction</h1>
        <hr id="underline">
        <div id="content">
            <p>content</p>
        </div>
    </div>
    <br>
    <div id="button-container" class="button">
        <a id="know-more-button" href="secondpage.html">Know More</a>
    </div>

</body>
</html>

一切都很好,除了我期望位于盒子底部的“了解更多按钮”。 (如下图)

Image given

我想请求您的帮助,以使按钮出现在正确的位置。 :)

html css button alignment
1个回答
1
投票

按钮的

div
未嵌套在框 div 内。这意味着它将出现在盒子外面。

它应该看起来像这样:

    <div id="box">
        <h1 id="title">Brief Introduction</h1>
        <hr id="underline">
        <div id="content">
            <p>content</p>
        </div>
        <br>
        <div id="button-container" class="button">
            <a id="know-more-button" href="secondpage.html">Know More</a>
        </div>
    </div>
© www.soinside.com 2019 - 2024. All rights reserved.