.parent {
width: 500px;
height: 500px;
background: red;
margin: 150px auto;
position: relative;
}
.child {
left: 300px;
top: 200px;
background: yellow;
position: absolute;
width: auto;
font-size: 16px;
line-height: 16px;
max-width: 500px;
}
<div class="parent">
<div class="child">
地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图地图
</div>
</div>
child并没有跟着内容自适应,而是自动换行了。
希望结果是
想问下这个如何实现。
- 4
新手上路,请多包涵position值为absolute时,子元素宽度默认自适应父元素,不会越界,要实现你的想法要定宽,不能auto
position值为relative时,子元素宽度默认和父元素宽度一致,即500px,调整定位值即可