reactjs - 文本不在 React JS(和 Tailwind CSS)中居中
问题描述
最近,我开始使用带有 React JS 的 Tailwind CSS。
(我使用Adrian Twarog 的本教程在我的 React 项目中安装 Tailwind。)
我试图h1
在我的页面上居中,除了......
……事情就是这样。但对我来说,这没有意义!我已经将我的文本和所有内容居中。
App.js
import React from "react";
function App() {
return (
<div className="container place-items-center">
<h1 className="text-7xl text-gray-800 uppercase tracking-wide text-center">
Text
</h1>
</div>
);
}
export default App;
tailwind.config.js
:
module.exports = {
purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
darkMode: false,
theme: {
extend: {
colors: {
orange: "#f97b4f",
},
},
},
variants: {
extend: {},
},
plugins: [],
};
index.css
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;900&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
font-family: "Poppins", sans-serif;
font-weight: 100;
}
h1 {
font-weight: 900;
}
我的问题是,如何在 Tailwind CSS 中将文本居中?谢谢!
解决方案
只需删除容器类,因为它会根据屏幕宽度提供多个宽度。
<div className="place-items-center">
<h1 className="text-7xl text-gray-800 uppercase tracking-wide text-center">
Text
</h1>
</div>
推荐阅读
- python - 如何使用 If Else (Python) 过滤不同的参数
- function - 有没有办法排除在 ElasticSearch 中之前的 function_scores 中匹配的文档?
- javascript - 如何在 JS 的 url 中将多个 Id 作为参数传递?
- python - 生成的熊猫数据框附加到excel表
- sql - 删除所有但选定的单词正则表达式
- android - android-如果清单中未提供访问权限,则在应用程序分析器中显示权限
- python - 使用Python将灰度图像转换为二值图像的问题
- python - Python 更改 JSON 数组中的特定项目
- java - 如何在 VSC 中解决“找不到命令”tmcTreeView.refreshCourses”?
- c - 在没有库函数的情况下反转字符串