代码之家  ›  专栏  ›  技术社区  ›  Nuñito Calzada

以百里香为图像水平居中

  •  1
  • Nuñito Calzada  · 技术社区  · 2 年前

    我有这个css:

    /* Global CSS styles */
    body {
        background-color: #364f6b;
        margin: 0;
        padding: 0;
    }
    
    /* Styling the logo */
    .logo {
        width: 400px;
        height: auto;
        justify-content: center; /* Horizontally center the content */
    }
    

    以及此模板:

    <!DOCTYPE HTML>
    <html xmlns:th="http://www.thymeleaf.org" lang="en">
    <head>
        
        <!-- Menu -->
        <link id="themeLink" th:href="@{/css/mystic-planets.css}"  rel="stylesheet" />
        <meta name="format-detection" content="telephone=no">
    
    </head>
    <body>
    <header>
        <img th:src="@{/images/137364472_padded_logo.png}"  alt="mystic-planets" th:class="logo" />
        <!-- Other header content goes here -->
    </header>
    </body>
    </html>
    

    但是徽标出现在页面的左上角

    2 回复  |  直到 2 年前
        1
  •  1
  •   Daham Akl    2 年前
    justify-content
    justify-item
    

    这些属性是CSS flex布局的子部分。要使用这些属性,您需要首先调整布局。

      {
         display: flex;
         flex-direction: column;
      }
    

    不要忘记使用灵活方向的行或列。 最后,您可以使用对正内容和对正项属性。

    看看下面的例子,

    div {
      display: flex;
      justify-content: center;
      justify-items: center;
    }
    

    希望这对你有帮助。

        2
  •  -1
  •   ByMunajat    2 年前

    要使用Thymelaf和CSS水平居中图像,可以使用flexbox。这个 justify-content: center

    CSS格式:

    /* Styling the logo container */
    .logo-container {
        display: flex; 
        justify-content: center; 
        align-items: center;
        height: 100vh; 
    }