html中div布局及其图片插入链接

2025-09-27 08:04:07

1、打开软件,新建html文件,如图,分析图片的构成部分,是由五张图片,五行字组成。建立五个div布局,每个div包含一张图片一段字。字和图片都有超链接

html中div布局及其图片插入链接

2、建立一个div包含五张图片,设置属性margin :0 auto;上下边界为0,左右相等。建立div5个,放置图片和字。

*{padding: 0;margin: 0;}

.news{width: 1080px;height: 200px;margin: 0 auto;}

html中div布局及其图片插入链接

3、.left_1{width: 200px;height: 150px;float: left;padding: 10px;}

.left_2{width: 200px;height: 150px;float: left;margin-top: 10px;}

.center{width: 200px;height: 150px;float: left;padding: 10px;}

.right_1{width: 200px;height: 150px;float: left;margin-top: 10px;}

.right_2{width: 200px;height: 150px;float: left;padding: 10px;}

html中div布局及其图片插入链接

4、给图片添加超链接

<div class="left_1">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a.jpg"height="150

   <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="left_2">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a1.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="center">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a3.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="right_1">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/day02.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="right_2">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/qiu.gif"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

html中div布局及其图片插入链接

5、图片和字都加超链接。运行看一下效果。

html中div布局及其图片插入链接

6、<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<style>

*{padding: 0;margin: 0;}

.news{width: 1080px;height: 200px;margin: 0 auto;}

.left_1{width: 200px;height: 150px;float: left;padding: 10px;}

.left_2{width: 200px;height: 150px;float: left;margin-top: 10px;}

.center{width: 200px;height: 150px;float: left;padding: 10px;}

.right_1{width: 200px;height: 150px;float: left;margin-top: 10px;}

.right_2{width: 200px;height: 150px;float: left;padding: 10px;}

a{ display: block; text-align: center;}

a:hover{color:#00FF00;text-decoration: underline;}

</style>

</head>

<body>

<div class="news">

<div class="left_1">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a.jpg"height="150

   <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="left_2">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a1.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="center">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/a3.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="right_1">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/day02.jpg"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

<div class="right_2">

<a href="http://news.baidu.com/" target="_blank"><img src="../img/qiu.gif"height="150

    <a href="baidu.com" target="_blank">图片链接</a>

</div>

</div>

</body>

</html>

所有代码,细节自行添加

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