Chrome应该不重新计算元素宽度

时间:2015-10-26 19:45:42

标签: html css google-chrome

我需要根据元素的高度调整元素的宽度,并且认为我使用透明的 import UIKit class UserCell_TableViewCell: UITableViewCell { @IBOutlet weak var userImage: UIImageView! @IBOutlet weak var userDescription: UILabel! @IBOutlet weak var loadIndicator: UIActivityIndicatorView! override func awakeFromNib() { super.awakeFromNib() // Initialization code } override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) // Configure the view for the selected state } func downloadedFrom(urlLink :String) { self.loadIndicator.startAnimating() if let urlData = NSURL(string: urlLink) { NSURLSession.sharedSession().dataTaskWithURL(urlData) { (data, response, error) in if error != nil { print("error = \(error)") self.loadIndicator.stopAnimating() return } else { // El servidor contesta la petición, pero la imágen puede no existir. if let httpResponse = response as? NSHTTPURLResponse { if httpResponse.statusCode == 200 { dispatch_async(dispatch_get_main_queue()){ self.userImage.image = UIImage(data: data!) self.loadIndicator.stopAnimating() }} }} }.resume() } } } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let newCell = tableView.dequeueReusableCellWithIdentifier("userCell") as! UserCell_TableViewCell let selectedUser = userArray[indexPath.row] newCell.userDescription?.text = selectedUser.getFirstName() + " " + selectedUser.getLastName() let randomNumber = arc4random_uniform(4) let arrayIndex = Int(randomNumber) let urlImage = imageArray[arrayIndex] newCell.downloadedFrom(urlImage) return newCell } 技巧制定了一个非常聪明的解决方案:

http://jsfiddle.net/6yc8a2yj/

粉红色的div正确呈现1:2的比例;但是,它应该在视口执行时调整大小(因为它具有100vh元素的100%的高度),但它没有。

如果调整视口大小,img元素会在视口高度增加时增加宽度,但img元素的宽度不会增加以容纳它,这违反了{container的规则1}}表示(如果您在Chrome控制台中选中并取消选中display: inline-block上的显示样式,则会正确调整大小以适合其子内容)。我假设问题是元素维度计算是父对子,因此当.container元素调整大小时,Chrome不会重新计算它的父级维度。有没有办法欺骗它呢?

1 个答案:

答案 0 :(得分:0)

Chrome最小化重新布局周期。这一般都很好。

我建议您在.viewport上设置height:50vh而不是width:max-content;,而在.container上使用public abstract class Mower { private String manufacturer; private int year; private String serialNumber; public String tostring(){ String temp = "Manufacturer: " + getManufacturer() + "\nYear: " + getYear() + "\nSerial Number:" + getSerialNumber() + "\n"; return temp; } } public class LawnTractor extends Mower{ private Engine engine = new Engine(); private String model; private double deckWidth; public LawnTractor(){ super(); } public String toString(){ String temp = super.tostring() + "Engine:\n" + getEngine().toString() + "\nModel: " + getModel() + "\nDeck Width: " + getDeckWidth() + "\n"; return temp; } public class CommercialMower extends LawnTractor { private double operatingHours; private boolean zeroTurnRadius; public CommercialMower(){ super(); } public String toString(){ String temp = super.toString() + "Operating Hours: " + getOperatingHours() + "\nZero Turn Radius: " + isZeroTurnRadius() + "\n"; return temp; }

请参阅:http://jsfiddle.net/0jgo5894/1/

关于vh单位:http://sciter.com/css-vwvhvminvmax-units-are-quite-dangerous/