亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

CSS Flex 屬性不適用于我的 React 組件

CSS Flex 屬性不適用于我的 React 組件

慕田峪9158850 2023-05-25 15:42:42
我正在處理一個要求我在樣式中使用 Flex 的 React 項目。所做的一切只是不起作用已經使用了幾乎所有的 flex 屬性,但它似乎不起作用。我的預期輸出是下圖但這就是我在下面得到的另外,我的條形圖組件是這樣的import React from "react";const tenHighestPopulation = [  { country: "World", population: 7693165599, percentage: 0 },  { country: "China", population: 1377422166, percentage: 0 },  { country: "India", population: 1295210000, percentage: 0 },  { country: "USA", population: 323947000, percentage: 0 },  { country: "Indonesia", population: 258705000, percentage: 0 },  { country: "Brazil", population: 206135893, percentage: 0 },  { country: "Pakistan", population: 194125062, percentage: 0 },  { country: "Nigeria", population: 186988000, percentage: 0 },  { country: "Bangladesh", population: 161006790, percentage: 0 },  { country: "Russian", population: 146599183, percentage: 0 },  { country: "Japan", population: 126960000, percentage: 0 },];export default function Bargroup() {  for (var i = 0; i < tenHighestPopulation.length; i++) {    const max = Math.max.apply(      Math,      tenHighestPopulation.map(function (o) {        return o.population;      })    );    // console.log(max);    // we do the conversion here    tenHighestPopulation[i].percentage =      Math.round((tenHighestPopulation[i].population / max) * 100) + "%";  }  return (    <div className="percent" >      {tenHighestPopulation.map((countries, index) => (        <div key={index}  className="details">          <div className="country"> {countries.country}</div>       <div className="content"  style={{              backgroundColor: "yellow",              width: `${countries.percentage}`,            }}></div>           <div className="population"> {countries.population}</div>        </div>      ))}    </div>  );}
查看完整描述

3 回答

?
紅顏莎娜

TA貢獻1842條經驗 獲得超13個贊

嘗試將其用于計數元素:


Flex: 1;

Justify-self: end;


查看完整回答
反對 回復 2023-05-25
?
躍然一笑

TA貢獻1826條經驗 獲得超6個贊

我在主文件中看不到您導入的工作表。在下面:

import React from "react";

放:

import './pathToYourCss.css';


查看完整回答
反對 回復 2023-05-25
?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

需要放在彈性框(列)中的與其說是列表,不如說是列表項:

display: flex; flex-flow: row nowrap; .details, .population: flex-shrink: 0; content-wrapper: flex-grow: 2;

這應該讓你接近。干杯


查看完整回答
反對 回復 2023-05-25
  • 3 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號