css width eq height

2017-11-15  本文已影响13人  9682f4e55d71

https://stackoverflow.com/questions/5445491/height-equal-to-dynamic-width-css-fluid-layout

  1. html
<div id="container">
    <div id="dummy"></div>
    <div id="element">
        some text
    </div>
</div>
  1. css
#container {
    display: inline-block;
    position: relative;
    width: 100%;
}
#dummy {
    margin-top: 50%;
}
#element {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: silver;
}

上一篇下一篇

猜你喜欢

热点阅读