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

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

问题描述

我的容器在浏览器中放大的背景图片出现问题.图片为1200px宽,我的容器也为1200px宽.我将其设置为我的.container选择器的背景图像.当我将其加载到浏览器中时,它仅显示图像的一小部分,因为它已被放大.为什么会这样?

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;
}

我想念什么吗?

推荐答案

您需要为背景图片指定其他一些属性,如下所示:

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天全站免登陆