在移动屏幕上打开时,如何将图像设置在右侧并移至底部?

huangapple go评论77阅读模式
英文:

How to set an image on the right that goes to bottom when opened on mobile screen?

问题

我在About Us页面上创建了一个页面,我想在页面的右侧显示一张图片,当在手机上查看时,图片应移至屏幕底部。

以下是我正在制作的React组件的JS和CSS文件。

aboutUS.js

import './AboutUs.css';
import TeamCard from '../../components/TeamCard';

export default function AboutUs() {
  const members = [
    { name: 'Bhavesh', link: 'https://developer.mozilla.org/en-US/', imageLink: 'https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg' },
    { name: 'Bhavesh', link: 'https://developer.mozilla.org/en-US/', imageLink: 'https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg' }    
  ]

  return (
    <div className='about-us-div'>
      <div className='content'>
        <h1 style={{ marginBottom: '30px' }}>About Us</h1>
        <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?</p>
      </div>
      <div className="cc-cards">
      {members.map((member, index) => <TeamCard key={index} name={member.name} link={member.link} imageLink={member.imageLink} />)}
      </div>
      <img className='logo-image' src="https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg" alt="" />
    </div>
  )
}

AboutUs.css

.about-us-div{
    color: white;
}
.content {
  max-width: 600px;
  margin: 30px 80px 60px;
}
.cc-cards{
    display: flex;
    flex-wrap: wrap;
    margin-left: 60px;
    margin-top: -20px;
}

@media (max-width: 710px){
    .cc-cards{
        justify-content: center;
        padding-bottom: 30px;
    }
}

图片应该在较大屏幕上放置在右侧的空白处,而在手机屏幕上放在底部。
这是未定位图片的示例

我尝试在父元素上使用flex,但仍然没有得到我想要的效果。

英文:

I have made an About Us page on which I want an image to be shown on the right of the page, which when viewed on phone, goes down to the bottom of screen.

Here is the JS and CSS file of the React Component that I am making.

aboutUS.js

