如何用css让一个div弹框随内容高度自适应

前提高度不设定或者auto,min-heigth都不适应,底部会出现空白。

.errors
{
    width: 390px;
    min-height: 210px;
    background:white;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 120px;
    z-index: 100;
    margin: 150px auto;
    color: black;
}

clipboard.png

阅读 3.4k
4 个回答

把bottom:0 去掉

定位属性,top,left,right,bottom,相对应的两个属性是位置,三个或者四个属性就是相当于设置宽高属性了,所以去掉bottom,或者top,属性

加一个transform: translate(-50%, -50%);

感觉 你贴的代码和你的截图并不对应。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题