在React.js中使网页上的图标居中对齐,可以通过以下几种方式实现:
import React from 'react';
import './App.css';
function App() {
return (
<div className="container">
<div className="icon-container">
<i className="icon"></i>
</div>
</div>
);
}
export default App;
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.icon-container {
display: flex;
justify-content: center;
align-items: center;
width: 100px;
height: 100px;
background-color: #ccc;
}
.icon {
font-size: 24px;
color: #fff;
}
import React from 'react';
import './App.css';
function App() {
return (
<div className="container">
<div className="icon-container">
<i className="icon"></i>
</div>
</div>
);
}
export default App;
.container {
position: relative;
height: 100vh;
}
.icon-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100px;
height: 100px;
background-color: #ccc;
}
.icon {
font-size: 24px;
color: #fff;
}
import React from 'react';
import './App.css';
function App() {
return (
<div className="container">
<div className="icon-container">
<i className="icon"></i>
</div>
</div>
);
}
export default App;
.container {
display: grid;
place-items: center;
height: 100vh;
}
.icon-container {
width: 100px;
height: 100px;
background-color: #ccc;
}
.icon {
font-size: 24px;
color: #fff;
}
以上是三种常用的方法来实现在React.js中使网页上的图标居中对齐的方式。根据具体情况选择合适的方法来实现对齐效果。
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云