如何防止背景图像在模态模式下放大?

huangapple go评论72阅读模式
英文:

How do I prevent the image in the background from zooming in modal mode?

问题

我有4张图片和一张背景图,为每张图片都编写了一个模态框。当我点击图片并以模态框模式打开它时,背景图也会稍微放大。在Chrome开发工具中,我看到一个新的类被添加到body元素中,名为.modal-open,同时在CSS中添加了属性和值。

body.modal-open {
  padding-right: 16px;
  display: block;
}

.modal-open .modal {
  overflow-x: hidden;
  overflow-y: auto;
}

如何防止body元素背景中的图片放大?

JsFiddle链接

英文:

I have 4 pictures and a background image and I wrote a modal for each of them. When I click on the image and it opens in modal mode, the background image also zooms in a bit. In chrome dev tools, I see that a new class is added to body called .modal-open and properties and values are added in the css.

body.modal-open {
padding-right: 16px;
display: block; }


.modal-open .modal {
overflow-x: hidden;
overflow-y: auto; }

Link to Js fiddle

How do I prevent the image in the background of the body element from zooming in?

答案1

得分: 0

CSS

.bg-image {
    background-image: url("Pictures/English-lang-background.jpg");
    background-size: cover;
    overflow: auto;
}

HTML

<body>
    <div class="bg-image">
    </div>
</body>

Correct, @iamwhitebox. It solves the problem.

英文:

CSS

.bg-image {
    background-image: url(&quot;Pictures/English-lang-background.jpg&quot;);
    background-size: cover;
    overflow: auto;
}

HTML

&lt;body&gt;
&lt;div class=&quot;bg-image&quot;&gt;

&lt;/div&gt;
&lt;/body&gt;

Correct, @iamwhitebox. It solves the problem.

huangapple
  • 本文由 发表于 2020年1月4日 01:55:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59583148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定