如何使用CSS将表格定位至背景图上 调整边距未生效 需满足最大宽度700px
布局定位问题
需要将页面中的一组表格向上移动位置,之前尝试调整CSS边距参数,始终无法实现预期效果。
- 当前实现效果:

- 预期达成效果:

约束条件:页面最大宽度固定为700px,其余布局配置已全部完成,仅需解决带图片的表格上移、叠加在背景图上的定位问题,对应的代码如下:
现有CSS代码
@charset "UTF-8"; /* CSS Document */ body { margin-top: 0; padding-top: 0; background: #fff; /* 容器最大宽度限制 */ max-width: 700px; text-align: left; margin-left: auto; margin-right: auto; } .background-pic { background-image: url("Image Background.png"); height: 450px; background-position: center; background-repeat: no-repeat; background-size: cover; margin-bottom: -100px; max-width: 700px; } h1 { padding-top: 50px; text-align: center; font-family: "bebas-neue"; font-weight: normal; font-size: 50px; color: #fff; } .col-welcome-1 { float: left; margin-left: 25px; } .col-navmenu-1 { float: right; width: 250px; height: 255px; margin-right: 25px; border-radius: 10px; background: #252525; } h2 { color: #FFFFFF; text-align: center; font-weight: 200; font-size: 24px; font-family: Gotham, "Helvetica Neue", Arial, "sans-serif"; } .navbuttons { padding-left: 45px; } #footer { clear: both; text-align: left; padding: 0 12px 2px 12px; background: #eee; border-top: 1px solid #502e74; } .redline { border-bottom-style: solid; border-bottom-color: #502e74; border-bottom-width: 1px; } table { border-spacing: 0px; } th, td { padding-left: 5px; padding-right: 5px; padding-top: 0px; padding-bottom: 0px; } a:link {color: #502e74} a:visited {color: #036} a:active {color: #502e74} a:hover {color: #000; background: #ffc; text-decoration: none} /* 小屏适配规则:屏幕宽度小于600px时隐藏非首项导航,显示菜单按钮 */ @media screen and (max-width: 600px) { .topnav a:not(:first-child) {display: none;} .topnav a.icon { float: right; display: block; } } /* 小屏响应式导航布局规则 */ @media screen and (max-width: 600px) { .topnav.responsive {position: relative;} .topnav.responsive a.icon { position: absolute; right: 0; top: 0; } .topnav.responsive a { float: none; display: block; text-align: left; } }
现有HTML代码
<!DOCTYPE html PUBLIC> <html lang="zh-CN"> <link href="Professional Development Getting Started Template Style.css" rel="stylesheet" type="text/css"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <link rel="stylesheet" href="站内字体引入地址"> <title>职业发展概览模板</title> </head> <body> <div class="main-content"> <div id= "banner"> <div class="background-pic"> <h1>职业发展<br>概览</h1> </div> <table style="margin-left:auto; margin-right: auto; padding-bottom: 25px;"> <tbody> <tr> <td> <div class="col-welcome-1"> <a href="#"> <img src="Welcome Video.png" alt="欢迎视频" class="rounded" width="320" height="255"> </a> </div> </td> <td> <div class="col-navmenu-1"> <blockquote> <h2>导航栏</h2> </blockquote> <div class= "navbuttons"> <a href="#" target="_blank"> <img src="How to Navigate button.png" alt="导航操作引导" class="rounded" width="175" height="45"> </a> <a href="#" target="_blank"> <img src="track my progres button.png" alt="进度追踪" class="rounded" width="175" height="45"> </a> <a href="#" target="_blank"> <img src="faq button.png" alt="常见问题" class="rounded" width="175" height="45"> </a> <a href="#" target="_blank"> <img src="access modules button.png" alt="模块入口" class="rounded" width="175" height="45"> </a> </div> </div> </td> </tr> </tbody> </table> </div> </div> <div class="resource-content"> <table style="margin-left:auto; margin-right: auto;"> <tbody> <tr> <td> <div class="col-resource-1"> <a href="#" target="_blank"> <img src="FightforFreedom.png" alt="公益项目介绍" class="rounded" width="165" height="97"> </a> </div> </td> <td> <div class="col-resource-2"> <a href="#" target="_blank"> <img src="TNU Graduate Programs.png" alt="院校研究生项目介绍" class="rounded" width="165" height="97"> </a> </div> </td> <td> <div class="col-resource-2"> <a href="#" target="_blank"> <img src="Trevecca's Master's in Organizational Leadership Program.png" alt="组织领导力硕士项目介绍" class="rounded" width="165" height="97"> </a> </div> </td> </tr> </tbody> </table> </div> <div id="footer"> <p class="xsmall"><strong>特里维卡纳扎雷恩大学</strong></p> <p class="xsmall">技术支持联系方式: <a href="#" target="_blank">在线课程技术支持站点</a> </p> </div> </body> </html>
内容的提问来源于stack exchange,提问作者Mara Hogan
相关产品推荐
相关产品推荐

