G
G
Gary_Ihar2021-06-05 22:23:03
React
Gary_Ihar, 2021-06-05 22:23:03

What is the difference in these two ways of writing styles?

Option 1:

style ={{background: `url(${props.item.img}) center center no-repeat`,}}

Option 2:
style ={{   
    backgroundImage: `url(${props.item.img})`,
    backgroundPosition: 'center center',
    backgroundRepeat: 'no-repeat',
}}


What is the fundamental difference between the two ways of writing styles inline in React?
The question arose because option 1 sometimes omits the "center center" property. I had to write through option 2 and everything became normal. Why did it happen?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-06-05
@Gary_Ihar

I suspect some garbage arrives in img, which cuts off the rest of the record. Otherwise, no difference. Well, except that background overwrites all other properties (even those that are not specified, i.e. if background-color was set, it will become the default, i.e. transparent).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question