如何在1920px和1366px(笔记本电脑)屏幕尺寸上创建兼容的网页?

时间:2017-08-07 02:01:32

标签: html css twitter-bootstrap sass

我正在开发一个要求为1920 * 1080px的网站。总共有五个部分,每个部分都是相同的规格(宽度为1920,高度为1080)。我没有使用bootstrap容器,因为它的宽度是960px并且还使用容器 - 流体我无法获得预期的输出。所以我在scss中设置每个div的宽度和高度,并且在1920px屏幕尺寸上页面看起来很好。但是当我在笔记本电脑中打开它时,它会变得非常糟糕。我也在使用多个图像,具有位置和z-index属性的叠加层。 html结构如下:

<div id="page_index">
 <div class="wrapper">
  <div id="one">
    <div class="row">
      <div class="col-xs-12 text-center">
      <!-- Here are the contents -->
      </div>
    </div>
  </div>
   <!-- div id=two, three, four, five goes here -->
 </div>
</div>

以下是我设置高度和宽度的一个div的示例:

#one {
    background-color: $g_color_blue_promotion;
    width: 1920px;
    min-width: 100%;
    margin: 0 auto;
    height: 1080px;
    font-family: 'Open Sans', sans-serif;
    position: relative;
}

在这种情况下,最适合两种屏幕尺寸的应该是什么?请注意,此页面不需要响应,但至少用户应该能够在两种屏幕尺寸上查看它。

1 个答案:

答案 0 :(得分:-2)

import UIKit

extension UIImage {
    static func resizeImage(image: UIImage, width: CGFloat) -> UIImage {
        let scale = width / image.size.width
        let newHeight = round(image.size.height * scale)
        UIGraphicsBeginImageContextWithOptions(CGSize(width:width, height:newHeight), false, image.scale)

        image.draw(in: CGRect(origin: CGPoint(x:0, y:0), size: CGSize(width: width, height: newHeight)))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return newImage!
    }

    static func resizeImage(image: UIImage, height: CGFloat) -> UIImage {
        let scale = height / image.size.height
        let newWidth = round(image.size.width * scale)
        UIGraphicsBeginImageContextWithOptions(CGSize(width:newWidth, height:height), false, image.scale)
        image.draw(in: CGRect(origin: CGPoint(x:0, y:0), size: CGSize(width: newWidth, height: height)))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        return newImage!
    }
}

let image = UIImage(named: "image.jpg")!
var mask = UIImage(named: "mask.jpg")!

let k1 = image.size.width / image.size.height
let k2 = mask.size.width / mask.size.height

if k1 >= k2
{
    mask = UIImage.resizeImage(image: mask, height: image.size.height)
}
else
{
    mask = UIImage.resizeImage(image: mask, width: image.size.width)
}

image
mask

let center = CGPoint(x: image.size.width/2, y: image.size.height/2)
let croppingRect = CGRect(x: abs(image.size.width-mask.size.width)/2*image.scale,
                                  y: abs(image.size.height-mask.size.height)/2*image.scale,
                                  width: mask.size.width*image.scale,
                                  height: mask.size.height*image.scale).integral
let maskReference = mask.cgImage!
let imageReference = image.cgImage!.cropping(to: croppingRect)!
let imageMask = CGImage(maskWidth: maskReference.width,
                        height: maskReference.height,
                        bitsPerComponent: maskReference.bitsPerComponent,
                        bitsPerPixel: maskReference.bitsPerPixel,
                        bytesPerRow: maskReference.bytesPerRow,
                        provider: maskReference.dataProvider!, decode: nil, shouldInterpolate: true)

imageMask?.colorSpace
imageMask?.alphaInfo

let maskedReference = imageReference.masking(imageMask!)
let maskedImage = UIImage(cgImage:maskedReference!, scale: image.scale, orientation: image.imageOrientation)

在你的JS文件头上使用它。