CSS 布局问题 - DIV & Floats



我的布局有几个错误,想知道是否有人可以帮助我。 我需要删除导航栏上方和页脚下方的空白区域。其次,我希望所有页脚元素都在同一行上,而不是稍微交错。 我附上了该网站的图片,以及随之而来的HTML和CSS。 提前感谢!

.HTML:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>21st Century Dad</title>
<link type="text/css" rel="stylesheet" href="css/reset.css" />
<link type="text/css" rel="stylesheet" href="styles.css" />
<link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
<style type="text/css">
    #mc_embed_signup{background:#26ADE4; float:right; font:14px 'Kanit',Helvetica,Arial,sans-serif; margin-right: 20px; margin-top: 20px; text-align:center; padding:10px; border-radius:20px;}
    /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
</head>
<body>
<header>
    <div id="header-content">
        <img src="../website/images/logo-big.png" alt="21st Century Dad" height="110" style="margin-left:20px; margin-top:20px;" /> 
<!-- Begin MailChimp Signup Form -->
<div id="mc_embed_signup">
<form action="//fb.us15.list-manage.com/subscribe/post?u=48be460d4492dcbdd2828666e&amp;id=f7d2ed069d" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
Sign up for our newsletter!
<div class="indicates-required"><span class="asterisk"></span></div>
<div class="mc-field-group">
    <label for="mce-EMAIL">Email Address  <span class="asterisk">*</span>
</label>
    <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
</div>
    <div id="mce-responses" class="clear">
        <div class="response" id="mce-error-response" style="display:none"></div>
        <div class="response" id="mce-success-response" style="display:none"></div>
    </div>    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_48be460d4492dcbdd2828666e_f7d2ed069d" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" style="background-color:#D1E751; font:14px 'Kanit',Helvetica,Arial,sans-serif; margin-top:4px; border-radius:5px; border-color:#D1E751;"></div>
    </div>
</form>
</div>
<!--End mc_embed_signup-->
<nav>
<ul>
    <li><a href="#">About</a></li>
    <li><a href="#">DIY Projects</a></li>
    <li><a href="#">Dad Tech</a></li>
    <li><a href="#">Kid Stuff</a></li>
    <li><a href="#">Ask a Dad</a></li>
    <li><a href="#">Dad Jokes</a></li>
</ul>
</nav>
</div>
</header>
<div id="wrapper">
<main>
<div class = "container">
<div class = "blocks">
<h1>What's New with Dad?</h1>
<img src="../website/images/whatsnew.png" alt="About Me Picture" style="border:1px solid #000;">
</div>
<div class = "blocks">
<h1>DIY Project of the Week</h1>
<img src="../website/images/diyproject.jpg" alt="DIY Project Picture" style="border:1px solid #000;">
</div>
<div class = "blocks">
<h1>Dad Gadget of the Week</h1>
<img src="../website/images/dadgadget.jpg" alt="Dad Gadget of the Week Picture" style="border:1px solid #000;">
</div>
<div class = "blocks">
<h1>Activity / Meal of the Week</h1>
<img src="../website/images/dadactivity.jpg" alt="Kid Activity & Meal of the Week" style="border:1px solid #000;">
</div>
<div class = "blocks">
<h1>Dad Q & A of the Week</h1>
<img src="../website/images/askadad.png" alt="Dad Q & A of the Week" style="border:1px solid #000;">
</div>
<div class = "blocks">
<h1>Dad Joke of the Week</h1>
<img src="../website/images/dadjokes.jpg" alt="Dad Joke of the Week" style="border:1px solid #000;">
</div>
</div><!-- end container -->

</main>
<footer>  
<div id="footer">
         <p class="left">
        21stcenturydad@gmail.com
        <p class="right">
        <a href="https://www.facebook.com/"> 
        <img src="../website/images/Facebook.png" alt="Facebook Logo"/></a>
        <a href="https://www.snapchat.com/"> 
        <img src="../website/images/Snapchat.png" alt="Snapchat Logo"/></a>
        <a href="https://www.instagram.com/"> 
        <img src="../website/images/Instagram.png" alt="Instagram Logo"/></a>
         <p class="centered">
        &copy; Copyright 2017 21st Century Dad
</div>
</footer>

</div>
</body>
</html>

.CSS:

@charset "UTF-8";
/* CSS Document */
@import url('https://fonts.googleapis.com/css?family=Kanit:200,300,500');
body {
    background-color: #FFF;
    background-image:url(../website/images/background.png);
    font-size: 13px;
    font-family: 'Kanit', sans-serif;
    font-weight: 200;
    color: #363636;
}
p {
    line-height: 140%;
}
header {
    background-color: #D1E751;
    width: 960px;
    z-index:1000;
    margin-right:auto;
    margin-left:auto;
}
#header-content {
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    height: 130px;
    position:relative;
    left:0px;
    top:0px;
}
nav {
    background-color: #26ADE4;
    color: #fff;
    width: 100%;
    text-align: center;
    font-size: 16px;
    font-weight:bold;
}
nav ul {
    display: block;
    padding:14px 0 14px;
}
nav li {
    display: inline-block;
}
nav a {
    padding: 5px 30px 5px;
}
nav a:link {
    color: #fff;
    text-decoration: none;
}
nav a:hover {
    background-color: #D1E751;
    color: #FFF;
}
nav a:visited{color:#FFF;}
#wrapper {
    width: 960px;
    margin-left: auto;
    margin-right: auto;
    background-color: #fff;
    overflow: hidden;
    padding-top:60px;
}
.container{width:960px;
margin-left:auto;
margin-right:auto;
text-align:center;}
.blocks{display:inline-block;
        width:300px;
        padding-left:5px;
        padding-right:5px;
}
h1 {
    font-size: 20px;
    color: #26ADE4;
    font-weight: 500;
    margin-bottom: 2px;
}
h2 {
    font-weight:500;
    font-size: 60px;
    color: #fff;
    position:absolute;
    left:-2px;
    bottom:-9px;
}
footer {
    background-color: #D1E751;
    color: #fff;
    font-size: 10px;
    padding: 12px;
    font-weight:bold;
    clear: both;
}
.left{text-align:left;
font-size:14px;
        float:left;
        padding-top:8px;
        padding-bottom:8px;
}
.right{float:right;
text-align:right;
}
.centered{text-align:center;
font-size:14px;
padding-top:8px;
        padding-bottom:8px;
        max-width:300px;
        margin-left:auto;
        margin-right:auto;}

截图

  • 去掉边距:自动到身体去掉周围的空白
  • 对于简单的页脚,您可以将元素fixed定位到屏幕
  • 对于页脚中的元素,您可以在带有 id 页脚的div 上使用显示 flex 属性

    下面的CSS规则和笔在这里

    body {
      margin: auto;
    }
    .left,
    right,
    .centered {
      margin-left: 50px;
      margin-right: 50px;
      margin-top: 0;
    }
    footer {
      position: fixed;
      bottom: 0;
      left: 0;
      width: 100%;
    }
    
  • 最新更新