The implementation of lattice style in CSS

Source: Internet
Author: User

Final results come out, Csapp finally did not hang, can have a good year!

Well, this time the demand is like this:

, in the parent box into the child box, the width of the child box is 50% (33%, 25% similar), so that the appearance of the above effect, seemingly simple, in fact, there are some cumbersome, specific code for

. Box{width:400px;height:400px;padding:5px;background-color: #CCC; border-radius:10px;}. block{float:left;width:50%;height:50%;border:5px solid #ccc; box-sizing:border-box;border-radius:7%; Background-color: #685473;}

The tips to use are:

1. Child elements using the Border-box model

2. Set floating for child elements

3. The spacing between the child elements is border with the same color as the parent element background color (because the width of the various box models does not include margin, using margin will make a row up to two boxes)

4. Parent element plus padding with the same width as child elements (if not added, there is 10px gray between child elements, but the edges adjacent to the parent element are only 5px gray, not beautiful)

This effect is useful when making some lattice games (see, 2048), etc.

The implementation of lattice style in CSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.