首页 > 解决方案 > HTML:H1 类不居中

问题描述

我是 HTML 新手,我正在尝试使用 css 类将 H1 居中,但它不起作用。一世

我的 HTML 如下:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="/style.css"> 

</head>  
<body>
  <div class='title'>
    <h1>Technologies</h1>
  </div>

</body>
</html>

我的CSS如下:

multi-input {
  display: inline-block;
  margin: 0 20px 20px 0;
}  
button {
  background-color: #eee;
  border: 1px solid #ddd;  
  font-size: 16px;
  height: 30px;
  margin: 0 10px 20px 0;
}   
body > div {
  align-items: center;
  display: flex;
  justify-content: center;
}   
label {
  display: block;
  margin: 0 20px 20px 0;
}    
div.title {
  text-align: center;
}

我从本教程中启发了自己:https ://www.w3schools.com/cssref/pr_text_text-align.ASP 我还尝试h1 {text-align: center;}在我的 css 中添加它,以便所有 H1 都居中,但它仍然无法正常工作。任何人都可以帮忙吗?谢谢!

标签: htmlcss

解决方案


您必须从<link rel="stylesheet" href="/style.css">

像这样 :<link rel="stylesheet" href="style.css">


推荐阅读