css - 使用 CSS 创建方格背景

标签 css

为什么不能使用这样的东西创建方格背景?

background-color:#ccc;
background-image:linear-gradient(90deg, transparent 50%, #aaa 50%),
                 linear-gradient(90deg, #aaa 50%, #ccc 50%);
background-size:50px 50px,50px 50px;
background-position:0 0, 0 25px;

想法是在条纹正方形的底部叠加交替的颜色。它不起作用,但似乎应该起作用。

最佳答案

这是方格背景在图形设计编辑器(如 Photoshop 或 Illustrator)中的外观的精确复制品。 (所有 CSS)

.checkered{
    height: 240px;
    background: -webkit-linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), -webkit-linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), white;
    background: -moz-linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), -moz-linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), white;
    background: linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), linear-gradient(45deg, rgba(0, 0, 0, 0.0980392) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.0980392) 75%, rgba(0, 0, 0, 0.0980392) 0), white;
    background-repeat: repeat, repeat;
    background-position: 0px 0, 5px 5px;
    -webkit-transform-origin: 0 0 0;
    transform-origin: 0 0 0;
    -webkit-background-origin: padding-box, padding-box;
    background-origin: padding-box, padding-box;
    -webkit-background-clip: border-box, border-box;
    background-clip: border-box, border-box;
    -webkit-background-size: 10px 10px, 10px 10px;
    background-size: 10px 10px, 10px 10px;
    -webkit-box-shadow: none;
    box-shadow: none;
    text-shadow: none;
    -webkit-transition: none;
    -moz-transition: none;
    -o-transition: none;
    transition: none;
    -webkit-transform: scaleX(1) scaleY(1) scaleZ(1);
    transform: scaleX(1) scaleY(1) scaleZ(1);
}

你可以在我的笔中看到一个有效的例子here

关于css - 使用 CSS 创建方格背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277641/

相关文章:

javascript - 如何在鼠标悬停时将 CSS 类动态添加到表格行

css - 屏幕上的媒体查询拖动/调整大小不起作用

html - 字体粗细不适用于任何浏览器

javascript - 模态 Bootstrap 用户输入

php - 如何将所有 td 对齐到中心,除了 td with class

css - 是否可以将 ShinyWidgets 中 progressBar() 的颜色更改为自定义颜色?

html - 如何保证自定义滚动条?

html - 在 CSS 中/通过 CSS 处理图像和媒体的宽度和高度(设置高度 = 宽度的 200%)

具有等高列的 CSS Fluid-Fixed 布局

javascript - 对 'slideshow' 元素使用 CSS Sprite ?