简体   繁体   English

如何按比例缩放到父级?

[英]How to scale proportionally to the parent?

I use an absolute div to put my centerbox into the imgwrap , but it don't follow the scale of my imgwrap box , even it is his parent. 我使用绝对div将中心imgwrap放入imgwrap ,但是它不遵循imgwrap框的大小,即使它是他的父母。 How could I make the center box be center of the imgwrap and scale proportionally when user resize? 当用户调整大小时,如何使中心框成为imgwrap的中心并按比例缩放? What's the correct way to do that? 正确的方法是什么? I thought absolute would follow the parent 我以为绝对会跟随父母

http://jsfiddle.net/gpqAx/ http://jsfiddle.net/gpqAx/

 <div id='imgwrap'>
            <img src='http://www.papercut.com/images/layout/banner-background-home-tree.png'>
        <div id='myabsolute'>
            <div id='centerbox'>
                Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod             tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,             quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo             consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse             cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non             proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            </div>
        </div>
</div> <!-- imgwrap -->

Yes, you're right but you also need to specify the distance from the edges. 是的,您是对的,但还需要指定到边缘的距离。 Add

top: 25%;
left: 25%;
right: 25%;
bottom: 25%;

to #centerbox #centerbox

You might also need to adjust its height. 您可能还需要调整其高度。 See this jsFiddle 看到这个jsFiddle

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

相关问题 html-按比例缩放图像以适合父对象 - html - Scale image proportionally to fit parent 如何按比例缩放此Flexbox瓷砖网格 - How to scale proportionally this flexbox tiles grid 如何根据父级按比例调整子图像的大小? - How to resize child images proportionally to parent? 如何按比例将图像缩放到最大宽度? - How can I proportionally scale images to max-width? 如何使图像与Web浏览器窗口的大小成比例缩放? - How do I make images scale proportionally to the resizing of a web browser window? 如何按比例缩小 <img> WxH中的较短者设置为固定数字? - How can I proportionally scale down an <img> element with the shorter of its WxH set to a fixed number? 我们如何使用 TailwindCSS 按比例缩放图像以始终适合视口? - How can we use TailwindCSS to proportionally scale an image to always fit within the viewport? 如何根据容器高度按比例缩放多个图像? - How can I make a number of images scale proportionally based on its container height? 如何按比例缩放图像并确保其始终占据屏幕的40% - how to proportionally scale an image and make sure it is always taking up 40% of screen 我有一个由5张图片组成的表格,该如何为该表格设置样式,以便在多种浏览器尺寸上按比例缩放? - I have a table composed of 5 images, how can i style this table so that it will scale proportionally on multiple browser sizes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM