html宽度设置为剩下的百分比,如何设置div以占用剩余宽度的百分比

4 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

如果您愿意更改HTML标记,这是一种方法。

在父display: table元素上使用.wrap并定义三个子单元格,左侧和右侧的宽度为50%。这三个子单元格中的每一个都将包含一个嵌套的CSS表.cwrap。

然后,您可以在最内层元素上使用display: table-cell,并根据需要指定20%和30%的宽度。

根据内容,中间单元格将根据需要进行调整。





.wrap, .cwrap {

width: 100%;

border: 1px dotted blue;

display: table;

}

.c1 {

display: table-cell;

width: 50%;

border: 1px dotted gray;

}

.c2 {

display: table-cell;

border: 1px dotted gray;

}

.cc1 {

display: table-cell;

width: 20%;

border: 1px dotted gray;

}

.cc2 {

display: table-cell;

width: 30%;

border: 1px dotted gray;

}

Should take 20%
Should take 30%
Something
 / 
Something
Should take 30%
Should take 20%




答案 2 :(得分:0)

我认为您正在寻找css calc()功能。

按如下方式使用:

示例:calc(20% - 20px)

这样您可以使用百分比和px / em来计算宽度/高度。

进一步解释here。

答案 3 :(得分:0)

Should take 30%
Something
 / 
Something
Should take 30%
Should take 20%

#outer {

min-width: 2000px;

position: relative;

padding: 0px;

}

#1{

width: 20%;

display:inline-block;

}

#2{

width: 30%;

display:inline-block;

}

#3{

width: 2em;

display:inline-block;

}

#4{

width: 1em;

display:inline-block;

}

#5{

width: 2em;

display:inline-block;

}

#6{

width: 30%;

display:inline-block;

}

#7{

width: 20%;

display:inline-block;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值