How can i make my background image fit to phone screen using styled components in react

Active3 hr before
Viewed126 times

9 Answers


How i made this with CSS style in react ? :s,how i can make background image in each div,You can do with dinamic props, like that

const Content = styled.div`
    border: 1px solid #000;
    background-image: url(./img/bg.gif);
    width: 2000px;
    height: 2000px;
load more v

In order to get images to load properly, you have to reference them dynamically as an import. This way, the variable URL will still work after Webpack does its thing., Is it possible for everything that exists to have a definition? , Advertising Reach developers & technologists worldwide

Move your file in public folder and try this command:

<RecommendItem imgUrl={process.env.PUBLIC_URL + '/banner.png'} >
load more v

 Pretag team - issue, fix, solve, resolve

There are four ways to set a backgroundImage style property using React's inline CSS.,This tutorial will show you all four methods, with code samples for each.,The properties set above will add background-repeat: no-repeat and width: 250px together with the background-image style to the <div> element.

function App() {
  return (
    <div style={{ 
      backgroundImage: `url("")` 
      Hello World
load more v

A common feature request from developers familiar with the web is background-image. To handle this use case, you can use the <ImageBackground> component, which has the same props as <Image>, and add whatever children to it you would like to layer on top of it.,Note that you must specify some width and height style attributes.,Allows to set a reference to the inner Image component

 Pretag team - issue, fix, solve, resolve

Nowadays, to create websites and web apps we need to care about a lot of devices and screen sizes.,This is just another approach to fluid, responsive and adaptive layouts.,Responsive layouts fit to a user's screen size. They don't change element positions, just fit. Adaptive layouts fit to user screen size as well but according to screen size, elements change position to fit the screen using media queries.

import {
} from "styled-components";
import px2vw from "../utils/px2vw";

export const Global = createGlobalStyle`
  * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  :root {
      font-size: ${px2vw(24)};

      @media (min-width: 768px) {
        font-size: ${px2vw(18)};

      @media (min-width: 1024px) {
        font-size: ${px2vw(16)};

export default Global;
load more v

Let’s build an app screen to see how we can define different primitive React Native components using styled objects from the styled-components library.,Here is an example of View and Text components being styled using styled objects from the styled-components library:,Styling an application is an important aspect of development. Managing styles could lead to better code readability. In React Native apps, the styling of components is done with the default method ofStyleSheet API. However, the CSS-in-JS approach using styled-components is another way to create and style UI components in React Native apps.

 Pretag team - issue, fix, solve, resolve

Whether you are a web developer or mobile app developer, you know that without the proper styling of your application, the UI would probably suck. Styling an application is important. I cannot put enough emphasis on how important it is for a mobile app to have a pleasing design and good use of colors.,Now let us import this component inside App.js file, after the Subtitle and let us see what results do we get.,Installing styled-components

 Pretag team - issue, fix, solve, resolve

We need to import a few more components to add style, image, text, and view.,For React Native full background image example, we are using the profoundly popular ecosystem; it is a free open source toolchain to develop React Native programs for iOS, Android, and Web.,This tutorial offers an exorbitantly easy method to add a full background image to React Native application using the ImageBackground component.

import {
} from 'react-native'
load more v

Other "screen-background" queries related to "How can i make my background image fit to phone screen using styled components in react"