react 如何引入圖片, 背景圖片, 盒子上下左右居中


import React, { Component } from 'react'
import Img from '@/assets/logo.png'  //這個圖片,是src下assets文件夾
import './styles.less'

export default class Imgs extends Component {
  render() {
    return (
      <div className='pages_img' style={{ backgroundImage: `url(${Img})` }}>
        <section className='section'>
        </section>
        {/* <img src={Img} /> */}
      </div>
    )
  }
}

  

.pages_img{
  height: 100%;
  max-width: 1920px;
  background: no-repeat center center;
  //background: url("../../assets/logo.png")  no-repeat center center;  //上面是通過 style 直接寫的 如果不用style 在less 中 可以這樣寫
  margin: 0 auto;
  display: flex;
  section{
    width: 500px;
    height: 500px;
    background: rgba(255, 255, 255, 0.5);  //盒子背景半透明
    margin: auto auto;
    // opacity: 0.5  //盒子半透明
  }
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM