簡體   English   中英

如果屏幕分辨率小於1280,則裁剪圖像

[英]crop image if screen resolution less then 1280

所以我發現的最后一個問題與2010年類似

我有一張1920像素寬的圖片。 我從左到右按比例調整大小。 但是,如果分辨率小於1280,我需要停止調整大小,並且僅將其兩側(左/右)切開,如果res> 1280,則保持居中。

.mainImg {
  position: absolute;
  height: 558px;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
}

我想我需要一個隱藏了溢出的包裝器,我嘗試了很多選擇,但是沒有一個起作用。

可能有人已經知道解決方案了嗎? 我會很感激!

 <body>
    <div class="container">
      <!-- Main part of the webpage -->
        <img src="img/main_01.jpg" class="mainImg shadow" alt="seo matters" />
    </div> <!-- /container -->
  </body>

設置min-width: 1280px; 那么它應該停止在1280px處調整大小。

這對我有所幫助, http://css-tricks.com/perfect-full-page-background-image/

也許您可以更改它以滿足您的需求。

感謝Tom Chew負責人Millard的鏈接。 這段(編輯過的)代碼按我的意願工作。

 img.mainPic {
  /* Set rules to dimensions */
  min-height: 100%;
  min-width: 1280px;

  /* Set up proportionate scaling */
  width: 100%;
  height: auto;

  /* Set up positioning */
  position: absolute;
  top: 0;
  left: 0;
}

@media screen and (max-width: 1280px) { /* Specific to this particular image */
  img.mainPic {
    left: 50%;
    margin-left: -640px;   /* 50% */
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM