html - 手机和平板电脑的图像拉伸(stretch)问题

标签 html css twitter-bootstrap coldfusion

问题:在移动版本中,图像在人像模式下被拉伸(stretch)。正如您在下面看到的,它看起来很压缩。

Portrait Mode

在横向模式下,图像看起来不会拉伸(stretch),看起来与站点的桌面版本完全一样。

Landscape Mode

我正在使用 bootstrap,图像有类 img-responsive 但它不起作用。

下面是我写的css。我已经尝试设置 background-size:contain 和其他一些方法,但没有呈现预期的结果。该元素使用 Coldfusion 和 Mura (CMS)。

更新

正在使用以下 css 以使其响应:

@media (min-width: 1024px) #homepage .carousel .item img {
  width:100%;
  height:auto;
}
media (min-width:769px) and (max-width:980px) {
  #homepage .carousel .item img {
    max-width: 100%;
    min-height: 100%;
    height: auto;
    margin-top: 154px !important;
  }
}
@media (max-width: 751px) and (orientation: landscape) {
  .override-hidden-xs1 {
    display: block;
  }
  .carousel-inner {
    width: 100% !important;
  }
  .fixNext {
    margin-right: 0px;
  }
  .carouselCaption {
    margin-top: 120px !important;
  }
  .h4Font {
    font-size: 16px !important;
  }
  .upcoming-events-image {
    max-width: 180px;
    max-height: 180px;
    width: 22% !important;
    margin-left: 340px !important;
  }
  .image-margin-top {
    margin-top: 170px !important;
    display: inline-block;
  }
}
@media (max-width: 767px) {
  #homepage .carousel .item {
    height: 200px;
    margin-top: 241px;
  }
  #homepage .carousel .item img {
    max-width: 100%;
    height: auto;
    display: block;
  }
}
@media (max-width: 767px) and (orientation: landscape) {
  #homepage .carousel .item {
    height: 200px;
    margin-top: 311px;
  }
}
@media (min-width: 768px) and (max-width: 980px) {
  .company-logo {
    width: 400px;
  }
  #homepage .carousel .item img {
    /*max-width: 1200px;*/
    max-width: 100%;
    min-height: 100%;
    padding-top: 162px;
  }
  #homepage .carousel .carousel-caption {
    margin-left: 64px;
  }
  .image-margin-top {
    margin-top: 57px !important;
  }
  .changePosition {
    margin-top: -193px !important;
  }
}
@media (min-width: 920px) {
  .company-logo {
    width: 400px;
  }
  #homepage .carousel .item img {
    /*max-width: 1200px;*/
    max-width: 100%;
    min-height: 100%;
  }
}

下面是从 CMS 调用图像的 coldfusion 代码:

<div class="row carousel-inner padding-topImage">
  <cfset local.iterator.reset()>
    <cfset local.idx=0>
      <cfloop condition="local.iterator.hasNext()">
        <cfset local.item=iterator.next()>
          <cfif ListFindNoCase( 'jpg,jpeg,gif,png', ListLast(local.item.getImageURL(), '.'))>
            <div class="row item img-responsive<cfif local.idx eq 0> active</cfif>">
              <img src="#local.item.getImageURL(argumentCollection=local.imageArgs)#" alt="#HTMLEditFormat(local.item.getTitle())#">
              <cfif arguments.showCaption>
                <div class="container">
                  <div class="carousel-caption carousel-caption1">
                    <div>
                      <!--- <h3><a href="#local.item.getURL()#">#HTMLEditFormat(local.item.getTitle())#</a></h3> --->
                      <div class="visible-xs">
                        <!---<h2>#HTMLEditFormat(local.item.getTitle())#</h2>--->
                      </div>
                      <div class="hidden-xs">#local.item.getSummary()#
                        <!--- #local.item.getBody()# --->
                        <!---<p><a class="btn btn-larg btn-primary" href="#local.item.getURL()#">Read More</a></p>--->
                      </div>
                      <!---<div class="override-hidden-xs1 carouselCaption" style="color:##000"><span class="h4Font">#HTMLEditFormat(local.item.getTitle())#</span>
                                                </div>--->

                    </div>
                  </div>
                </div>
              </cfif>
            </div>
            <cfset local.idx++>
          </cfif>
      </cfloop>
