我有一个带有span元素的按钮元素,我需要能够获得跨度的实际宽度。
<button id="button"><span>text that is longer than the button width</span></button>
我尝试的所有方法都没有显示真正的宽度(这是JSFiddle示例大约是233px - 只需从span中删除溢出:隐藏的css属性就可以看到):
答案 0 :(得分:1)
跨度的实际宽度与按钮相同,因为您隐藏了任何溢出。
我认为你需要得到跨度的卷轴宽度,事实上你几乎就在那里:
import sys
class Shelf:
def get_factor(self):
self.some_factor = 0.5
return self.some_factor
class CalcB:
def __init__(self):
self.shelf = Shelf()
self.ref = 1.0
self.area = 3.14285
def run(self):
print("Calculation B running")
some_factor = self.shelf.get_factor()
self.update_val(some_factor)
def update_val(self, some_factor):
self.value = some_factor*self.area
if (self.value > self.ref):
print("too bad.. exiting the program")
sys.exit()
class A:
def main_logic(self):
b = CalcB()
b.run()
# some more code follows...
#do_something()
#d = CalcD()
#do_something_else(d)
if __name__ == "__main__":
a = A()
a.main_logic()
答案 1 :(得分:0)