最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

html - How do I put a button to the bottom of a box? - Stack Overflow

matteradmin4PV0评论

I have recently started using html in order to create a website for my project. I have planned on making this website that contains the intro page, that has a button, revealing further contents. This is my current html code:

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(".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=":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>

I have recently started using html in order to create a website for my project. I have planned on making this website that contains the intro page, that has a button, revealing further contents. This is my current html code:

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/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/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>

Everything turns out to be good, except for the "know more button" that I expected to be in the bottom of the box. (shown below)

I would like to ask for your help in order to make the button appear at the right place. :)

Share Improve this question edited Nov 17, 2024 at 13:49 Rob 15.2k30 gold badges48 silver badges73 bronze badges asked Nov 17, 2024 at 3:42 Srijan SinghSrijan Singh 91 bronze badge 1
  • If the answer helped solve your problem you can mark it as solved using the grey tick on the left of the answer. – stickynotememo Commented Nov 24, 2024 at 23:35
Add a comment  | 

1 Answer 1

Reset to default 1

The div of your button is not nested inside the box div. This means it will appear outside of the box.

It should look something like this:

    <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>
Post a comment

comment list (0)

  1. No comments so far