简体   繁体   English

如何更好地执行DIV和处理css

[英]How to perform DIV better and deal with the css

First, it is a loop in React and assumed as a mobile version.首先,它是 React 中的一个循环,并假设为移动版本。

Within each loop of DIV , it will have a photo(150*150px) on the left-hand side.DIV的每个循环中,它的左侧会有一张照片(150*150px)。 On the photo's right-hand side, it will have 3 div and each of the div will have a p (name, car and salary).在照片的右侧,它将有 3 个div ,每个div都有一个p (姓名、汽车和薪水)。 At the bottom, it will have a line and its length will be the same as the parent div .在底部,它会有一条线,其长度与父div相同。

One special is that the p of car will have many words, when the width of the phone is not enough, it will go to the next line.比较特别的是car的p会有很多字,当手机宽度不够的时候会go到下一行。 If it is still not enough, it will become Tesla, Honda, BMW,...如果还不够,就变成特斯拉、本田、宝马……

it is the Sample Image这是样本图像

I really try many methods(float, position,...), but I still cant deal with it,真的试了很多方法(float, position,...),还是处理不了,

Here is the HTML part (using React)这是 HTML 部分(使用 React)

<div className='loop'>
   <img className='image' src={value.image}></img>
       <div>
           <p className='title'>{value.name}</p>
       </div>
       <div class>
           <p className='car'>Tesla, Honda, BMW, Porsch,Mitsubishi, Mazda, Toyota, Jaguar, KIA </p>
       </div>
       <div>
           <p>{value.salary}</p>
       </div>
       <div className='linebreak'></div>
 </div>

Try with grid:尝试使用网格:

 .loop { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: .5em; width: 400px }.image { grid-row: span 3; }.linebreak { margin-top: .5em; grid-column: span 2; border: 2px solid #4f86f7; }.loop p, img { border: 2px solid #777696; margin: 0; }.title { align-self: start; }.salary { align-self: end; }
 <div class='loop'> <img class='image' src="https://picsum.photos/100" /> <p class='title'>name</p> <p class='car'>Tesla, Honda, BMW, Porsch,Mitsubishi, Mazda, Toyota, Jaguar, KIA </p> <p class='salary'>salary</p> <div class='linebreak'></div> </div>

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

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