zoukankan      html  css  js  c++  java
  • n宫格的实现方法

    方法一、table#

    1、看成多列##

    <style>
        .line{	display: table;	 1024px;
                    clear:both;	overflow:auto; 	/*-----设置父div高度包住子div高度*/}
        .news{	display: table-row;	float: left;	background-color:#236483;}
    
        .news img,.news-txt{	float:left;	display: table-cell;	height: 150px;
    			 100%;	font-size: 1.5em;	text-align: center;}
    
    <html>
    	<div class="line">
    	<!-- 第一列 -->
    		<div class="news">
    		<!-- 第一格 -->
    			<img src="img/news.jpg"><div class="news-txt">a</div>
    		<!-- 第二格 -->		
    			<img src="img/news.jpg"><div class="news-txt">b	</div>
    		</div>
    
    	<!-- 第二列 -->
    		<div class="news">
    		<!-- 第一格 -->	<div class="news-txt">a</div>	<img src="img/news.jpg">
    
    		<!-- 第二格 -->	<div class="news-txt">b</div>	<img src="img/news.jpg">
    		</div>
    
    	</div>
    

    2、看成多行##

    <style>
        .line{	display: table;	 1024px;
                    clear:both;	overflow:auto; 	/*-----设置父div高度包住子div高度*/}
    
        .news{	display: table-row;		float: left;		background-color:#236483;}
    
        .news img,.news-txt{	float:left;	display: table-cell;	height: 150px;
    			 25%;	font-size: 1.5em;	text-align: center;}
    
    <html>
    	<div class="line">
    	<!-- 第一行 -->		
                    <div class="news">
    		<!-- 第一格 -->
    			<img src="img/news.jpg"><div class="news-txt">    a	</div>
    		<!-- 第二格 -->
    			<img src="img/news.jpg"><div class="news-txt">    b	</div>
    		</div>
    	<!-- 第二行 -->
    		<div class="news">
    		<!-- 第一格 -->
    			<div class="news-txt">    c	</div>
    			<img src="img/news.jpg">
    		<!-- 第二格 -->
    			<div class="news-txt">    d    </div>
    			<img src="img/news.jpg">
    		</div>
    	</div>
    

    总结:
    1、优点table-cell单元格高度取其所在行l单元格高度的最大值,高度统一
    2、缺点:①ie6/7兼容性不好, ②后台输出时需要水平、垂直各repeat

    方法二、inline-block#

    <style>
        .line{	display: table;	 1024px;
                    clear:both;	overflow:auto; 	/*-----设置父div高度包住子div高度*/}
        .news{	display: table-row;	float: left;	background-color:#236483;}
    
        .news img,.news-txt{	float:left;	display: inline-block;	height: 150px;
    			 100%;	font-size: 1.5em;	text-align: center;}
    

    区别:display: inline-block
    其余相同

    优点:①可与文字,图片混排,可内嵌block属性元素,可以可以置身于inline水平的元素中;②所在行高取单元格最高值
    ③ie6/7虽然不支持display,但让其表现的跟inline-block一样

  • 相关阅读:
    7、单向一对多的关联关系(1的一方有n的一方的集合属性,n的一方却没有1的一方的引用)
    6、JPA_映射单向多对一的关联关系(n的一方有1的引用,1的一方没有n的集合属性)
    解决ubuntu的screen已经处于Attached状态,无法再打开窗口
    关于.ssh出错,无法从远程git仓库拉代码
    给程序添加git commit信息
    ubuntu服务器常用命令
    uint128_t 添加 c++ 重载类型强制转换
    Visual Studio 查看宏展开
    EOS dice移到1.8版本的修改汇总
    ubuntu 添加字体
  • 原文地址:https://www.cnblogs.com/KarmaDeng/p/7250508.html
Copyright © 2011-2022 走看看