简体   繁体   English

如何使用 Bootstrap 在 React.js 中显示图像

[英]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.我正在使用 React-Bootstrap 示例,但它不起作用。 Here is the code I'm using and here is a link to the examplehttps://react-bootstrap.github.io/components.html#media-content .这是我正在使用的代码,这里是示例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这也是它连接的 App.jsx 文件

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'))

如果你只想要图像为什么不使用:

<Image src="https://static.pexels.com/photos/296886/pexels-photo-296886.jpeg" responsive />

Try replacing this code:尝试替换此代码:

const responsiveEmbedInstance = (
<div style={{width: 500, height: 'auto'}}>
<ResponsiveEmbed a16by9>
  <embed type="image/svg+xml" src="https://static.pexels.com/photos/296886/pexels-photo-296886.jpeg" />
</ResponsiveEmbed>
</div>
);

Here is an example: http://jsfiddle.net/jayesh24/ywzw5hrt/这是一个例子: http : //jsfiddle.net/jayesh24/ywzw5hrt/

Bootstrap Jumbotron stuff does not deal with background image. Bootstrap Jumbotron 的东西不处理背景图像。 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 }/>在您的 div 中: <img style={{height:'auto',width:'100%'}} src={ Jumbotron }/>

It should be a16by9 and not a16b9.它应该是 a16by9 而不是 a16b9。 Answered by rishipuri由 rishipuri 回答

Use react-bootstrap package使用 react-bootstrap package

import Image from "react-bootstrap/Image";
import "bootstrap/dist/css/bootstrap.css";

<Image src="image.png" fluid/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM