一旦我将列设为屏幕的100%,内容会在顶部对齐,而不是在中间。

huangapple go评论68阅读模式
英文:

Once I make the columns 100 percent of the screen, the contents are aligned on top, instead of the middle

问题

I want to set my column of size vh-100
however the moment I add that piece of code, it will shift everything to the top.

How do I go about avoiding this?
Specifically on the left side, the content has image, text1, text2
I want these three items centered on the left column
centered vertically and horizontally

.left-side {
  background-color: #012611;
  color: white;
}

h1 {
  font-family: "Monarcha";
  font-weight: bolder;
}

h3 {
  font-family: "Soleil";
}

label {
  font-family: "Monarcha";
}

.right-side {
  background-color: white;
}

div {
  outline: black solid 5px;
}
<!-- Left Column -->
<div class="col-lg-6 col-sm-6 vh-100 center-block text-center d-none d-sm-block left-side">
  <img src="../pictures/logo.png" alt="" width="72" height="72" />
  <h1>Text1</h1>
  <h3>Text2</h3>
</div>
英文:

I want to set my column of size vh-100
however the moment I add that piece of code, it will shift everything to the top.

How do I go about avoiding this?
Specifically on the left side, the content has image, text1, text2
I want these three items centered on the left column
centered vertically and horizontally

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.left-side {
  background-color: #012611;
  color: white;
}

h1 {
  font-family: &quot;Monarcha&quot;;
  font-weight: bolder;
}

h3 {
  font-family: &quot;Soleil&quot;;
}
label {
  font-family: &quot;Monarcha&quot;;
}

.right-side {
  background-color: white;
}

