html宽度不随文本变化,html – 如果文本宽度超过90%,则阻止文本从容器中移出...

如果滚动条的宽度是固定的(300px),并且文本的宽度(文本,而不是元素)或多或少是固定的(大约85px – 从1%到100%),请将文本设置为绝对定位的伪元素.progress的子项,并设置它的宽度和最大宽度:

width: calc(100% + 100px);

max-width: 300px;

如果将文本右对齐,它将显示在条形后面,直到达到最大宽度.

/** js to demonstrate changing values **/

var progressBar = document.querySelector('.progress');

function progress() {

var minmax = [0,100];

var step = 1;

const iterate = (current) => {

progressBar.style.width = `${current}%`;

progressBar.setAttribute('data-percentage',current);

if(current !== minmax[1]) {

setTimeout(() => iterate(current + step),40);

} else {

minmax = minmax.reverse();

step = -step;

setTimeout(() => iterate(minmax[0]),500);

}

}

iterate(minmax[0]);

}

progress();

section#progressish {

padding: 20px;

width: 300px;

}

div#progressbar {

background-color: #d1d1d1;

height: 10px;

margin-bottom: 15px;

width: 100%;

}

div#progressbar>.progress[data="bar"] {

position: relative;

background-color: #111111;

height: 10px;

margin-bottom: 15px;

width: 0%;

}

.progress::before {

position: absolute;

top: -20px;

width: calc(100% + 85px);

max-width: 300px;

text-align: right;

white-space: nowrap;

content: attr(data-percentage)"% avklarat";

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值