创建左侧固定图像、右侧按钮、中央或中间文本的布局
P粉681400307
P粉681400307 2023-09-04 21:02:34
[CSS3讨论组]

我正在制作一个食品订单布局,其中左侧包含图像,中间包含文本,右侧用于添加按钮。

图像固定在左侧,但按钮根据中间文本长度移动。所以我想修复这个布局:

按钮也将固定在右侧,与左侧图像相同,并且不依赖于中间测试长度。

如果文本较长,则文本将移至下一行。

Foodlist.js

import React from "react";
import "./Foodlist.css";
import { useStateValue } from "../../StateProvider";

function Foodlist({ id, title, rating, image, price, info, stock, nostock  }) {
 
  const [{ basket }, dispatch] = useStateValue();

  // console.log("This is the basket >>>", basket);


  const addToBasket = () => {
    // dispatch the item into the data layer
      dispatch({
          type: "ADD_TO_BASKET",
          item: {
              id: id,
              title: title,
              info: info,
              image: image,
              price: price,
              stock: stock,
              nostock: nostock,
              rating: rating,
          },
      });
  };


  return (
    <div className="food">
      <div className="food__details">
        <img src={image} alt="" />
        {/* <button onClick={addToBasket} style={{fontWeight: "bold"}}>
          <strong style={{fontSize: 20}}>+ </strong>
          Add
        </button> */}
      </div>

      <div className="food__title">
        <div className="food__info__layout">
          <p style={{fontWeight: "bold"}}>{title}</p>
          <p className="food__info">
            <small>₹ </small>
            <strong style={{fontSize: 14 ,fontWeight: 100}}>{price}</strong>
          </p>
        </div>

        <button onClick={addToBasket} style={{fontWeight: "bold"}}>
          <strong style={{fontSize: 20}}>+ </strong>
          Add
        </button>
        
      </div>
    </div>
  );
}

export default Foodlist

Foodlist.css

.food {
  display: flex;
  flex-direction: row;
  background-color: transparent;
  align-items: center;
  margin: 5px;
}

.food__details{
  display: flex;
  flex-direction: row;
}

.food__details > img {
  max-height: 100px;
  width: 120px;
  object-fit: contain;
  margin-right: 10px;
  border: 1px solid gold;
  border-radius: 10px;
  overflow: hidden;
}

/* 
.food__details > button {
  background: gold;
  border: none;
  cursor: pointer;
  border-radius: 5px;
  height: fit-content;
  width: fit-content;
} */


.food__info__layout {
  display: flex;
  flex-direction: column;
}

.food__info {
  display: flex;
  flex-direction: row;
  height: auto;
  /* margin-bottom: 5px; */
}

.food__title {
  display: flex;
  flex-direction: row;
}

.food__title > button {
  background: gold;
  border: none;
  cursor: pointer;
  border-radius: 5px;
  height: fit-content;
  width: fit-content;
  margin-left: 15px;
}

P粉681400307
P粉681400307

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号