aspect-ratio

Java: maintaining aspect ratio of JPanel background image

£可爱£侵袭症+ 提交于 2019-11-25 21:42:30
问题 I have a JPanel with a painted background image and a layout manager holding other smaller images, all of this inside a JFrame . The background image is pretty big and I want to be able to have it maintain its aspect ratio whether its on a big or small monitor. Eventually, I want to be able to have my LayoutManager and the smaller images in its cells \"glued\" to the background picture. I looked around for resources and it seems that many examples use a BufferedImage but I am not; will this

Maintain the aspect ratio of a div with CSS

痴心易碎 提交于 2019-11-25 21:34:24
问题 I want to create a div that can change its width/height as the window\'s width changes. Are there any CSS3 rules that would allow the height to change according to the width, while maintaining its aspect ratio ? I know I can do this via JavaScript, but I would prefer using only CSS. 回答1: Just create a wrapper <div> with a percentage value for padding-bottom , like this: div { width: 100%; padding-bottom: 75%; background: gold; /** <-- For the demo **/ } <div></div> It will result in a <div>