亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在人物上創建透明背景

在人物上創建透明背景

LEATH 2023-09-28 15:26:54
我有一個頁面需要有一個圖形作為背景。但是,在某些情況下,我想要在該背景上放置一些文本以及背景(圖形上的淺灰色但透明的覆蓋物)。就目前情況而言,我設法獲得了我想要的文本,但無法獲得背景。這是我的一個示例應用程序,展示了它的工作原理。基本上我想要的只是圖像上的透明背景。const App = () => {  return (    <div>            <figure style={{                position: 'fixed',                top: 0,                left: 0,                backgroundImage: `url(https://placekitten.com/1000/1000)`,                backgroundSize: 'fit',                backgroundPosition: 'top',                width: '100%',                height: '100%',                margin: 0            }}></figure>      <div style={{  width: '100%', width: 'height%', backgroundColor: 'red'}}>        <div style={{            position: 'absolute',                      top: '50%',                      left: '50%',                      transform: 'translate(-50%, -50%)',                      width: '412px',            color: 'white'          }}>            <h1>Div content</h1>            <p>Would like to add a backdrop over the parent div</p>            <p>Make the background a light gray over the image</p>            <p>As it stands, any background related color I put on this div does not work. (see the backgroundColor set to red on one of the parent divs</p>        </div>      </div>    </div>  )}ReactDOM.render(    <App />,    document.getElementById('app'));<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script><div id="app"></div>
查看完整描述

1 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

嘗試這樣的事情。我在你的代碼中更改了這一行:


 <div style={{  width: '100%', height: '100%', backgroundColor: 'red', position: 'absolute', opacity: '20%'}}> </div>

const App = () => {


  return (

  

    <div>

            <figure style={{

                position: 'fixed',

                top: 0,

                left: 0,

                backgroundImage: `url(https://placekitten.com/1000/1000)`,

                backgroundSize: 'fit',

                backgroundPosition: 'top',

                width: '100%',

                height: '100%',

                margin: 0

            }}></figure>

      <div style={{  width: '100%', height: '100%', backgroundColor: 'red', position: 'absolute', opacity: '20%'}}> </div>

        <div style={{

            position: 'absolute',

                      top: '50%',

                      left: '50%',

                      transform: 'translate(-50%, -50%)',

                      width: '412px',

            color: 'white'

          }}>

            <h1>Div content</h1>

            <p>Would like to add a backdrop over the parent div</p>

            <p>Make the background a light gray over the image</p>

            <p>As it stands, any background related color I put on this div does not work. (see the backgroundColor set to red on one of the parent divs</p>


        

      </div>


    </div>

  )

}



ReactDOM.render(

    <App />,

    document.getElementById('app')

);

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>

<div id="app"></div>


查看完整回答
反對 回復 2023-09-28
  • 1 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號