为什么我的容器背景图像被放大了? [英] Why is my container background image so zoomed in?

查看:31
本文介绍了为什么我的容器背景图像被放大了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在浏览器上放大容器的背景图像时遇到问题.图片是 1200px 宽,我的容器也是 1200px 宽.我将它设置为我的 .container 选择器的背景图像.当我在浏览器中加载它时,它只显示图像的一小部分,因为它到目前为止已经放大了.为什么会发生这种情况?

HTML:

<html lang="zh-cn"><头><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link type="text/css" rel="stylesheet" href="css/bootstrap.min.css"><link type="text/css" rel="stylesheet" href="style.css"><身体><主要角色=主要"><文章角色=文章"><部分><标题><div class="容器">

</标题></节></文章></main>

CSS:

@font-face {字体系列:布兰登怪诞";src: url("字体/Brandon_Grotesque/Brandon_reg.otf")格式(开放类型");}html,正文{填充:0;边距:0;背景色:#222222;}身体 {字体系列:布兰登怪诞";宽度:1200px;边距:0 自动;}.容器 {宽度:1200px;高度:600px;背景图片:网址(img/background.jpg");文字对齐:居中;保证金:自动;填充:0;}

我错过了什么吗?

解决方案

您需要为您的背景图像指定更多属性,如下所示:

.container {宽度:1200px;高度:600px;背景图片:url("img/background.jpg");背景尺寸:封面;/* 或包含取决于你想要的 */背景位置:居中;背景重复:不重复;文字对齐:居中;保证金:自动;填充:0;}

I am having an issue with my background image of a container being zoomed in on the browser. The picture is 1200px wide and my container is also 1200px wide. I have it set as the background-image for my .container selector. When I load it in the browser it is only showing a small portion of the image because it is zoomed in so far. Why is this happening?

HTML:

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="style.css">
</head>
<body>
<main role="main">
<article role="article">
<section>
<header>
<div class="container">

</div>   
</header>
</section>    
</article>
</main>
</body>
</html>

CSS:

@font-face {
  font-family: "Brandon Grotesque";
  src: url("fonts/Brandon_Grotesque/Brandon_reg.otf")
  format("opentype");
}

html, body {
  padding:0;
  margin: 0;
  background-color:#222222;
}

body {
  font-family:"Brandon Grotesque";
  width: 1200px;
  margin: 0 auto;
}

.container {
  width: 1200px;
  height:600px;
  background-image:url("img/background.jpg");
  text-align:center;
  margin:auto;
  padding:0;
}

Am I missing anything?

解决方案

You need to specify a few more properties for your background-image like this:

.container {
  width: 1200px;
  height:600px;
  background-image: url("img/background.jpg");
  background-size: cover; /* or contain depending on what you want */
  background-position: center center;
  background-repeat: no-repeat;
  text-align:center;
  margin:auto;
  padding:0;
}

这篇关于为什么我的容器背景图像被放大了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