CSS“背景位置:中心”不适用于移动设备

时间:2020-08-20 17:25:58

标签: html css background-image background-position background-size

我目前正在一个网站页面上,其中一张图像覆盖了整个页面。这是我的代码。

- (void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
    
    
    CGPoint p = [gestureRecognizer locationInView:self.tableView];
    selectedIndexPath = [self.tableView indexPathForRowAtPoint:p];
    

    if (selectedIndexPath != nil && gestureRecognizer.state == UIGestureRecognizerStateBegan) {
        [self.tableView reloadData];
        [self resetTableView];
        
        PresentationCell *cell = (PresentationCell *)[self.tableView cellForRowAtIndexPath:selectedIndexPath];
        NSLog(@"start click");
        [cell.deleteButton setHidden:NO];
        [cell.updateShowView setHidden:YES];
        if (IS_IPAD) {
                [cell.nameLabel setHidden:NO];
                [cell.descriptionLabel setHidden:NO];
        } else {
                [cell.nameLabel setHidden:YES];
                [cell.descriptionLabel setHidden:YES];
        };
        
        // Use ivar
        if ( ! self.pressed ) {
            self.pressed = YES; // Never fire again
            hideButtonTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(hideButton) userInfo:nil repeats:NO];
        }
        // Reset timer if it is counting down
        else if ( hideButtonTimer ) {
           // Invalidate old timer
           [hideButtonTimer invalidate];
           // Start a new one
           hideButtonTimer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(hideButton) userInfo:nil repeats:NO];
        }
        // else timer already fired - no action
        
        //NSLog(@"%@", hideButtonTimer);
    }
}
.cover-bg {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
}

.banner { /* linear-gradient darkens out the background image */
  background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url("../images/image.jpg");
  background-attachment: fixed;
  height: 100vh;
  width: 100%;
}

这在PC和Mac上运行良好,即使缩小浏览器大小,效果也很好。但是,它仅在移动设备上不起作用(图像未居中,因此图像看起来非常难看)。我已经在网上进行了数小时的研究,并尝试了其他人为解决此问题而采取的所有可能的解决方案,但对我来说没有任何用处。你们中有没有人知道如何解决这个问题?

在移动设备上,我同时尝试了Safari和Chrome浏览器(两者均无法正常运行),并且我认为Firefox也无法正常运行。

0 个答案:

没有答案