I can’t access container data

Asked

Viewed 27 times

0

I’m using ReactJS to set up a food page and I’m having trouble changing the properties of Container for CSS.

Here’s an example of how this in my project:

inserir a descrição da imagem aqui

Where "1" is controlled by .ImgContainer:

.ImgContainer {
    height: 150px;
    width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ImgContainer .Image {
    background-position: center;
    background-size: cover;
    height: 100%;
    width: 100%;
    transition: 0.2s;
}

.Body:hover .ImgContainer .Image {
    transform: scale(1.2);
}

the "2" by .teste:

.teste{
    border-radius: 25px;
    width: 100%;
    padding-right: 1rem;
    padding-left: 1rem;
    margin-right: auto;
    margin-left: auto;
    background-color: #ee1414c5
}

and the "3" by .Body:

.Body {
    background-color: #ffffff;
    display: inline-block;
    padding: 0;
    border-radius: 8px;
    border-style: dashed;
    border-width: 1px;
    border-color: #a2de96;
    margin: 8px 32px 8px 0;
    width: 250px;
    overflow: hidden;
    transition: 0.2s;
}

I would like to remove this white part of "3" to leave as in the reference image:

inserir a descrição da imagem aqui

But I’m not able to access this part of the container or edit it. What I’m doing wrong?

General structure of the code:

import React from 'react'
import { connect } from 'react-redux'

import * as actions from '../../../../../store/actions/actions'

import style from './item.module.css'

function Item(props) {
    const { name, desc, id, imgLink, price } = props
    const item = {
        id: id,
        name: name,
        price: price,
        desc: desc,
        imgLink: imgLink
    }
    return (
        <div className={style.Body}>
            <div className={style.ImgContainer}>
                <div className={style.Image} style={{ backgroundImage: `url(${imgLink})` }} />
            </div>
            <div className={style.teste} > 
                <span className="font-weight-light pt-2">
                    <p></p>
                    <strong>{name}</strong>
                </span>
                <br />
                <span className={`font-italic font-weight-lighter text-muted ${style.Description}`}>{desc}</span>
                <div className="row">
                    <div className={`mb-2 ${style.Row}`}>
                        <span className={`my-auto font-weight-light ${style.Price}`}>
                            <strong>€</strong> {price}
                        </span>
                        <div className={`my-auto ml-auto ${style.BtnHolder}`}>
                            <button className={style.ItemActionBtn} onClick={() => props.removeItemFromCart(item)}>
                                <i className="fa fa-minus" aria-hidden="true" />
                            </button>
                            <span className={`my-auto mx-1 font-weight-light ${style.Price}`}>
                                <strong> {id in props.itemMap ?
                                    props.cart[props.itemMap[id]].quantity : 0} </strong>
                            </span>
                            <button className={style.ItemActionBtn} onClick={() => props.addItemToCart(item)}>
                                <i className="fa fa-plus" aria-hidden="true" />
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    )
}

const mapStateToProps = state => ({
    cart: state.cart.cart,
    itemMap: state.cart.itemMap
})

const mapDispatchToProps = dispatch => ({
    addItemToCart: item => dispatch(actions.addItemToCart(item)),
    removeItemFromCart: item => dispatch(actions.removeItemFromCart(item)),
})

export default connect(mapStateToProps, mapDispatchToProps)(Item)
  • Add the complete code structure so we can analyze/reproduce the situation...

  • @Felipeduarte made!

  • Welcome to Sopt, already tried to remove the property background-color of .Body { ... } or change like that: .Body { background-color: none } or create another class in your element? .Body.sem-fundo { background: none } in your file: item.module.css

  • @Ivanferrer yes, the point is that the photo does not accompany the white part. Even removing the BACKGROUND-COLOR, the white space remains there

  • So maybe it’s because your container is bigger height, and the image is smaller, and the bottom element with the data is not at the right time to fill that area. What you could do, is enlarge the image, using two properties, object-fit: cover and background-size: cover;

  • There is also the possibility of you going up element 2 to stay above the image: .teste { position: relative; top: -50px;}, your container would adjust in height, in case if you use a min-height, instead of using a fixed height size.

  • @Ivanferrer he still keeps the bottom space :/ https://uploaddeimagens.com.br/imagens/LAatdng ja mexi in all the Infos of . Body but can’t set container size

  • Elements with display equal to inline or inline-block will work as paragraphers, thus having the same behavior as the texts in the same paragraph will have, the "concept" is explained in: https://answall.com/questions/56938/o-that-%C3%A9-baseline/56947#56947 and here I suggest a few ways around it: https://answall.com/a/306277/3635

  • Now it’s just a matter of the height of the image box...,I think you need to adjust it to suit the size of your image at the time, you put 100%, but in css, the 100% is only recognized within a fixed height context.

  • vc is using align-items: center; this causes the elements of your container to be centered on height, switch to: align-items: flex-start;

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.