简体   繁体   English

屏幕尺寸变化时如何获得图像宽度反应?

[英]How to get a image width when screen size changes in react?

I had created a image hover,Some text in screen when i hover cover the text image appears the image is responsive,i want to set the text width equal to image width when changing the screen size the text width should change with image width,Please help me i'm using this css lib How can i create the function to get the width of the image and set it to text width? 我已经创建了一个图像悬停,当我将鼠标悬停覆盖文本图像时屏幕上出现了一些文本,该图像会响应,我想在更改屏幕大小时将文本宽度设置为等于图像宽度,文本宽度应随图像宽度而变化,请帮帮我, 我正在使用此CSS库。 如何创建函数以获取图像的宽度并将其设置为文本宽度?

const About = () => {
    return (
        <div className="bucket">
            <div class="row">
                <div class="col-sm-8 mainOne">
                <figure class="imghvr-shutter-in-horiz">
                <h1 className=" text animated bounceInLeft delay-2s">A Front-End Dev...</h1>
                    <figcaption>

                    <img 
                 className="responsive"
                    src="https://netbramha.com/wp-content/uploads/2016/12/senior-front-end-developer-openings-1.gif"/>
                    </figcaption>
                </figure>

                </div>
                <div class="col-sm-4 mainTwo">
                    <div className="col">sub one</div>
                    <div className="col">sub two</div>
                </div>
            </div>
        </div>
    )
}

CSS 的CSS

 .responsive {
    width: 100%;
    height: auto;
  }

You can use the class fill available 您可以使用可用的课程填写

.responsive{
   width: -webkit-fill-available;
}
<Image
   style={{flex:1, height: undefined, width: undefined}}
   source={require('../../../assets/images/onboarding-how-it-works.png')}
   resizeMode="contain"
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM