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

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

如何相對于圖像定位 div?

如何相對于圖像定位 div?

瀟瀟雨雨 2024-01-18 15:50:47
我有一個作品集頁面,其中包含一個網格,其中包含帶有信息疊加的圖像。這是鏈接:cyrilmoisson-dev.netlify.app有沒有一種解決方案可以使覆蓋 div 的大?。ǜ叨群蛯挾龋┡c圖像完全相同,而不使用類似的東西background: url(...); 問題是圖像是隨機大小的......這個問題不是這個問題的重復,因為它還沒有為我解決。這是每個圖像的組件代碼:src/component/ImageWithInfos/ImageWithInfos.jsx:// Lazyloadimport LazyLoad from 'react-lazyload';// Styleimport { ImageContainer, ImageSrc, ImageInfoContainer, ImageInfo } from './styles';// Utilsimport PropTypes from 'prop-types';import { v4 as uuid } from 'uuid';const ImageWithInfos = ({ height, width, src, title, infos }) => (    <LazyLoad height={height} offset={height + 100}>        <ImageContainer height={height} width={width}>            <ImageSrc src={src} alt={title} />            <ImageInfoContainer>                <ImageInfo main>{title}</ImageInfo>                {infos.map((info) => <ImageInfo key={uuid()}>{info}</ImageInfo>)}            </ImageInfoContainer>        </ImageContainer>    </LazyLoad>);ImageWithInfos.propTypes = {    height: PropTypes.number.isRequired,    width: PropTypes.number.isRequired,    src: PropTypes.string.isRequired,    title: PropTypes.string.isRequired,    infos: PropTypes.array,};export default ImageWithInfos;src/component/ImageWithInfos/index.jsexport { default } from './ImageWithInfos';感謝您的幫助。順便說一句:我正在使用反應和樣式組件,如果它改變了什么......
查看完整描述

1 回答

?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

我相信您可以將圖像和覆蓋層放在同一個 div 中,并讓覆蓋層元素覆蓋整個父 div:


<div className="parent">

  <img />

  <div className="overlay"></div>

</div>

.parent {

  position: relative;

}


.overlay {

  position: absolute;

  width: 100%;

  height: 100%;

}


查看完整回答
反對 回復 2024-01-18
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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