div {
  outline: black solid 5px;
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;title&gt;Title&lt;/title&gt;
    &lt;!-- Required meta tags --&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta
      name=&quot;viewport&quot;
      content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;
    /&gt;

    &lt;!-- Bootstrap CSS v5.2.1 --&gt;
    &lt;link
      href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot;
      rel=&quot;stylesheet&quot;
      integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot;
      crossorigin=&quot;anonymous&quot;
    /&gt;

    &lt;link rel=&quot;stylesheet&quot; href=&quot;./index.css&quot; /&gt;
  &lt;/head&gt;

  &lt;body&gt;
    &lt;div class=&quot;container-fluid&quot;&gt;
      &lt;!-- Stack the columns on mobile by making one full-width and the other half-width --&gt;
      &lt;div class=&quot;row justify-content-center align-items-center&quot;&gt;
        &lt;!-- Left Column --&gt;
        &lt;div
          class=&quot;col-lg-6 col-sm-6 vh-100 center-block text-center d-none d-sm-block left-side&quot;
        &gt;
          &lt;img src=&quot;../pictures/logo.png&quot; alt=&quot;&quot; width=&quot;72&quot; height=&quot;72&quot; /&gt;
          &lt;h1&gt;Text1&lt;/h1&gt;
          &lt;h3&gt;Text2&lt;/h3&gt;
        &lt;/div&gt;
        &lt;!-- Right Column --&gt;
        &lt;div class=&quot;col-lg-6 col-sm-6 center-block right-side&quot;&gt;
          &lt;div class=&quot;container&quot;&gt;
            &lt;div class=&quot;row align-items-center&quot;&gt;
              &lt;div class=&quot;col-lg-6&quot;&gt;
                &lt;form class=&quot;form-signin&quot;&gt;
                  &lt;div class=&quot;text-center d-block d-sm-none&quot;&gt;
                    &lt;img
                      src=&quot;../pictures/logo.png&quot;
                      alt=&quot;&quot;
                      width=&quot;72&quot;
                      height=&quot;72&quot;
                    /&gt;
                    &lt;h1&gt;text1&lt;/h1&gt;
                    &lt;h3&gt;text2&lt;/h3&gt;
                  &lt;/div&gt;

                  &lt;h3 class=&quot;login-heading mb-4&quot;&gt;Login&lt;/h3&gt;

                  &lt;!-- Sign In Form --&gt;
                  &lt;div class=&quot;mb-3&quot;&gt;
                    &lt;label&gt;Email address&lt;/label&gt;
                    &lt;input
                      type=&quot;email&quot;
                      class=&quot;form-control&quot;
                      id=&quot;floatingInput&quot;
                      placeholder=&quot;name@example.com&quot;
                    /&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;mb-3&quot;&gt;
                    &lt;label&gt;Password&lt;/label&gt;
                    &lt;input
                      type=&quot;password&quot;
                      class=&quot;form-control&quot;
                      id=&quot;floatingPassword&quot;
                      placeholder=&quot;Password&quot;
                    /&gt;
                  &lt;/div&gt;

                  &lt;div class=&quot;form-check d-flex justify-content-between mb-3&quot;&gt;
                    &lt;div&gt;
                      &lt;input
                        class=&quot;form-check-input&quot;
                        type=&quot;checkbox&quot;
                        value=&quot;&quot;
                        id=&quot;rememberPasswordCheck&quot;
                      /&gt;
                      &lt;label
                        class=&quot;form-check-label&quot;
                        for=&quot;rememberPasswordCheck&quot;
                      &gt;
                        Remember password
                      &lt;/label&gt;
                    &lt;/div&gt;

                    &lt;a class=&quot;small&quot; href=&quot;#&quot;&gt;Forgot password?&lt;/a&gt;
                  &lt;/div&gt;

                  &lt;div class=&quot;d-grid&quot;&gt;
                    &lt;button
                      class=&quot;btn btn-block btn-outline-dark text-uppercase mb-2&quot;
                      type=&quot;submit&quot;
                    &gt;
                      Sign in
                    &lt;/button&gt;
                  &lt;/div&gt;
                &lt;/form&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;

    &lt;!-- Bootstrap JavaScript Libraries --&gt;
    &lt;script
      src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js&quot;
      integrity=&quot;sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3&quot;
      crossorigin=&quot;anonymous&quot;
    &gt;&lt;/script&gt;

    &lt;script
      src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js&quot;
      integrity=&quot;sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz&quot;
      crossorigin=&quot;anonymous&quot;
    &gt;&lt;/script&gt;
  &lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

答案1

得分: 1

已添加 flex-column align-items-center justify-content-sm-center。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->
.left-side {
  background-color: #012611;
  color: white;
}

h1 {
  font-family: "Monarcha";
  font-weight: bolder;
}

h3 {
  font-family: "Soleil";
}
label {
  font-family: "Monarcha";
}

.right-side {
  background-color: white;
}

div {
  outline: black solid 5px;
}

<!-- language: lang-html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Title</title>
    <!-- Required meta tags -->
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no"
    />

    <!-- Bootstrap CSS v5.2.1 -->
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT"
      crossorigin="anonymous"
    />

    <link rel="stylesheet" href="./index.css" />
  </head>

  <body>
    <div class="container-fluid">
      <!-- Stack the columns on mobile by making one full-width and the other half-width -->
      <div class="row justify-content-center align-items-center">
        <!-- Left Column -->
        <div
          class="col-lg-6 col-sm-6 vh-100 center-block flex-column align-items-center justify-content-sm-center text-center d-none d-sm-flex left-side"
        >
          <img src="../pictures/logo.png" alt="" width="72" height="72" />
          <h1>Text1</h1>
          <h3>Text2</h3>
        </div>
        <!-- Right Column -->
        <div class="col-lg-6 col-sm-6 center-block right-side">
          <div class="container">
            <div class="row align-items-center">
              <div class="col-lg-6">
                <form class="form-signin">
                  <div class="text-center d-block d-sm-none">
                    <img
                      src="../pictures/logo.png"
                      alt=""
                      width="72"
                      height="72"
                    />
                    <h1>text1</h1>
                    <h3>text2</h3>
                  </div>

                  <h3 class="login-heading mb-4">Login</h3>

                  <!-- Sign In Form -->
                  <div class="mb-3">
                    <label>Email address</label>
                    <input
                      type="email"
                      class="form-control"
                      id="floatingInput"
                      placeholder="name@example.com"
                    />
                  </div>
                  <div class="mb-3">
                    <label>Password</label>
                    <input
                      type="password"
                      class="form-control"
                      id="floatingPassword"
                      placeholder="Password"
                    />
                  </div>

                  <div class="form-check d-flex justify-content-between mb-3">
                    <div>
                      <input
                        class="form-check-input"
                        type="checkbox"
                        value=""
                        id="rememberPasswordCheck"
                      />
                      <label
                        class="form-check-label"
                        for="rememberPasswordCheck"
                      >
                        Remember password
                      </label>
                    </div>

                    <a class="small" href="#">Forgot password?</a>
                  </div>

                  <div class="d-grid">
                    <button
                      class="btn btn-block btn-outline-dark text-uppercase mb-2"
                      type="submit"
                    >
                      Sign in
                    </button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap JavaScript Libraries -->
    <script
      src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"
      integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3"
      crossorigin="anonymous"
    ></script>

    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js"
      integrity="sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz"
      crossorigin="anonymous"
    ></script>
  </body>
</html>

<!-- end snippet -->
英文:

Added flex-column align-items-center justify-content-sm-center

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.left-side {
  background-color: #012611;
  color: white;
}

h1 {
  font-family: &quot;Monarcha&quot;;
  font-weight: bolder;
}

h3 {
  font-family: &quot;Soleil&quot;;
}
label {
  font-family: &quot;Monarcha&quot;;
}

.right-side {
  background-color: white;
}

div {
  outline: black solid 5px;
}

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;title&gt;Title&lt;/title&gt;
&lt;!-- Required meta tags --&gt;
&lt;meta charset=&quot;utf-8&quot; /&gt;
&lt;meta
name=&quot;viewport&quot;
content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;
/&gt;
&lt;!-- Bootstrap CSS v5.2.1 --&gt;
&lt;link
href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/css/bootstrap.min.css&quot;
rel=&quot;stylesheet&quot;
integrity=&quot;sha384-iYQeCzEYFbKjA/T2uDLTpkwGzCiq6soy8tYaI1GyVh/UjpbCx/TYkiZhlZB6+fzT&quot;
crossorigin=&quot;anonymous&quot;
/&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;./index.css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;container-fluid&quot;&gt;
&lt;!-- Stack the columns on mobile by making one full-width and the other half-width --&gt;
&lt;div class=&quot;row justify-content-center align-items-center&quot;&gt;
&lt;!-- Left Column --&gt;
&lt;div
class=&quot;col-lg-6 col-sm-6 vh-100 center-block flex-column align-items-center justify-content-sm-center text-center d-none d-sm-flex left-side&quot;
&gt;
&lt;img src=&quot;../pictures/logo.png&quot; alt=&quot;&quot; width=&quot;72&quot; height=&quot;72&quot; /&gt;
&lt;h1&gt;Text1&lt;/h1&gt;
&lt;h3&gt;Text2&lt;/h3&gt;
&lt;/div&gt;
&lt;!-- Right Column --&gt;
&lt;div class=&quot;col-lg-6 col-sm-6 center-block right-side&quot;&gt;
&lt;div class=&quot;container&quot;&gt;
&lt;div class=&quot;row align-items-center&quot;&gt;
&lt;div class=&quot;col-lg-6&quot;&gt;
&lt;form class=&quot;form-signin&quot;&gt;
&lt;div class=&quot;text-center d-block d-sm-none&quot;&gt;
&lt;img
src=&quot;../pictures/logo.png&quot;
alt=&quot;&quot;
width=&quot;72&quot;
height=&quot;72&quot;
/&gt;
&lt;h1&gt;text1&lt;/h1&gt;
&lt;h3&gt;text2&lt;/h3&gt;
&lt;/div&gt;
&lt;h3 class=&quot;login-heading mb-4&quot;&gt;Login&lt;/h3&gt;
&lt;!-- Sign In Form --&gt;
&lt;div class=&quot;mb-3&quot;&gt;
&lt;label&gt;Email address&lt;/label&gt;
&lt;input
type=&quot;email&quot;
class=&quot;form-control&quot;
id=&quot;floatingInput&quot;
placeholder=&quot;name@example.com&quot;
/&gt;
&lt;/div&gt;
&lt;div class=&quot;mb-3&quot;&gt;
&lt;label&gt;Password&lt;/label&gt;
&lt;input
type=&quot;password&quot;
class=&quot;form-control&quot;
id=&quot;floatingPassword&quot;
placeholder=&quot;Password&quot;
/&gt;
&lt;/div&gt;
&lt;div class=&quot;form-check d-flex justify-content-between mb-3&quot;&gt;
&lt;div&gt;
&lt;input
class=&quot;form-check-input&quot;
type=&quot;checkbox&quot;
value=&quot;&quot;
id=&quot;rememberPasswordCheck&quot;
/&gt;
&lt;label
class=&quot;form-check-label&quot;
for=&quot;rememberPasswordCheck&quot;
&gt;
Remember password
&lt;/label&gt;
&lt;/div&gt;
&lt;a class=&quot;small&quot; href=&quot;#&quot;&gt;Forgot password?&lt;/a&gt;
&lt;/div&gt;
&lt;div class=&quot;d-grid&quot;&gt;
&lt;button
class=&quot;btn btn-block btn-outline-dark text-uppercase mb-2&quot;
type=&quot;submit&quot;
&gt;
Sign in
&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- Bootstrap JavaScript Libraries --&gt;
&lt;script
src=&quot;https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js&quot;
integrity=&quot;sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3&quot;
crossorigin=&quot;anonymous&quot;
&gt;&lt;/script&gt;
&lt;script
src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.1/dist/js/bootstrap.min.js&quot;
integrity=&quot;sha384-7VPbUDkoPSGFnVtYi0QogXtr74QeVeeIs99Qfg5YCF+TidwNdjvaKZX19NZ/e6oz&quot;
crossorigin=&quot;anonymous&quot;
&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月15日 08:23:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478347.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定