使用overflow/text-overflow时要注意父元素的float和width

<html>
<head>
<title>无标题文档</title
<style type="text/css">
div#outter {width:200px;height:auto;}
div#wrapper {}
p{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
div#footer {clear:both;}
</style>

</head>


<body>
<div id="outter">
<div id="wrapper">
<p>ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo</p>
</div>
<div id="footer"></div>
</div>
</body>

</html>

1、最开始,div#wrapper没有设置任何样式,<p></p>中内容显示正常,过长部分省略号显示,如图1:


(图1)

2、将div#wrapper设置为

div#wrapper {float:left;}

此时,<p></p>中内容就会完全显示,不能达到省略号显示效果,如图2:


(图2)

3、给div#wrapper添加“width:auto”

div#wrapper {float:left;width:auto;}

<p></p>中内容仍然会完全显示,不能达到省略号显示效果,如图3:


(图3)

4、给div3#wrapper指定一个宽度,这里设置为父元素的100%

此时,<p></p>中内容能达到预期效果,如图4:


(图4)


所以,是包裹<p></p>的div#wrapper设置为float后,其位置虽然还是根据父元素div#outter定位,但是其宽度并不受父元素限制。

因而,当一个元素设置为float后,必须为其指定具体的width。


解释可能不太正确,欢迎指正!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<div class="Lefter" > <div style="margin-top: 0px;"> <div style="height: 50px;background:#0bcbd4"> <span style="padding-top: 15px; float: left; margin-left: 25px"></span> </div> <el-menu :default-active="$store.state.activatedIndex" class="el-menu-vertical1" background-color="#1e1e21" :router="true" text-color="#fff" v-show="showMenu" > <el-menu-item index="1" route="/mainWeb"> <el-badge :count="15" type="primary" > <el-icon><VideoCameraFilled /></el-icon> <span>视频管理</span> </el-badge> </el-menu-item> <el-sub-menu index="2" route="/fileManage"> <template #title> <el-icon><VideoCamera /></el-icon> <span>生成视频</span> </template> <el-menu-item index="2-2" route="/VirtualMenu/2"><span>虚拟人</span></el-menu-item> <el-menu-item index="2-3" route="/VirtualMenu/3"><span>背景</span></el-menu-item> <el-menu-item index="2-1" route="/VirtualMenu/1"><span>模板</span></el-menu-item> <!-- <el-menu-item index="2-4" route="/VirtualMenu/4"><span>素材</span></el-menu-item> --> </el-sub-menu> .Lefter { width: 130px; float: left; display: inline-block; overflow: hidden ; height: 100vh; background-color: #2f2e36; } .el-menu-item { padding-left: 10px; font-size: 15px; } .el-menu-vertical1:not(.el-menu--collapse) { width: 210px; min-height: 100vh; padding-left: 0px; margin-left: 0; } :deep().el-sub-menu__title { width: 275px; font-size: 15px; } .badge{ /* margin-top: 10px; margin-right: 40px; */ /* background-color: white; */ font-size: larger; /* color: crimson; z-index: 9999 !important */ }
最新发布
07-23

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值