首页
极刻
圈子
教程
开源
极客社区
写文章
发极刻
建圈子
发项目
登录 / 注册
返回教程:CSS3 教程
TRY RUN / 在线示例
CSS3 教程 居中
CSS3 教程 居中
源代码
运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>安科教程(www.ancii.com)</title> <style> .container { position: relative; } .center { position: absolute; left: 0; top: 50%; width: 100%; text-align: center; font-size: 18px; } img { width: 100%; height: auto; opacity: 0.3; } </style> </head> <body> <h2>图片文本</h2> <p>在图片中间位置添加文本信息:</p> <div class="container"> <img src="/statics/images/course/trolltunga.jpg" alt="Norway" width="1000" height="300"> <div class="center">居中</div> </div> </body> </html>
运行结果