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

daupos2t  于 2023-06-25  发布在  Bootstrap
关注(0)|答案(6)|浏览(149)

对不起,这是一个重复的问题。我似乎无法解决这个问题或找到答案。
从本质上说,我想显示一个图像,使其响应调整取决于屏幕大小。我正在使用React-Bootstrap示例,但它不起作用。下面是我使用的代码,下面是示例www.example.com的链接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>
        );
    }
});

这也是它连接的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'))
ldxq2e6h

ldxq2e6h1#

如果你想只是图像为什么不用途:

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

fkaflof62#

Bootstrap Jumbotron的东西不处理背景图像。在文件顶部尝试以下操作:

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

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

nhjlsmyf

nhjlsmyf3#

尝试替换此代码:

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

下面是一个例子:http://jsfiddle.net/jayesh24/ywzw5hrt/

roejwanj

roejwanj4#

它应该是a16by9而不是a16b9。由Rishipuri回答

ulydmbyx

ulydmbyx5#

使用react-bootstrap包

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

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

mrzz3bfm6#

如果存储在数据结构(const、var、...)中

<img
  src={URL.createObjectURL(image)}
  alt="Error loading file"
/>

相关问题