</div>

更新

这是我遇到的问题,但我无法解决。

高度是固定的,所以我尝试 height: auto 但轮播中的图像消失了。

我将如何修改 css,以便背景高度取决于根据屏幕尺寸调整大小的图像。

这里是修改后的CSS:

@media (max-width: 747px){
	#homepage .carousel .item img{
		margin-top: 71px !important;
		max-width:0px;
		min-height:0%;
	}/*
	#homepage .carousel .item {
		height:180px !important;
	}*/
	.carousel-inner {
		height:auto;
	}
}
@media (min-width: 748px){
	#homepage .carousel .item img{
		max-width:0px;
		min-height:0%;
	}/*
	#homepage .carousel .item {
		height:180px !important;
	}*/
}

@media (max-width: 1024px) and (min-width: 768px){
	#homepage .carousel .item {
		width: 100% !important;
		/*margin-top: 20px !important;*/
		height:396px !important;
	}
}

/*@media (min-width:992px) and (max-width:1363px){
	#homepage .carousel .item img {
		/* width: 100% !important; 
		margin-top: 15px !important;
		max-height: auto;
		max-height: 100%;
		min-height: 80%;
	}
}

@media (min-width:1024px) and (max-width:1255px){

}*/

@media (min-width: 1024px){
	#homepage .carousel .item img {
		/* width: 100% !important; */
		margin-top: 15px !important;
		max-height: auto;
		max-height: 100%;
		min-height: 80%;
	}
}
@media (max-width:1263px) and (min-width:1024px){
	#homepage .carousel .item{ height:500px !important; }
		
	#homepage .carousel .carousel-caption { 
		left: 100px; 
		top: 80px;
		width: 500px;
	}
}

@media (min-width:1264px) and (max-width:1363px){
	#homepage .carousel .item{ height:502px !important; }
		#homepage .carousel .carousel-caption { 
		left: 99px;
		top: 100px;
	}
}

@media (min-width:1364px) and (max-width:1641px){
	#homepage .carousel .item{ height:540px !important; }
	
	#homepage .carousel .carousel-caption { 
		left: 170px; 
		top: 120px;
		width: 500px;
	}
		#homepage .carousel .carousel-caption { 
		left: 170px; 
		top: 80px;
		width: 500px;
	}
}

@media (min-width:1642px){
	#homepage .carousel .item{ height:650px !important; }
	
	#homepage .carousel .carousel-caption { 
		left: 170px; 
		top: 120px;
		width: 500px;
	}
}
<div class="row carousel-inner padding-topImage">
						
<div class="row item myclass">

<img src="/Regal-en-us/cache/file/90A5069B-155D-0201-11BF135B13F69E9A_W1280_H500.jpg" alt="Real People, Real Solutions See how we've helped make a difference in the lives of our members.">
									
	<div class="container">
		<div class="carousel-caption carousel-caption1">
			<div>
			<div class="visible-xs"></div>
				<div class="hidden-xs"><h1 class="titleSlide"><br>
	Real People,<br>
	Real Solutions</h1>

<p class="content1">See how we’ve helped make a difference in the lives of our members.</p>

<p style="font-size: 12px; color: #ffffff;">&nbsp;</p>

<p><a class="btn btn-info1 styleText btn-primary" href="/index.cfm/doctor-finder/" role="button">Read More</a></p>
<!---<p style="font-size: 12px; color: #ffffff;">&nbsp;</p>

<p><a class="btn btn-info" href="/index.cfm/doctor-finder/" role="button">Read More</a></p>--->
													
													
	</div>
                                                
                                                
	</div>
		</div>
	</div>
									
	</div>
								
<div class="row item myclass">

	<img src="/Regal-en-us/cache/file/9CFFC7AA-155D-0201-119470C3C01460AE_W1280_H500.jpg" alt="Need an Urgent Care Center? There is one right in your neighborhood – and we will help you find it.">
									
