dw如何为图片设置css样式

html-css012

dw如何为图片设置css样式,第1张

dw里怎样设置图片的css样式

1、首先在文件内插入一张图片,点击插入\图像,选择一张图片即可。

2、选中图像,点击css样式窗口的+号,新建一个CSS(相关课程推荐:css视频教程) 样式,打开对话框。选择标签元素,下面就自动变为img,就是说为图像编辑规则。

3、比如要为图片编辑边框,就在弹出的对话框中选择边框,有三个属性可以更改,一个是类型,大小和颜色。可以根据需要选择。

4、在右侧的css面板上就多了个边框属性,代码中多了个图像的css样式代码。图像就自动按照样式进行更改了。

5、如果要对该图像再进行修改,可以点击css样式窗口下的铅笔,在弹出的对话框中修改即可。

写个简单的例子给你吧

htlm如下:

<h4>图片水平居中</h4>

<div class="demo1">

<img src="你的图片" alt="">

</div>

<h4>图片垂直居中</h4>

<div class="demo2">

<div class="imgbox">

<img src="你的图片" alt="">

</div>

</div>

<h4>图片水平垂直居中</h4>

<div class="demo3">

<div class="imgbox">

<img src="你的图片" alt="">

</div>

</div>

css如下:

<style type="text/css">

.demo1{width: 200pxheight: 200pxborder: 1px solid #cccdisplay: inline-blocktext-align: center}

.demo1 img{width: 100pxheight: auto}

.demo2{width: 200pxheight: 200pxborder: 1px solid #cccdisplay: table}

.demo2 .imgbox{display: table-cellvertical-align: middle}

.demo2 .imgbox img{width: 100pxheight: auto}

.demo3{width: 200pxheight: 200pxborder: 1px solid #cccdisplay: table}

.demo3 .imgbox{display: table-cellvertical-align: middletext-align: center}

.demo3 .imgbox img{width: 100pxheight: auto}

</style>

为img标签加一个id或class就好啦,这样就可以自由的选择要编辑css的图片了。

class例子:<img class="one" src="#" />

在css中则这样选择

.one{ width:100px height:300px float:left}

id例子:<img id="two" src="#" />

#two{width:200px height:200px float:left}