import &#39;./AboutUs.css&#39;
import TeamCard from &#39;../../components/TeamCard&#39;
export default function AboutUs() {
const members = [
{ name: &#39;Bhavesh&#39;, link: &#39;https://developer.mozilla.org/en-US/&#39;, imageLink: &#39;https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg&#39; },
{ name: &#39;Bhavesh&#39;, link: &#39;https://developer.mozilla.org/en-US/&#39;, imageLink: &#39;https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg&#39; }    
]
return (
&lt;div className=&#39;about-us-div&#39;&gt;
&lt;div className=&#39;content&#39;&gt;
&lt;h1 style={{ marginBottom: &#39;30px&#39; }}&gt;About Us&lt;/h1&gt;
&lt;p&gt;Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus dicta, ea similique voluptatum minus voluptates architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?&lt;/p&gt;
&lt;/div&gt;
&lt;div className=&quot;cc-cards&quot;&gt;
{members.map((member, index) =&gt; &lt;TeamCard key={index} name={member.name} link={member.link} imageLink={member.imageLink} /&gt;)}
&lt;/div&gt;
&lt;img className=&#39;logo-image&#39; src=&quot;https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg&quot; alt=&quot;&quot; /&gt;
&lt;/div&gt;
)
}

AboutUS.css

.about-us-div{
color: white;
}
.content {
max-width: 600px;
margin: 30px 80px 60px;
}
.cc-cards{
display: flex;
flex-wrap: wrap;
margin-left: 60px;
margin-top: -20px;
}
@media(max-width: 710px){
.cc-cards{
justify-content: center;
padding-bottom: 30px;
}
}

The image should be placed on the right blank space when viewed on larger screen whereas at the bottom in case of phone screen.
Here is the sample with image not positioned

I tried using flex on the parent div but still I am not getting what I wanted.

答案1

得分: 1

很有帮助如果你能分享你的代码片段。仅凭查看代码很难确定项目的完整布局。不过,我通过参考你的截图在沙盒上快速创建了一个布局。欲获取更多信息,请访问链接。谢谢。

我也分享了代码片段。请跟进这段代码。

关于我们组件

import "./aboutUs.css";

export default function AboutUs() {
  const members = [
    {
      name: "Bhavesh",
      link: "https://developer.mozilla.org/en-US/",
      imageLink:
        "https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg"
    },
    {
      name: "Bhavesh",
      link: "https://developer.mozilla.org/en-US/",
      imageLink:
        "https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg"
    }
  ];

  const cardWrapper = {
    width: "160px",
    height: "260px",
    padding: "1rem",
    marginRight: "1.5rem",
    borderRadius: "15px",
    backgroundColor: "#3b3b3b"
  };

  return (
    <div className="about-us-div">
      <div className="content">
        <div>
          <h1 style={{ marginBottom: "30px" }}>About Us</h1>
          <div>
            <p style={{ marginBottom: "1.3rem" }}>
              // ...(部分文字内容被截断)
            </p>
          </div>
        </div>

        <div className="cc-cards">
          {members.map((member, index) => (
            <div key={index} style={cardWrapper}>
              <div className="logo-wrapper">
                <div className="logo-image">
                  <img src={member.imageLink} alt="member-avatar" />
                </div>

                <div className="linkedin-icon-wrapper">
                  <a href={member.link} target="_blank">
                    <i class="bi bi-linkedin icon-size"></i>
                  </a>
                </div>

                <div className="user-name">{member.name}</div>
                <div></div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

关于我们的样式

@import url("https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;0,900;1,100&display=swap");
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css");

.about-us-div {
  // ...(CSS样式定义被截断)
}

.content {
  // ...(CSS样式定义被截断)
}

.cc-cards {
  // ...(CSS样式定义被截断)
}

// ...其他CSS样式定义被截断

注意:由于我没有"TeamCard"组件,我根据你的截图参考构建了一个区块。

英文:

It would be very helpful if you could share your code snippet. I find it challenging to determine the complete layout of your project by examining your code alone. However, I was able to quickly create a layout on the sandbox by referring to your screenshot. For additional information, please visit the link. Thank you.

I have also shared the code snippet. Kindly follow through with the code.

About Us Component

import &quot;./aboutUs.css&quot;;
// import TeamCard from &quot;../../components/TeamCard&quot;;
export default function AboutUs() {
const members = [
{
name: &quot;Bhavesh&quot;,
link: &quot;https://developer.mozilla.org/en-US/&quot;,
imageLink:
&quot;https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg&quot;
},
{
name: &quot;Bhavesh&quot;,
link: &quot;https://developer.mozilla.org/en-US/&quot;,
imageLink:
&quot;https://cdn.pixabay.com/photo/2021/08/26/01/56/mountains-6574828__340.jpg&quot;
}
];
const cardWrapper = {
width: &quot;160px&quot;,
height: &quot;260px&quot;,
padding: &quot;1rem&quot;,
marginRight: &quot;1.5rem&quot;,
borderRadius: &quot;15px&quot;,
backgroundColor: &quot;#3b3b3b&quot;
};
return (
&lt;div className=&quot;about-us-div&quot;&gt;
&lt;div className=&quot;content&quot;&gt;
&lt;div&gt;
&lt;h1 style={{ marginBottom: &quot;30px&quot; }}&gt;About Us&lt;/h1&gt;
&lt;div&gt;
&lt;p style={{ marginBottom: &quot;1.3rem&quot; }}&gt;
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quisquam
qui libero, nulla quo sequi doloribus dicta, ea similique
voluptatum minus voluptates architecto beatae quam eum nam fugiat.
Soluta, saepe ipsa?Lorem, ipsum dolor sit amet consectetur
adipisicing elit. Quisquam qui libero, nulla quo sequi doloribus
dicta, ea similique voluptatum minus voluptates architecto beatae
quam eum nam fugiat. Soluta, saepe ipsa?Lorem, ipsum dolor sit
amet consectetur adipisicing elit. Quisquam qui libero, nulla quo
sequi doloribus dicta, ea similique voluptatum minus voluptates
architecto beatae quam eum nam fugiat. Soluta, saepe ipsa?Lorem,
ipsum dolor sit amet consectetur adipisicing elit. Quisquam qui
libero, nulla quo sequi doloribus dicta, ea similique voluptatum
minus voluptates architecto beatae quam eum nam fugiat. Soluta,
saepe ipsa?
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div className=&quot;cc-cards&quot;&gt;
{members.map((member, index) =&gt; (
// &lt;TeamCard
//   key={index}
//   name={member.name}
//   link={member.link}
//   imageLink={member.imageLink}
// /&gt;
&lt;div key={index} style={cardWrapper}&gt;
&lt;div className=&quot;logo-wrapper&quot;&gt;
&lt;div className=&quot;logo-image&quot;&gt;
&lt;img src={member.imageLink} alt=&quot;member-avatar&quot; /&gt;
&lt;/div&gt;
&lt;div className=&quot;linkedin-icon-wrapper&quot;&gt;
&lt;a href={member.link} target=&quot;_blank&quot;&gt;
&lt;i class=&quot;bi bi-linkedin icon-size&quot;&gt;&lt;/i&gt;
&lt;/a&gt;
&lt;/div&gt;
&lt;div className=&quot;user-name&quot;&gt;{member.name}&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
))}
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
);
}

Style for About Us

@import url(&quot;https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;0,900;1,100&amp;display=swap&quot;);
@import url(&quot;https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css&quot;);
.about-us-div {
width: 900px;
margin: 0 auto;
font-family: &quot;Lato&quot;, sans-serif;
color: white;
padding: 1rem;
background-color: #2b2b2b;
}
.content {
display: flex;
align-items: center;
}
.cc-cards {
display: flex;
/* flex-wrap: wrap; */
margin-left: 60px;
margin-top: -20px;
}
.logo-wrapper {
width: 100%;
display: flex;
align-items: center;
flex-direction: column;
}
.logo-image {
width: 135px;
height: 135px;
}
.logo-image img {
width: 100%;
height: 100%;
border-radius: 100%;
}
.linkedin-icon-wrapper {
position: relative;
top: -25px;
}
.linkedin-icon-wrapper .icon-size {
color: #ffffff;
font-size: 2rem;
}
.user-name {
font-size: 1.68rem;
font-weight: 600;
}
@media (max-width: 710px) {
.cc-cards {
justify-content: center;
padding-bottom: 30px;
}
}
@media only screen and (max-width: 420px) {
.about-us-div {
width: auto;
}
.content {
flex-direction: column;
}
.cc-cards {
flex-direction: column;
}
.cc-cards div {
margin-top: 1rem;
}
}

Note: Since I do not possess the TeamCard component, I have built a block by taking reference from your screenshot.

huangapple
  • 本文由 发表于 2023年2月16日 15:53:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75469265.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定