动态扩展动态加载的DIV的宽度(Dynamically expanding width of a dynamically loaded DIV)

编程入门 行业动态 更新时间:2024-10-28 20:27:20
动态扩展动态加载的DIV的宽度(Dynamically expanding width of a dynamically loaded DIV)

我创建了一个基于服务器端数据动态加载的工具提示。 它一直运作良好,直到我得到更大的SKU。 现在有溢出。

我正在尝试使用CSS或JS动态更改宽度以消除溢出, 如此小提琴所示。

我的HTML:

<div class="ext-tooltip 12345-789-1456789-431535" data-sku="12345-789-1456789-431535"> <div class="tooltip-stock">12345-789-1456789-431535 :: 5</div> </div> <div id="invoice-lines"> <div id="progress-container" class="hide" style="display: none;"> <div class="progress-bar-container"> <div id="progress-bar" class="progress-bar-progress" style="width: 100%;"></div> </div> <div class="example ta_center">Loading...</div> </div> <table cellspacing="0" id="invoice-time" class="invoice-lines spreadsheet" style="display:none"></table>

我的CSS:

.ext-tooltip { display: inline-block; background: url(//cdn.shopify.com/s/files/1/0059/3992/t/14/assets/oem-icon.png?17543244824127338148) -78px 0 no-repeat; font-family: Arial, sans-serif; padding: 0 10px 7px 3px; margin-left: 3px; line-height: 22px; overflow: hidden; color: black; font-weight: normal; font-size: 9pt; }

我的JS:

var $tooltip = $('.ext-tooltip.12345-789-1456789-431535'); $tooltip.innerWidth($('.tooltip-stock', $tooltip).innerWidth());

这样做的正确方法是什么?

I've created a tooltip that is loaded dynamically based on server side data. It's been working well until I got to much larger SKUs. Now there is overflow.

I'm trying to use either CSS or JS to dynamically change the width to eliminate the overflow as shown in this fiddle.

My HTML:

<div class="ext-tooltip 12345-789-1456789-431535" data-sku="12345-789-1456789-431535"> <div class="tooltip-stock">12345-789-1456789-431535 :: 5</div> </div> <div id="invoice-lines"> <div id="progress-container" class="hide" style="display: none;"> <div class="progress-bar-container"> <div id="progress-bar" class="progress-bar-progress" style="width: 100%;"></div> </div> <div class="example ta_center">Loading...</div> </div> <table cellspacing="0" id="invoice-time" class="invoice-lines spreadsheet" style="display:none"></table>

My CSS:

.ext-tooltip { display: inline-block; background: url(//cdn.shopify.com/s/files/1/0059/3992/t/14/assets/oem-icon.png?17543244824127338148) -78px 0 no-repeat; font-family: Arial, sans-serif; padding: 0 10px 7px 3px; margin-left: 3px; line-height: 22px; overflow: hidden; color: black; font-weight: normal; font-size: 9pt; }

My JS:

var $tooltip = $('.ext-tooltip.12345-789-1456789-431535'); $tooltip.innerWidth($('.tooltip-stock', $tooltip).innerWidth());

What's the correct way to do this?

最满意答案

从background规则中删除no-repeat允许宽度调整为不同的文本长度。

修改小提琴

Removing no-repeat from the background rule allows the width to adjust to different lengths of text.

Revised Fiddle

更多推荐

本文发布于:2023-07-22 12:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   宽度   加载   DIV   Dynamically

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!