html - 如何在 HTML 和 CSS 中的标题中的两个元素之间平均间隔一个元素
问题描述
我有一个包含徽标和注销链接的标题。标题在我使用标签包含的外部页面中。然后我在标签下的 HTML 文件中有一个标题。我想自动将标题居中,以便它在 logo() 元素的末尾和 logout() 元素之间是均匀的空间。这样:
LOGO<等间距>TITLE<等间距>LOGOUT
这是我的代码现在的样子:
样式.css:
* {
background-color: black;
font-family: verdana;
font-size: 14px;
color: white;
}
.header{
position: absolute;
top: 20px;
right:10px;
}
h1{
text-align: center;
font-size: 45px;
align-content: auto;
margin-top:10px;
}
头文件.php
<a href="home.php"><img class = "logo" src="https://images.squarespace-cdn.com/content/v1/5d5a565bed5af400017a2c97/1614516482816-LL1JVIR67NFFN016FNID/THRIVE-LOGO-2_RGB_NEW_WHITE.png?format=1500w" width="300" height="50"alt="Company logo"></a>
<div class="header">
<a href="logout.php?logout">Logout</a>
<p></p>
</div>
set_goal.php
html>
<head>
<include src="header.php"></include>
<h1>Please set your goal and choose your programme type</h1>
<link rel="stylesheet" href="styles.css">
</head>
解决方案
除 3 或任何列的方式不止一种。您可以从此处查看示例。您也可以使用 display flex。
例子:
<div class="parent_element">
<div class="logo">child element 1</div>
<div class="titile">child element 2</div>
<div class="logout">child element 3</div>
</div>
<style>
.parent_element{
display: flex;
align-content: center;
}
</style>
您在 set_goal.php 文件中犯了另一个简单的错误。您已经添加了头文件和 h1 标签,这意味着您在 head 元素下添加了元素,这是无效的。
推荐阅读
- java - 鉴于我有同一个网卡的多个 ip,如何在 java 中通过特定的网卡 ip 发送请求
- python - 包含多个字符串的列表到 excel 文件
- c# - 如何使用 OLEDB 读取 xls 文件?
- c# - 如何在具有相同架构的两个 MSSQL 数据库之间进行查询并在实体框架中合并结果
- php - Eloquent 错误地将多个模型保存到数据库
- c# - 如何使用asp.net c#将分页添加到父gridview?
- java - 如何使用 spring data jpa 返回该日期的日期和记录数?
- asp.net-web-api - 在方法 POST 中接收数据和文件
- python - 使用 pandas 从 Excel 文件中读取最后一列
- spring-boot - 如何在rest api中将数据列表导出到csv文件