我面临着对其中一种要素有“掩盖”背景的需求。
将CSS background-size: cover
与实际img
与object-fit: cover
一起使用的优缺点是什么?
据我所知,我可以通过srcSet和响应大小来更好地控制img。如果没有polyfill,它就无法在IE11中工作。
答案 0 :(得分:3)
除了其他人所说的兼容性(所有现代浏览器都支持from collections import defaultdict
hottest_day = defaultdict(lambda: -99)
for file_name in file_list:
with open('weatherdata/' + file_name) as f:
# nb: this is a list of lines so it should be a plural
# nb2: beware, you're reading the whole file in memory,
# this can crash on huge files.
lines = f.read().splitlines()
lines = lines[2:-1]
for line in lines:
# nb : python as a `csv` module, which might be safer
line = line.split(',')
year = line[0].split('-')[0]
try:
temp = int(line[1])
except ValueError as e:
# you may want to log the error somewhere
# for debugging...
continue
# defaultdict magic: if `year` has
# not been set yet, it will default to -99
if temp >= hottest_day[year]:
hottest_day[year] = temp
,而background-size: cover
却不支持)之外,将object-fit: cover
元素与div
是,如果用户尝试打印您的页面,很多时候将无法打印图像,因为浏览器会将其视为背景并被忽略。
这对您可能根本不重要,但是需要注意。
有some ways to get around this,但我不知道单个跨浏览器的Silver Bullet方法。