admin管理员组文章数量:1435258
I have this react component:
const IslandDash = () => {
return (
<Wrapper>
<div className="dashboard">
<NavLink to={"/Blog"}>
<div className="dash-item-container">
<TbHome className="dash-items" />
<p className="label-container">Home</p>
</div>
</NavLink>
</div>
</Wrapper>
);
};
How do I center this p element beneath the TbHome Icon?
Here is the code for the Wrapper css:
import styled from "styled-components";
const Wrapper = styled.section`
.dashboard {
width: max-content;
height: 46px;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--foreground);
color: var(--primary-dark);
border-radius: var(--border-radius);
margin: auto;
margin-top: 30px;
padding: 0px 30px;
column-gap: 20px;
}
.translate {
padding: 0px 20px;
position: absolute;
top: 0;
right: 100px;
}
.dash-items {
width: 30px;
height: 30px;
color: var(--primary-dark);
stroke-width: 1.5;
transition: transform 185ms ease-in-out;
}
.dash-items:hover {
color: var(--primary-light);
cursor: pointer;
transform: translateY(-5px) scale(1.1);
}
.label-container {
border-color: red;
border-style: solid;
color: var(--primary-light);
}
.dash-item-container {
border-color: green;
border-style: solid;
display: grid;
}
`;
export default Wrapper;
I tried position Absolute, which is not viable here as it wouldn't be responsive. My next thought was to use grid, but that did not work either. You can see the results below:
intended design
my result
I added border color so you can visualize the divs.
I have this react component:
const IslandDash = () => {
return (
<Wrapper>
<div className="dashboard">
<NavLink to={"/Blog"}>
<div className="dash-item-container">
<TbHome className="dash-items" />
<p className="label-container">Home</p>
</div>
</NavLink>
</div>
</Wrapper>
);
};
How do I center this p element beneath the TbHome Icon?
Here is the code for the Wrapper css:
import styled from "styled-components";
const Wrapper = styled.section`
.dashboard {
width: max-content;
height: 46px;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--foreground);
color: var(--primary-dark);
border-radius: var(--border-radius);
margin: auto;
margin-top: 30px;
padding: 0px 30px;
column-gap: 20px;
}
.translate {
padding: 0px 20px;
position: absolute;
top: 0;
right: 100px;
}
.dash-items {
width: 30px;
height: 30px;
color: var(--primary-dark);
stroke-width: 1.5;
transition: transform 185ms ease-in-out;
}
.dash-items:hover {
color: var(--primary-light);
cursor: pointer;
transform: translateY(-5px) scale(1.1);
}
.label-container {
border-color: red;
border-style: solid;
color: var(--primary-light);
}
.dash-item-container {
border-color: green;
border-style: solid;
display: grid;
}
`;
export default Wrapper;
I tried position Absolute, which is not viable here as it wouldn't be responsive. My next thought was to use grid, but that did not work either. You can see the results below:
intended design
my result
I added border color so you can visualize the divs.
Share Improve this question edited Nov 17, 2024 at 3:37 Zheng Jiawen asked Nov 17, 2024 at 3:36 Zheng JiawenZheng Jiawen 133 bronze badges1 Answer
Reset to default 0Just add text-align: center;
to the .dashboard
class.
Here it is in action:
.dashboard, div[classname="dashboard"] {
width: max-content;
height: 46px;
display: flex;
align-items: center;
justify-content: center;
background-color: var(--foreground);
color: var(--primary-dark);
border-radius: var(--border-radius);
margin: auto;
margin-top: 30px;
padding: 0px 30px;
column-gap: 20px;
text-align: center; /*this is the essence*/
}
.translate {
padding: 0px 20px;
position: absolute;
top: 0;
right: 100px;
}
.dash-items, div[classname="dash-items"] {
width: 30px;
height: 30px;
color: var(--primary-dark);
stroke-width: 1.5;
transition: transform 185ms ease-in-out;
}
.dash-items:hover, div[classname="dash-items"]:hover {
color: var(--primary-light);
cursor: pointer;
transform: translateY(-5px) scale(1.1);
}
.label-container, p[classname="label-container"] {
border-color: red;
border-style: solid;
color: var(--primary-light);
}
.dash-item-container, div[classname="dash-item-container"] {
border-color: green;
border-style: solid;
display: grid;
}
const IslandDash = () => {
return (
<Wrapper>
<div className="dashboard">
<NavLink to={"/Blog"}>
<div className="dash-item-container">
<TbHome className="dash-items" /><img src="https://i.sstatic/pY8PYtfg.png"></TbHome>
<p className="label-container">Home</p>
</div>
</NavLink>
</div>
</Wrapper>
);
};
Image used in the code:
本文标签:
版权声明:本文标题:html - How to center a div containing text label right below another div containing icon, in a dashboard - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745639531a2667767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论