1
我已经习惯于使用媒体查询来动态更改DOM元素ad-hoc。不过,据我所知,这些只能检测窗口/设备宽度/高度,而不是单个DOM元素。我希望能够制作一个CSS,它将根据该元素的大小重新排列和调整元素内容的大小。例如:我可以根据自己的尺寸动态调整元素的内容大小吗?
╒══════════════════════════════╕
│Browser Window │
├──────────────────────────────┤
│ ┌──────────────────────────┐ │
│ │.resizingParent │ │
│ │┌──────┐ Some caption text│ │
│ ││ IMG │ directly relating│ │
│ ││ │ to the image. │ │
│ │└──────┘ │ │
│ └──────────────────────────┘ │
│ │
└──────────────────────────────┘
╒══════════════════════════════╕
│Browser Window │
├──────────────────────────────┤
│ ┌───────────────┐ │
│ │.resizingParent│ │
│ │┌─────────────┐│ │
│ ││ ││ │
│ ││ I M G ││ │
│ ││ ││ │
│ ││ ││ │
│ │└─────────────┘│ │
│ │Some caption │ │
│ │directly │ │
│ │relating to the│ │
│ │image. │ │
│ └───────────────┘ │
│ │
└──────────────────────────────┘
我希望的解决方案是为使用媒体查询,如下面的(无效)代码一样简单:
<STYLE>
.resizingParent>IMG {
display: inline-block;
width: 25%;
}
.resizingParent(max-width:10em)>IMG {
display: block;
width: 100%;
}
</STYLE>
<DIV CLASS=".resizingParent">
.resizingParent
<IMG SRC="IMG.png" ALT="IMG"/>
Some caption text directly relating to the image
</DIV>
我一直在收集*自然响应的各种演示*在这里:http://codepen.io/collection/LfoGq – cimmanon 2013-03-13 19:59:52
最大的问题是图像不能以我需要的方式更改大小.. 。 不管怎么说,还是要谢谢你。 – Supuhstar 2013-03-13 23:46:48
我已经更新了演示以删除div,以便图像调整大小。 – cimmanon 2013-03-13 23:58:00