无法为小型设备的弹性盒中的三个元素设计
我是第一次使用React构建投资组合,并且在使用FLEX的三个元素中,我被固定的三个元素在整个设备中对齐,在全屏上,一切都可以。
在小设备中,我现在要检索的是:
我想获得的内容:
图像应位于社交图标的同一行中,我还希望文字“您好我是Amedeo ...和按钮”在社交图标的同一位置垂直启动。
使用的代码是:
HTML:
function Intro() {
return (
<IntroStyled>
<div className="item-1">
<SocialMedia />
</div>
<div className="item-2">
<h1>Hi, I'm Amedeo</h1>
<p>Tech Entusiast</p>
<Button />
</div>
<div className="item-3">
<img src={Amedeo} alt="Amedeo_Image" />
</div>
</IntroStyled>
);
}
CSS:
export const IntroStyled = styled.div`
height: 100vh;
width: 100vw;
display: flex;
//background-color: yellow;
align-items: center;
justify-content: center;
h1 {
font-size: 40px;
margin: 0;
}
.item-1 {
order: 1;
}
.item-2 {
order: 2;
}
.item-3 {
order: 3;
}
@media screen and (max-width: 768px) {
flex-direction: column;
.item-1 {
order: 1;
}
.item-2 {
order: 3;
}
.item-3 {
order: 2;
}
}
`;
社交媒体图标: HTML:
function SocialMedia() {
return (
//dimensione icone default =24
<SocialMediaStyled>
<a href="#" className="icon" target="_blank">
<UilLinkedin size="24" />
</a>
<a href="#" className="icon" target="_blank">
<UilInstagram size="24" />
</a>
<a href="#" className="icon" target="_blank">
<UilGitHub size="24" />
</a>
</SocialMediaStyled>
);
}
CSS:
export const SocialMediaStyled = styled.div`
display: flex;
flex-direction: column;
margin-right: 100px;
@media (max-width: 798px) {
margin-right: 20px;
margin-left: 20px;
}
.icon {
color: ${Colors.firstColor};
margin-bottom: 10px;
&:hover {
color: ${Colors.firstColor_Alt};
}
}
`;
您能帮我吗? 多谢 Amedeo
编辑: 在@antokhio评论之后,我更改了代码,现在我能够在我有一个小设备时检索预期的结果,如下图中所示:
当我处于全尺寸时。订单属性无法正常工作
新代码:
html
function Intro() {
return (
<IntroStyled>
<div className="intro_container">
<div className="social_image_container">
<div className="item-1">
<SocialMedia />
</div>
<div className="item-3">
<img src={Amedeo} alt="Amedeo_Image" />
</div>
</div>
<div className="item-2">
<h1>Hi, I'm Amedeo</h1>
<p>Tech Entusiast</p>
<Button />
</div>
</div>
</IntroStyled>
);
}
css:
export const IntroStyled = styled.div`
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
h1 {
font-size: 40px;
margin: 0;
}
.intro_container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.social_image_container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.item-1 {
order: 1;
}
.item-2 {
order: 2;
}
.item-3 {
order: 3;
}
@media screen and (max-width: 768px) {
.intro_container {
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
.item-1 {
order: 1;
}
.item-2 {
order: 3;
margin-left: 20px;
}
.item-3 {
order: 2;
}
}
`;
I am building my portfolio using react for the first time and i am stucked with formatting three element aligned using flex in case of small devices, in full screen everything is ok.
What i want to obtain is:
In full size(this case is ok):
In small device what i am retrieving now is this:
What i want to obtain:
The image should be in the same row of the social icon, and i would like also that the text"Hello I'm Amedeo ... and the button" start vertically at the same position of the social icon.
The code used is this one:
HTML:
function Intro() {
return (
<IntroStyled>
<div className="item-1">
<SocialMedia />
</div>
<div className="item-2">
<h1>Hi, I'm Amedeo</h1>
<p>Tech Entusiast</p>
<Button />
</div>
<div className="item-3">
<img src={Amedeo} alt="Amedeo_Image" />
</div>
</IntroStyled>
);
}
CSS:
export const IntroStyled = styled.div`
height: 100vh;
width: 100vw;
display: flex;
//background-color: yellow;
align-items: center;
justify-content: center;
h1 {
font-size: 40px;
margin: 0;
}
.item-1 {
order: 1;
}
.item-2 {
order: 2;
}
.item-3 {
order: 3;
}
@media screen and (max-width: 768px) {
flex-direction: column;
.item-1 {
order: 1;
}
.item-2 {
order: 3;
}
.item-3 {
order: 2;
}
}
`;
Social Media icons:
HTML:
function SocialMedia() {
return (
//dimensione icone default =24
<SocialMediaStyled>
<a href="#" className="icon" target="_blank">
<UilLinkedin size="24" />
</a>
<a href="#" className="icon" target="_blank">
<UilInstagram size="24" />
</a>
<a href="#" className="icon" target="_blank">
<UilGitHub size="24" />
</a>
</SocialMediaStyled>
);
}
CSS:
export const SocialMediaStyled = styled.div`
display: flex;
flex-direction: column;
margin-right: 100px;
@media (max-width: 798px) {
margin-right: 20px;
margin-left: 20px;
}
.icon {
color: ${Colors.firstColor};
margin-bottom: 10px;
&:hover {
color: ${Colors.firstColor_Alt};
}
}
`;
Could you help me please?
Thanks a lot
Amedeo
Edit:
After @antokhio comment I changed the code, now i am able to retrieve the expected result when i have a small device, as you can see in the below image:
But now image is in the wrong position when i am in full size.Order properties not working
New code:
HTML
function Intro() {
return (
<IntroStyled>
<div className="intro_container">
<div className="social_image_container">
<div className="item-1">
<SocialMedia />
</div>
<div className="item-3">
<img src={Amedeo} alt="Amedeo_Image" />
</div>
</div>
<div className="item-2">
<h1>Hi, I'm Amedeo</h1>
<p>Tech Entusiast</p>
<Button />
</div>
</div>
</IntroStyled>
);
}
CSS:
export const IntroStyled = styled.div`
height: 100vh;
width: 100vw;
display: flex;
align-items: center;
justify-content: center;
h1 {
font-size: 40px;
margin: 0;
}
.intro_container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.social_image_container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.item-1 {
order: 1;
}
.item-2 {
order: 2;
}
.item-3 {
order: 3;
}
@media screen and (max-width: 768px) {
.intro_container {
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
.item-1 {
order: 1;
}
.item-2 {
order: 3;
margin-left: 20px;
}
.item-3 {
order: 2;
}
}
`;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是实现这一目标的方法:
将Divs
Item-2
和Item-3
放入另一个样式的组件中。我命名了这个新的样式组件
progiledScStyled
。这个新内部样式组件将处理内部挠性定位
这两个divs。
现在将此
放置在与
item-1
相同级别的第二个DIV中介绍了
组件。我给这个div的类名称为profile-desc-div
。请参阅下面的代码(我使用Ellipsis
...
指示我没有更改的代码部分,并且简洁地说明):以下步骤适用于上面的样式组件定义:
item-2
和item-3
在内内>内外
定义中删除flex订单属性。<强>为DIV
profile-desc-div
添加弹性顺序,并分配2。的值。
从
内部删除媒体查询
完全定义。profiledEscStyled
定义 display>显示:flex 和flex方向:列
垂直堆叠其中的元素。最后设置添加媒体查询目标
item-item-2
和item-3
,然后翻转其flex订单属性,如下所示。so:so:so:so:
Here's how to achieve this:
Put the divs
item-2
anditem-3
inside another styled component.I named this new styled component
ProfileDescStyled
. This newinner styled component will handle the internal flex positioning of
those two divs.
Now put this
ProfileDescStyled
component inside a second div on the same level asitem-1
. I gave this div a class name ofprofile-desc-div
.See the code below (I use ellipsis
...
to indicate parts of the code I didn't change and for brevity):And the following steps are for the styled-component definitions from above:
Remove the flex order properties for
item-2
anditem-3
in theIntroStyled
definition.Add in a flex order for the div
profile-desc-div
and assign the value of 2.Remove the media query from the
IntroStyled
definition entirely.In the
ProfileDescStyled
definition setdisplay: flex
andflex-direction: column
to stack the elements within it vertically.Lastly set add in a media query targeting just
item-2
anditem-3
and flipping their flex order properties as shown below.Like so: