skip to Main Content

I have this 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 */
}

and this template:

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

but the logo appears on the top-left side of the page

2

Answers


  1. justify-content
    justify-item
    

    These properties are sub-parts of CSS flex layout. To use these properties you need to you flex layout first.

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

    Do not forget to use the flex-direction row or column.
    Finally, you can use justify-content and justify-item properties.

    Look at the following example,

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

    Hope this is helpful for you.

    Login or Signup to reply.
  2. To horizontally center the image using Thymeleaf and CSS, you can use flexbox. The justify-content: center

    CSS:

    /* Styling the logo container */
    .logo-container {
        display: flex; 
        justify-content: center; 
        align-items: center;
        height: 100vh; 
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search