V
V
Vladislav2018-03-04 15:46:39
css
Vladislav, 2018-03-04 15:46:39

How to properly set the style attribute in React?

I have a problem,
there is a component in which an image should be placed on the background of the block through the style attribute, the image should be transferred to the component by props from top to bottom. I implemented approximately according to the documentation, but there is simply no picture!

import React from 'react';

import Button from './Button'

export default function Post(props){
    const postImage ={
        background: 'url(' + props.img + ') no-repeat center top/cover'
    };
    return(
        <div className="col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <div className="post__item" style={postImage}>
                <div className="descr">
                    <p className="post__title">{props.title}</p>
                    <Button className="button">Open</Button>
                    <div className="post__descr">
                        {
                            props.descr
                        }
                    </div>
            </div>
        </div>
    </div>
    );
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-04
@Cetch

I implemented roughly according to the documentation, but...

And exactly according to the documentation instead of about did not try? - well, there, {{postImage}}remove the curly brace from both ends, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question