css 实现九宫格
1.自己写了一个,写完对比了下别人写的发现自己写的太low.故就不写自己太差劲的了。
别人写的我总结优化了一下,如果不用写内容去掉position,content简单也是可以的。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
.box-wrap {
text-align: center;
background-color: #d4d4f5;
border:1px solid #FF0000;
overflow: hidden; /*为了清除浮动*/
}
.box-wrap>div {
width: 31.33%;
padding-bottom: 31.33%;/*是父级元素的宽度的百分比*/
margin:1%;
border-radius: 10%;
float: left;
background-color: orange;
position:relative;
}
.content {
position:absolute;
width:100%;
height:100%;
border-radius: 10%;
}
</style>
</head> <body>
<div class="box-wrap">
<div class="box">
<div class="content">格子1</div>
</div>
<div class="box">
<div class="content">格子2</div>
</div>
<div class="box">
<div class="content">格子3</div>
</div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</body>
</html>
2.也可以使用伪元素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style>
.box-wrap {
text-align: center;
background-color: #d4d4f5;
border:1px solid #FF0000;
overflow: hidden; /*为了清除浮动*/
}
.box-wrap>div {
width: 31.33%;
padding-bottom: 31.33%;/*是父级元素的宽度的百分比*/
margin:1%;
border-radius: 10%;
float: left;
background-color: orange;
position:relative;
}
.box:after {
position:absolute;
content:"格子";
display:block;
width:100%;
height:100%;
border-radius: 10%;
}
</style>
</head> <body>
<div class="box-wrap">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</body>
</html>
css 实现九宫格的更多相关文章
- css实现九宫格
原理:浮动+margin负边距 示例代码: <!DOCTYPE html> <html lang="zh"> <head> <meta c ...
- 纯CSS写九宫格样式,高宽自适应正方形
<!DOCTYPE html><html> <head> <meta charset="utf-8"> ...
- 利用div+css实现九宫格,然后用js实现点击每个格子可以随机更改格子(div)的背景颜色
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- css实现九宫格图片自适应布局
我之前写九宫格自适应布局的时候,每个格子是使用媒体查询器(@media)或者js动态设置css,根据不同的手机屏幕宽度,适配不同手机,但是这样有个很大的缺点,那就是移动端的屏幕尺寸太多了,就得写很多代 ...
- css布局 - 九宫格布局的方法汇总(更新中...)
目录: margin负值实现 祖父和亲爹的里应外合 换个思路 - li生了儿子帮大忙. 借助absolute方位值,实现自适应的网格布局 cloumn多栏布局 grid display: table: ...
- table 实现 九宫格布局
九宫格布局 最近遇到一个题目,是实现一个九宫格布局的.实现的效果大概是下图这种这样子的: (鼠标悬浮的时候,九宫格的边框颜色是改变的.) 首先想到的是直接使用<table>进行布局,原因很 ...
- 【消灭代办】第2周 - 数组判断、开发工具、transform:matrix、Grid
2018.11.19代办一:[数组判断] 代办描述: 怎么判断一个数组是数组呢?其实这个也是一个常考的题目 关键考点: 1.js中对象类型判断的几种方法 2.数组的知识和灵活运用 解决方案s: 篇幅过 ...
- sencha touch Container
Container控件是我们在实际开发中最常用的控件,大部分视图控件都是继承于Container控件,了解此控件能帮我们更好的了解sencha touch. layout是一个很重要的属性,能够帮助你 ...
- Matplotlib数据可视化(3):文本与轴
在一幅图表中,文本.坐标轴和图像的是信息传递的核心,对着三者的设置是作图这最为关心的内容,在上一篇博客中虽然列举了一些设置方法,但没有进行深入介绍,本文以围绕如何对文本和坐标轴进行设置展开(对图像 ...
随机推荐
- linux一些基本操作-防火墙操作
防火墙操作 一.service方式 查看防火墙状态: [root@centos6 ~]# service iptables status iptables:未运行防火墙. 开启防火墙: [root@c ...
- 蒲公英Ghost Win 7 Sp1(x86/x64)旗舰版 201910
蒲公英Ghost Win 7 Sp1(x86/x64)旗舰版 201910 <ignore_js_op> <ignore_js_op> <ignore_js_op> ...
- 整合SSM遇到的错误,数据库连接失败问题集合
Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be a ...
- 吴裕雄--天生自然HTML学习笔记:HTML 统一资源定位器(Uniform Resource Locators)
URL 是一个网页地址. URL可以由字母组成,如"runoob.com",或互联网协议(IP)地址: 192.68.20.50.大多数人进入网站使用网站域名来访问,因为 名字比数 ...
- python jQuery筛选器
筛选器:$(this).next() 下一个 $(this).prev 上一个 $(this).parent() 父 $(this).children() 孩 $(th ...
- GYOJ_1812_股票(stock)
题目描述 2130年,股神巴菲特投胎了!他投胎到你身上! 你作为股神转世,能力比原股神还要强,你可以预测到今后n天的股价.假设刚开始你的手上有1元钱,你想知道n天后你最多可以赚到多少钱.作为股神转世, ...
- 爬虫入门-使用python写简单爬虫
从第一章到上一章为止,基本把python所有的基础点都已经包括了,我们有控制逻辑的关键字,有内置数据结构,有用于工程需要的函数和模块,又有了标准库和第三方库,可以写正规的程序了. python可以做非 ...
- IP地址0.0.0.0表示什么
参考RFC文档: 0.0.0.0/8 - Addresses in this block refer to source hosts on "this"network. Addre ...
- 是AI就躲个飞机-纯Python实现人工智能
你要的答案或许都在这里:小鹏的博客目录 代码下载:Here. 很久以前微信流行过一个小游戏:打飞机,这个游戏简单又无聊.在2017年来临之际,我就实现一个超级弱智的人工智能(AI),这货可以躲避从屏幕 ...
- 【转载】(String)、toString、String.valueOf的区别
用于个人参考,查看请前往原地址http://blog.csdn.net/springk/article/details/6414017 问题讨论http://bbs.csdn.net/topics/2 ...