【问题标题】:How do I get my image header to resize? It's cut off on mobile but looks fine on desktop如何让我的图像标题调整大小?它在移动设备上被切断,但在桌面上看起来不错
【发布时间】:2016-08-10 10:38:13
【问题描述】:

我正在寻找一些 CSS 帮助。我正在我教会的网站上工作,我正在尝试获取我所谓的响应主题的移动版本来调整标题图像的大小。现在标题图像似乎没有调整大小,或者至少没有完全调整。

网址:http://www.rochestertrinity.com/kids.html

我希望得到的是将标题图像缩放到显示尺寸的确切宽度。所以在桌面上看起来基本上是一样的,但在移动设备上,用户会看到整个标题图像。我附上了一张我现在看到的和我想看到的模拟图像。

image of what I see vs what I'd like

我不是 CSS 专家,但我怀疑管理此问题的代码位于以下 sn-ps 之一中:

/* Tall Header Page */
.tall-header-page .banner-wrap {
  display: table;
  width: 100%;
  min-height: 450px;
  padding-top: 50px;
  text-align: center;
}
.tall-header-page .banner-wrap .container {
  height: 450px;
}
.tall-header-page .banner-wrap .banner h2 {
  font-size: 70px;
  padding-top: 65px;
}

或

/* Banner */
.banner-wrap {
  position: relative;
  max-width: 100%;
  height: auto;
  padding: 55px 0;
  box-sizing: border-box;
  background: #ffffff url('default-bg.jpg') center center no-repeat;
  background-size: cover;
}
.banner-wrap:before {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 100%;
  height: auto;
  background: rgba(0, 0, 0, 0);
  content: ' ';
}
.banner-wrap .container {
  display: table;
  overflow-y: hidden;
  height: 100%;
}
.banner-wrap .banner {
  position: relative;
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}
.banner-wrap .banner h2 {
  padding-bottom: 30px;
  color: #ffffff;
  word-spacing: .1em;
  text-transform: uppercase;
  font-family: 'Fjalla One', sans-serif;
  font-size: 100px;
  font-weight: normal;
  line-height: 1.1em;
}
.banner-wrap .banner p {
  padding-bottom: 40px;
  color: #ffffff;
  letter-spacing: .03em;
  text-transform: uppercase;
  font-family: 'Lato', sans-serif;
  font-size: 24px;
  font-weight: normal;
  line-height: 1.4em;
}
.banner-wrap .banner .button-wrap {
  display: inline-block;
}
.banner-wrap .banner .wsite-button {
  text-align: center !important;
}
.banner-wrap .banner .wsite-button .wsite-button-inner {
  background: #ff8345;
  color: #ffffff !important;
}
.banner-wrap .banner .wsite-button:hover .wsite-button-inner {
  background: #e56525;
}

我希望有人可以提供帮助。

谢谢!

2016 年 4 月 22 日更新

tall-header.html 代码:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>

<body class='tall-header-page  wsite-theme-light'>

  <div class="wrapper">
	  <div class="paris-header">
      <div class="container">
      	<label class="hamburger"><span></span></label>
      	<div class="logo">{logo}</div>
        <div class="nav desktop-nav">{menu}</div>
      </div><!-- end .container -->
	  </div><!-- end .header -->  
	        
		<div class="banner-wrap wsite-background">
			<div class="container">
				<div class="banner">
					<h2>{headline:text global="false"}</h2>
					<p>{headline-paragraph:text global="false"}</p>	
				</div>
			</div>
		</div>


		<div class="main-wrap">
	    <div class="container">
	 			<div class="content-wrap">{content}</div>
	  	</div><!-- end container -->
	  </div>

    <div class="footer-wrap">
    	<div class="container">
    		<div class="footer">{footer}</div>
    	</div><!-- end container -->
    </div><!-- end footer-wrap -->
	</div>

    <div class="nav mobile-nav">
        <label class="hamburger"><span></span></label>
        {menu}
    </div>

	<script type="text/javascript" src="/files/theme/plugins.js"></script>
	<script type="text/javascript" src="/files/theme/custom.js"></script>
</body>
</html>

【问题讨论】:

    标签: css background banner image-size responsive


    【解决方案1】:

    在你的 kids.html 中你有这个,它会覆盖你的 CSS 代码:

    <style>
    .wsite-background {background-image: url("//cdn1.editmysite.com/uploads/6/5/4/8/65485229/background-images/2036811843.jpg") !important;background-repeat: no-repeat !important;background-position: 50.00% 37.71% !important;background-size: 100% !important;background-color: transparent !important;}
    body.wsite-background {background-attachment: fixed !important;}.wsite-background.wsite-custom-background{ background-size: cover !important}
    </style>
    

    删除或更改这部分代码就可以了:

    .wsite-background.wsite-custom-background {
        background-size: cover !important;
    }
    

    在您的 CSS 文件中,您有以下媒体查询: 媒体查询说明:http://www.w3schools.com/cssref/css3_pr_mediaquery.asp

    @media screen and (max-width: 992px) {
    

    在你的媒体查询中写下这行代码:

    .banner-wrap.wsite-background.wsite-custom-background{ background-size: 100% 100% !important; }
    

    它并不完美,另一个解决方案应该是这样,然后你必须改变元素的高度:

    .banner-wrap.wsite-background.wsite-custom-background{ background-size: 100% auto !important; }
    

    或者这个:

    .banner-wrap.wsite-background.wsite-custom-background{ background-size: contain !important; }
    

    背景尺寸说明:http://www.w3schools.com/css/css3_backgrounds.asp

    【讨论】:

    • 谢谢 - 不幸的是,Weebly 要么动态生成 kids.html 文件,要么阻止用户对其进行编辑。我在要编辑的可用文件列表中没有看到它。 :-/
    • 谢谢。 “100% 自动”是关于我所追求的。但是,正如我所料,它正在全局应用更改 - 到具有横幅的每个页面。我不希望它在我的登陆页面上这样做。有没有办法将其限制为某种类型的页面?高大的标题页? kids.html 是一个高标题类型的页面。我附上了 tall-header.html 代码。
    • 如果你可以访问 html 代码,你可以在你的 html 代码中添加一个类到你想要改变的 html 文件中的元素,像这样:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 2014-09-30
    相关资源
    最近更新 更多