英文:
Horizontally center an image with Thymeleaf
问题
我有这个CSS:
/* 全局CSS样式 */
body {
background-color: #364f6b;
margin: 0;
padding: 0;
}
/* 样式化标志 */
.logo {
width: 400px;
height: auto;
justify-content: center; /* 水平居中内容 */
}
和这个模板:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<!-- 菜单 -->
<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" />
<!-- 其他头部内容放在这里 -->
</header>
</body>
</html>
但是标志出现在页面的左上角。
英文:
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
答案1
得分: 1
justify-content
justify-item
这些属性是CSS弹性布局的子部分。要使用这些属性,首先需要使用弹性布局。
{
display: flex;
flex-direction: column;
}
不要忘记使用flex-direction属性,可以选择row(行)或column(列)。
最后,你可以使用justify-content和justify-item属性。
看下面的例子,
div {
display: flex;
justify-content: center;
justify-items: center;
}
希望对你有所帮助。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论