父元素绝对定位后,怎么由子元素撑开宽度

adouwt 2016-08-18 04:29:23
.parent{
position: absolute;
top:-10px;
z-index: 2000 !important;
left: 100%;
background: #fff !important;
border-radius: 0 5px 5px 0;
padding:10px;
width:auto;
min-height:300px;
border: 2px solid #ddd;
}
.children{
display: inline-block;
}
如上代码,就是撑不开的父元素的宽度。求解
...全文
3160 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
前端小懒虫 2020-01-12
  • 打赏
  • 举报
回复
那不用绝对定位的方式,用什么方式比较好,达到这种效果
天际的海浪 2018-08-09
  • 打赏
  • 举报
回复
可以撑开啊

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
.parent{
position: absolute;
border-radius: 0 5px 5px 0;
padding:10px;
width:auto;
min-height:300px;
border: 2px solid #ddd;
}
.children{
display: inline-block;
}
</style>
</head>
<body>
<div class="parent">
<div class="children">
1343545685535554755757
</div>
</div>

</body>
</html>
dengjiecsdn 2018-08-09
  • 打赏
  • 举报
回复
在实际开发中,父元素的宽度是由里面的子元素撑开的,而绝对定位的子元素由于脱离了父元素文本结构,所以是撑不开父元素的。不但撑不开,而且还会受到父元素宽度的限制。所以,不要想着用定位的子元素去撑开父元素了,这理论上就是错误的!
  • 打赏
  • 举报
回复
描述不清,粘所有的代码请,left: 100%是干撒滴
布尔凯索LST 2016-08-31
  • 打赏
  • 举报
回复
你父元素没有设置宽高,就要用子元素设置一个宽高对父元素作用,然而你的子元素上只有一个display:inlinblock
wooden_fish丶 2016-08-18
  • 打赏
  • 举报
回复
不太明白楼主的问题,我给children定义一个宽度就自动撑开了

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