简体   繁体   English

如何在CSS中制作1个图像图块?

[英]How to make 1 image tile in css?

How can I make it so that a 100 by 100 image repeats itself all throughout the webpage. 我如何才能使100 x 100的图像在整个网页中重复出现。 I want the image to duplicate itself and fill the screen. 我希望图像能够自我复制并填充屏幕。

for example lets say I had this picture: 例如说我有这张照片:

and I wanted it to look like this: 我希望它看起来像这样:

The spacing doesn't matter, but how would I do this? 间距无关紧要,但是我该怎么做呢?

You would use a repeating background image in CSS. 您将在CSS中使用重复的背景图片。 Then you can control the size of the image with background-size . 然后,您可以使用background-size控制图像background-size

body {
    background: url('https://i.stack.imgur.com/LtCRM.png') center center repeat;
    background-size: 2em;
}

CodePen: http://codepen.io/oculusriff/pen/VmZdzg CodePen: http ://codepen.io/oculusriff/pen/VmZdzg

Edit: As per nicovank's comment - if you are new to CSS, here is the separated version of the above code. 编辑:根据nicovank的评论-如果您是CSS的新手,这里是上述代码的单独版本。

body {
    background-image: url('https://i.stack.imgur.com/LtCRM.png');
    background-position: center center;
    background-repeat: repeat;
    background-size: 4em;
}

This is the closest I got to what I wanted. 这是我最想要的。 Sorry for not wording the question right. 很抱歉没有正确地表达问题。

https://codepen.io/anon/pen/ZBzRaX https://codepen.io/anon/pen/ZBzRaX

I don't know what is making it repeat, but I think it's this. 我不知道是什么使它重复,但是我想就是这样。 Now I just have to figure out how to make the button fit the whole screen. 现在,我只需要弄清楚如何使按钮适合整个屏幕。 The button is only a sliver at the top right now. 该按钮现在只是顶部的一个小条。

document.body.style.background = "url('"+links[i]+"')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM