CSS 如何实现让div的四个边框都有阴影的效果?

html-css013

CSS 如何实现让div的四个边框都有阴影的效果?,第1张

CSS 实现让div的四个边框都有阴影的效果:

首先:

HTML代码

<h1>CSS 如何实现让div的四个边框都有阴影的效果?</h1>

<div class="g1">

<div class="g2"></div>

</div>

CSS代码

body{background:#f00}

html{background:#f00}/*html加背景色*/

.g1{

width:500px

height:500px

border:2px solid #fff

margin:30px auto

background-color:#fff

box-sizing:border-box

}

.g2{

width:400px

height:400px

margin:50px auto

border:2px solid #000

box-shadow:5px 5px 5px #000,5px -5px 5px #000,-5px 5px 5px #000,-5px -5px 5px #000

}

具体效果:

指定的<table>为细边框,把<table>放在<div>中即可。

一、首先新建表格,代码如下:

<table width="500" border="1">  <tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr><tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr><tr>  <td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr</table>。

二、在table里加css样式,代码如下:

<table width="500" border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse">  <tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td </tr><tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></tr><tr><td>&nbsp</td><td>&nbsp</td><td>&nbsp</td></table>。

三、单元格边距(表格填充)(cellpadding) -- 代表单元格外面的一个距离,用于隔开单元格与单元格空间。单元格间距(表格间距)(cellspacing) -- 代表表格边框与单元格补白的距离,也是单元格补白之间的距离,border-collapse:collapse表示表格的两边框合并为一条即可。