简体   繁体   English

用CSS安排元素的困难

[英]Difficulties arranging elements with CSS

Im struggling with some arraning of html elements in my reactjs project. 我在我的reactjs项目中尝试了一些html元素的准备工作。 Im new to all the webdevelopment and also to css and i have absolutly no idea how to resolve it in a responsive way. 我是所有Web开发人员和CSS的新手,我绝对不知道如何以响应方式解决它。 Im trying to solve the following placement of elemtns within my app: Link to what i try to archieve Here i show you what i actually have in react-jsx: 我正在尝试解决elemtns在我的应用程序中的以下放置: 链接到我尝试存档的内容这里,我向您展示我在react-jsx中的实际用途:

<img className="img" src={this.props.img_1} alt="DummyPicture" />
      <span className="personName">{this.props.name_1}</span>
      <span className="personAge">({this.props.age_1})</span>
      <span className="personMatching">
        {this.props.matching_1}% gemeinsame Interessen
      </span>

<img className="img" src={this.props.img_2} alt="DummyPicture" />
    <span className="personName">
      {this.props.name_2} ({this.props.age_2})
     </span>
     <span className="personMatching">
       {this.props.matching_2}% gemeinsame Interessen
     </span>

And here my css: 这是我的CSS:

.personName {
  width: 30%;
   float: left;
  margin-bottom: 5%;
   }

.personAge {
  width: 60%;
  float: left;
  margin-bottom: 5%;
 }
.personMatching {
  float: left;
  width: 70%;
    margin-bottom: 5%;
 }

.img {
  width: 48pt;
  height: 48pt;
  float: left;

  margin-left: 5%;
 }  

I also tried it with thinks like flex-box or display:inline but I think I just have a lack of knowledge about it. 我也尝试过使用flex-box或display:inline之类的方法,但我认为我对此并不了解。 Hope someone of you can help me out here. 希望你们中有人可以在这里帮助我。

The best practice today is to use flexbox . 今天的最佳实践是使用flexbox

As you see in the example below, flex will align items for you. 如下面的示例所示,flex将为您对齐项目。

 .person { display: flex; align-items: center; } .info { display: flex; align-items: center; flex-wrap: wrap; margin-left: 10px; } .age { font-size: 12px; margin-left: 5px; } .matching, .name { margin: 5px 0; flex-basis: 100%; } .img { width: 48pt; height: 48pt; border-radius: 50%; } 
 <div class="person"> <img class="img" src="https://randomuser.me/api/portraits/women/81.jpg" alt="DummyPicture" /> <div class="info"> <p class="name">Caroline Scott <span class="age">(26)</span></p> <p class="matching">74% gemeinsame Interessen</p> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM