第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何使用 HTML 和 CSS 將 div 放在圖像上?

如何使用 HTML 和 CSS 將 div 放在圖像上?

夢里花落0921 2023-07-20 16:06:47
我還是一個編程初學(xué)者,我正在做一個項(xiàng)目來提高知識。我需要在圖像頂部插入一個帶有文本的 div,我正在嘗試重新創(chuàng)建下圖的示例:div 的一半是圖像,另一半是文本。你能告訴我該怎么做嗎?這是我放入codeandbox 的代碼import React from "react";import "./styles.css";export default function App() {  return (    <div className="App">      <h1>Restaurant</h1>      <div        style={{          display: "flex",          flexDirection: "column",          justifyContent: "baseline",          alignItems: "baseline",          height: "200px",          width: "100%",          maxWidth: "300px"        }}      >        <div>          <img            style={{              width: "100%",              height: "100%"            }}            src="https://b.zmtcdn.com/data/collections/271e593eb19475efc39021c6e92603db_1454591396.jpg"            alt=""            className="img"          />        </div>        <div className="divText">          <span            style={{              color: "#fff",              backgroundColor: "#000"            }}          >            Lorem Ipsum! Lorem Ipsum! Lorem Ipsum!          </span>        </div>      </div>    </div>  );}
查看完整描述

3 回答

?
30秒到達(dá)戰(zhàn)場

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個贊

設(shè)置背景圖像有兩種解決方案:


使用 CSS 中的背景屬性


.divText {

  background-image:url("https://b.zmtcdn.com/data/collections/271e593eb19475efc39021c6e92603db_1454591396.jpg");

}

使用定位來制作自定義布局


export default function App() {

  return (

    <div className="App">

      <h1>Restaurant</h1>

      <div

        style={{

          position: "relative",

          height: "200px",

          width: "300px"

        }}

      >

        <img

          style={{

            width: "100%",

            height: "100%"

          }}

          src="https://b.zmtcdn.com/data/collections/271e593eb19475efc39021c6e92603db_1454591396.jpg"

          alt=""

          className="img"

        />

        <div className="divText"

          style={{

            position: "absolute",

            bottom: 0,

            height: "50%",

            width: "100%",

            color: "#fff",

            backgroundColor: "#000",

            opacity: 0.7

          }}>

            Lorem Ipsum! Lorem Ipsum! Lorem Ipsum!

        </div>

      </div>

    </div>

  );

}



查看完整回答
反對 回復(fù) 2023-07-20
?
天涯盡頭無女友

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個贊

也許你可以做這樣的事情?


""

.wrapper {

  width: 400px;

  height: 200px;

  position: relative;

}

picture {

  position: absolute;

  z-index: -1;

}


picture img {

  object-fit: cover;

  top: 0;

}


.text-overlay {

  top: 50%;

  height: 50%;

  position: relative;

  background-color: white;

  display: flex;

  z-index: 2;

  padding: 10px;

  opacity: 0.8;

  

  font-family: sans-serif;

}

<div class="wrapper">

 <picture>

  <img src="https://images.unsplash.com/photo-1601758064224-c3c5ec910095?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2047&q=80"

  width="400px"

  height="200px"

  style=" "/>

 </picture>

 

 <div class="text-overlay">

  <p>Hello</p>

 </div>

</div>


查看完整回答
反對 回復(fù) 2023-07-20
?
寶慕林4294392

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個贊

我的這個解決方案:


樣式.css:


.divText {

  position: absolute;

  height: 50%;

  background-color: white;

  bottom: 0;

}

應(yīng)用程序.js:


import React from "react";

import "./styles.css";


export default function App() {

  return (

    <div className="App">

      <h1>Restaurant</h1>

      <div

        style={{

          display: "flex",

          flexDirection: "column",

          justifyContent: "baseline",

          alignItems: "baseline",

          height: "200px",

          width: "100%",

          maxWidth: "300px",

          position: "relative"

        }}

      >

        <div

        style={{

          height: "inherit"

        }}>

          <img

            style={{

              width: "100%",

              height: "100%"

            }}

            src="https://b.zmtcdn.com/data/collections/271e593eb19475efc39021c6e92603db_1454591396.jpg"

            alt=""

            className="img"

          />

        </div>

        <div className="divText">

          <span

            style={{

              color: "#fff",

              backgroundColor: "#000"

            }}

          >

            Lorem Ipsum! Lorem Ipsum! Lorem Ipsum!

          </span>

        </div>

      </div>

    </div>

  );

}


查看完整回答
反對 回復(fù) 2023-07-20
  • 3 回答
  • 0 關(guān)注
  • 268 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號