<div class="container">
	<div class="carousel-caption carousel-caption1">
			<div>
		<div class="visible-xs"></div>
				<div class="hidden-xs"><h1 class="titleSlide"><br>
	<h1>Need an Urgent Care Center?</h1>

<p class="content1">There is one right in your neighborhood –<br>
	and we will help you find it.</p>

<div class="embeddedContent oembed-provider-">&nbsp;</div>
<!---<p style="font-size: 12px; color: #ffffff;">&nbsp;</p>

<p><a class="btn btn-info1 styleText" href="http://oc2-web03/index.cfm/doctor-finder/" role="button">Find an Urgent Care</a></p>---><!---<p style="font-size: 12px; color: #686868;">&nbsp;</p>--->

<p><a class="btn btn-info1 slideText btn-primary urgentButton" href="/index.cfm/urgent-care-finder/" role="button">Find an Urgent Care</a></p>
													
</div>
</div>
	</div>
	</div>
									
		</div>
								
	<div class="row item myclass active">

	<img src="/Regal-en-us/cache/file/9CFD4EC1-155D-0201-11C0E45BAE92654E_W1280_H500.jpg" alt="Looking for a Doctor? We have just the right one for you.">
									
	<div class="container">
	<div class="carousel-caption carousel-caption1">
	<div>
	<div class="visible-xs"></div>
		<div class="hidden-xs"><h1 class="titleSlide"><br>
	Looking for a doctor?</h1>

<p class="content1">We have just the right one for you.</p>
<!---<p style="font-size: 12px; color: #ffffff;">&nbsp;</p>

<p><a class="btn btn-info1 styleText" href="/index.cfm/doctor-finder/" role="button">Read More\\\</a></p>--->

<p style="font-size: 12px; color: #686868;">&nbsp;</p>

<p><a class="btn btn-info1 slideText btn-primary" href="/index.cfm/doctor-finder/" role="button">Find a Doctor Now</a></p>
													
													
</div>
                                                
                                                
</div>
	</div>
		</div>
									
	</div>
								
	<div class="row item myclass">

	<img src="/Regal-en-us/cache/file/22E66EFF-155D-0201-11F1D4090927E676_W1280_H500.jpg" alt="Snow Machines Run as Winter Winds Down">
									
										<div class="container">
											<div class="carousel-caption carousel-caption1">
											    <div>
												
												<div class="visible-xs"></div>
													<div class="hidden-xs"><p>Curabitur ut suscipit tellus. Maecenas rhoncus, ante vitae vehicula vestibulum, metus sapien dapibus tellus, et mattis dolor neque vitae nisl.</p>
													
													
												</div>
                                                
                                                
												</div>
											</div>
										</div>
									
								</div>
								
					</div>

由于高度固定,手机和平板电脑版本出现以下情况。我试图删除导致问题的元素类,但如前所述,它会使轮播消失

任何帮助将不胜感激 enter image description here

enter image description here

最佳答案

根据经验,您不应为任何轮播组件指定高度或将它们设置为 auto 导致拉伸(stretch)的原因是 [max/min]-height: 100 % 在这些组件中:

.carousel-inner {
   height:auto;
  }

.carousel .item {
    height: auto;
}

.carousel .item img {
    height:auto;

这个概念不仅仅适用于轮播。设计类时,保持高度不变或自动。

例如:

.give-me-the-bounty
{
    width: 100%;
    height:auto;
}

关于html - 手机和平板电脑的图像拉伸(stretch)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40347159/

相关文章:

html - 为什么这个 div 不居中?

css - 如何在两个div和button之间显示

css - 在弹出的 Lightbox 上获取压缩图像,删除 Fluid Layout.css 修复它。但是我两者都需要,我该如何解决冲突?

html - 如何使下拉导航栏变黑?

HTML 页面高度不占屏幕的全高

javascript - 使用没有嵌入 JS 或 CSS 的严格 javascript 隐藏和显示 DIV

javascript - Bootstrap 4 popper 未定义

javascript - 构建与移动设备/平板电脑兼容的 Web 应用程序的最佳实践是什么

html - Bootstrap 从一个网格大小列更改为另一个

html - 如何使div背景图像响应