Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a seamless pattern with CSS on the web [closed]

I am making a seamless CSS pattern on the web. I know this is totally nonsense and non-practical at all. But it is just for the sake of having fun.

http://codepen.io/vennsoh/pen/iFKyo

I have done creating my first tile. Now I am thinking of a way to repeat it to fill up the whole background.

Can I complete this feat by just using HTML and CSS? Or must I use javascript to complete this?

-

Here are my steps if using javascript, correct me or suggest better ways:

  1. Calculate current browser width and height.
  2. A single tile is (150x150), I will just need to create as many div(s) to cover the whole screen.

-

I might want to make things move around, each polygon changes color, etc. It won't be static. I am not looking for a background-image solution.

Thanks, Venn.

like image 232
Vennsoh Avatar asked Feb 05 '13 02:02

Vennsoh


People also ask

How do I stop a background image from repeating CSS?

To make a background image not repeat in HTML, specify no-repeat in the background-repeat property or the background shorthand property. The background image is set to 'no-repeat' using the 'background-repeat' property. The above example uses the background-repeat property to set the image to no-repeat .

How do I put a background image in HTML without repeating it?

To avoid the background image from repeating itself, set the background-repeat property to no-repeat .

How do you style a background in CSS?

CSS Syntax background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit; Note: If one of the properties in the shorthand declaration is the bg-size property, you must use a / (slash) to separate it from the bg-position property, e.g. background:url(smiley.

What is background-repeat in CSS?

The background-repeat CSS property sets how background images are repeated. A background image can be repeated along the horizontal and vertical axes, or not repeated at all.


2 Answers

Actually this is possible with only html and css. The problem in your example is that every part of background will overlap when you set background-repeat property because they have different size, so you just need to resize and position your shapes differently. The easy way to do this in your case is set one background-size for every shape (size of desired complete pattern) and change their position accordingly.

I've modified part of your example to give you an idea of how it should look like: http://codepen.io/anon/pen/pnxyd

like image 185
dimusic Avatar answered Oct 12 '22 11:10

dimusic


Just add,

float:left;

to the css, and then just make multiple copies of the div, just like here...http://codepen.io/anon/pen/rlDqh

I guess this should do the trick.

like image 38
Mohd Abdul Mujib Avatar answered Oct 12 '22 11:10

Mohd Abdul Mujib