css 我无法使用Bootstrap将元素居中,并且一个div的半径存在问题

sqxo8psd  于 2022-12-15  发布在  Bootstrap
关注(0)|答案(1)|浏览(170)

因此,我试图做一个使用HTML和Bootstrap登录表单,但我不能得到所有元素的中心对齐。他们似乎是在中心,但标题是由Bootstrap中心对齐是不是在一行垂直与其他元素。我正在使用网格,我需要的元素在中型和小型屏幕中心对齐。在中等屏幕中,我尝试按照12列网格的逻辑来填充空间,直到我到达中心,但元素仍然没有正确对齐。
我也不能应用所需的半径登录形式。我需要它是更圆。 Bootstrap 似乎不工作。CSS做,但它适用于所有的div半径

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="css/style.css" >
    <title>Social Network</title>
</head>

<body class="bg-primary">

<div class="row">
    <div class="col-3 col-md-6"></div>
        <header class="text-center fs-3 text-white my-5">
            SOCIAL NETWORK
        </header>
</div>

<div class="row">
    <div class="col-2 col-md-4 m-1"></div>
    <div class="rounded-3 text-center bg-light p-4 col-centered col-8 col-md-3 px-5">
        <div>
            <input type="email" class="form-control my-5" id="inputUsername" aria-describedby="emailHelp" placeholder="Username">
            <input type="password" class="form-control my-5" id="inputPassword1" placeholder="Password">
        </div>
        <div class="text-center">
            <button type="submit my-5" class="btn btn-primary">Log In</button>
        </div>
        <div class="text-center my-4 text-secondary">OR</div>
        <div class="text-center">
            <a class="text-decoration-none link-secondary" href="">Forgot Password?</a>
        </div>
    </div>
    <div class="col-md-3"></div>
    <div class="col-md-1"></div>
    <div class="col-md-1"></div>
</div>
<div class="row">
    <div class="col-1 col-md-3"></div>
    <div class="col-1 col-md-1"></div>
    <div class="text-center text-secondary rounded-pill col-8 col-md-3 bg-light my-4 py-3" id="signUp">
        <div class="text-centered">Don't have an account?    <a class="text-primary px-3" href="">Sign Up</a></div>
    </div>
    <div class="col-1 col-md-3"></div>
    <div class="col-md-2"></div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</body>
</html>
eblbsuwk

eblbsuwk1#

我根据你的Div框和布局为你设计了一个简单的例子。简而言之,你可以使用。
这里有几点需要注意。***居中***是通过使用Flex并将内容对齐到中心来实现的- d-flex justify-content-center
至于边界半径,我添加了一个名为***login-box***的规则,它将半径设置为20 px。
希望能有所帮助。

.login-box {
  background-color: #fff;
  border-radius: 20px;
}

.new-user-box {
  border-radius: 20px;
 }
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="css/style.css" >
    <title>Social Network</title>
</head>

<body class="bg-primary">

<div class="d-flex justify-content-center">
    <header class="text-center fs-3 text-white my-5">
        Social Network
    </header>
</div>
<div class="row d-flex justify-content-center ">
    <div class="col-6 login-box">
    <div>
                <input type="email" class="form-control my-5" id="inputUsername" aria-describedby="emailHelp" placeholder="Username">
                <input type="password" class="form-control my-5" id="inputPassword1" placeholder="Password">
            </div>
            <div class="text-center">
                <button type="submit my-5" class="btn btn-primary">Log In</button>
            </div>
            <div class="text-center my-4 text-secondary">OR</div>
            <div class="text-center mb-4">
                <a class="text-decoration-none link-secondary" href="">Forgot Password?</a>
            </div>
    </div>
</div>
<div class="row d-flex justify-content-center">
    <div class="text-center text-secondary col-6 bg-light my-4 py-3 new-user-box" id="signUp">
        <div class="text-centered">Don't have an account?    <a class="text-primary px-3" href="">Sign Up</a></div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

</body>
</html>

相关问题