网页学习体会

  • 首页
  • 个人博客
您的位置: 首页  >  技术问答  >  页脚停留在
的右侧

页脚停留在
的右侧

分类: 技术问答 • 2022-03-08 00:02:37
问题描述:

I'm learning HTML/CSS/PHP and building a website from scratch in my spare time.

The footer in the following code stays at the bottom where I want it unless I use the content <div>, then it shoots to the right of the content.

I can't figure out why?! I've commented out the float: left and that doesn't make a difference.

Thanks for your help.

style.css:

html {
font-family: sans-serif;
}

.wrap {
min-width: 600px;
width: 85%;
margin: auto;
float: left;
}

.navigation {
padding: 5px;
background: black;
text-align: center;
}

.navigation li {
display: inline;
padding-right: 10px;

}

.navigation a {
text-decoration: none;
color: white;
font-size: 20;
font-family: fantasy;

}

.navigation a:hover {
text-decoration: underline;

}

.content {
background: #f8f8f8;
float: left; 
width: 80%;
}


header {
text-align: center;
margin: auto;
}

header a {
text-decoration: none;
color: black;
}

h5 {
font-size: 120px;
font-family: cursive;
font-variant: small-caps;
margin-top: 10px;
margin-bottom: -100px;
text-shadow: 2px 1px 3px gray; 

 }

h6 {
font-size: 32px;
}

p {
padding-bottom: 10px;
}

header.php:

<html>

<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <title></title>
</head>

<body>

<div class="wrap">

<header>
    <a href="/index.php"><img src = "/images/banner_logo.jpg"></a>

</header>


<div class="navigation">
    <ul>
        <li><a href="/index.php">Home</a></li>
        <!--<li><a href="/blog/index.php">Blog</a></li>-->
        <li><a href="/pics/index.PHP">Pics</a></li>
        <li><a href="/contact/index.php">Contact</a></li>
        <li><a href="/about/index.php">About</a></li>
        <li><a href="/produce/index.php">Produce</a></li>
    </ul>
</div>

footer.php:

<!--begin footer -->


<br><small>Copyright 2015</small>

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

index.php (with content):

<?php include "header.php"; ?>

<!--begin page content-->

    <h2>Welcome</h2>
    <div class="content">
        <p>Wander around and see if I've figured out what to do here.</p>


            <h4>Would you like to tell me you are here?</h4>
            <form action="process.php" method="post"> 

            First Name: <input name="fname" type="text" /> 
            <input type="submit" />
            </form> 




    </div>  
    <br>

答

Because clearing divs is a common problem that you will run across frequently, you will likely want to create a utility class.

.clearfix:after {
    clear: both;
   content: " ";
   display: block;
   font-size: 0;
   height: 0;
   visibility: hidden;
}
.clearfix {
   display: block;
}
.clearfix {
   display: inline-block;
}

Apply it to the div directly, or sometimes, you'll find that you want to toss it in a div at the end of your oddly floating clear.

<div class="clearfix"></div>

or

<div id="leftnav">
   ...
   <div class="clearfix"></div>
</div>

答

you need to apply a clearing to the footer, since your .content element is floated. The easy way is to wrap your footer content with a meaningful tag (e.g. <footer>) and then give this style

footer {
  clear: both;
}

A better refined way is to use the .clearfix class as used in the html5 boilerplate applied directly to the .content element, e.g.

.content:before,
.content:after {
    content: " ";  
    display: table;  
}

.content:after {
    clear: both;
}

答

Commenting out the float: left in the .content section of the CSS does indeed force the footer onto the next line. See: http://jsfiddle.net/Lu7w03mh/1/.

相关推荐

  • css 两列 左侧列固定 width: 100px; float: left; 右侧列自适应 margin-left:100px; 注意要用在div上的style
  • 怎么取消div定义块与屏幕右侧的缝隙,求大神指导
  • 解决Bootstrap container样式左右内边距15px,导致屏幕不美观 首先上问题:此问题为bootstrap的 container样式导致,该样式默认左右内边距15px为了栅栏效果而设计,具体看源码css样式,如下图,右侧黄色边框边距和30px,实为两个div左浮动,将边距挤到右侧;
  • 将div附加到另一个div的右侧
  • 18常用web开发 浮动层、提示层代码下载 1、jQuery顶部固定层页面滚动淡出淡进菜单显示 2、jQuery鼠标滚动条到页面底部浮动层滑动弹出信息 3、网页向导Jquery插件wlGuide功能操作步骤引导 4、jQuery文字段落鼠标悬停图片突出显示和预览 5、jquery 万能float浮动层插件 制作QQ MSN 旺旺在线客服代码 6、jquery右侧悬浮层在线客服代码,在线问答QQ代码 7、jquery浮动层制作右下角float浮动提示框向上滑动提示 8、div css3样式表制作jquery返回顶部特效 9、jquery smartFloat插件仿淘宝产品列表页随页面滚动固定层 10、jquery浮动固定层导航描点上下滚动的浮动定位层 11、jQuery插件页面滚动返回顶部按钮 12、jquery tips提示插件自适应屏幕宽度提示图片信息 13、jquery固定层顶部固定层和底部固定层IE6不抖动 14、jquery提示框鼠标滑过图片提示框 15、jquery浮动菜单跟随页面滚动左
  • 如何让一个在浏览器底部的div在向下滚动的时候停留在浏览器的顶部
  • 如何让一个在浏览器底部的div在向上滚动的时候停留在浏览器的顶部
  • 右侧的Div键填写所有可用空间
  • div+css如何实现页脚的置底
  • 使用div+CSS将页脚始终控制在页面最下方的方法
  • 如何将div的背景图像属性设置为动态生成的图像
  • 为什么 Jenkins 抱怨我的反向代理设置坏了?
    网站免责声明 网站地图 最新文章 用户隐私 版权申明
本站所有数据收集于网络,如果侵犯到您的权益,请联系网站进行下架处理。   

Copyright © 2018-2021   Powered By 网页学习体会    备案号:   粤ICP备20002247号