Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an image in React.js with Bootstrap

Sorry if this is a duplicate question. I can't seem to solve this or find an answer.

Essentially I want to display an image so it responsively adjusts depending on screen size. I'm using the React-Bootstrap example and it just isn't working. Here is the code I'm using and here is a link to the example https://react-bootstrap.github.io/components.html#media-content .

import React from 'react';
import {ResponsiveEmbed, Image} from 'react-bootstrap';



export default React.createClass ( {
    render() {
        return (
            <div style={{width: 660, height: 'auto'}}>
                <ResponsiveEmbed a16b9>
                    <embed type="image/href+xml" href = "https://static.pexels.com/photos/296886/pexels-photo-296886.jpeg"/>
                </ResponsiveEmbed>
            </div>
        );
    }
});

This is the App.jsx file it connects too

import React from "react"
import { render } from "react-dom"
import Footer from "./components/Footer"
import HeaderNavigation from "./components/HeaderNavigation"
import App1Container from "./containers/App1Container"
import Carousel from "./components/Carousel"
class App1 extends React.Component {
  render() {
    return (
        <div>
          <HeaderNavigation />
          <Carousel />
          <App1Container/>
          <Footer/>
        </div>
    )
  }
}

render(<App1/>, document.getElementById('App1'))
like image 934
LeCoda Avatar asked Mar 10 '23 02:03

LeCoda


2 Answers

If you want just image why not to use:

<Image src="https://static.pexels.com/photos/296886/pexels-photo-296886.jpeg" responsive />
like image 160
mradziwon Avatar answered Mar 19 '23 21:03

mradziwon


Bootstrap Jumbotron stuff does not deal with background image. Try this instead at top of file:

import Jumbotron from "./src/img/1.png"

in your div: <img style={{height:'auto',width:'100%'}} src={ Jumbotron }/>

like image 40
poppytattoo Avatar answered Mar 19 '23 21:03

poppytattoo