让左栏一直向下延伸

2024-03-12

我已经为此绞尽脑汁近三天了。我读过很多关于 3col 拉伸、设置清晰和使用绝对位置和相对位置的文章(很多是矛盾的)

我认为,我想要一个非常简单的布局。我想要左侧的导航 div。左侧有两个 div 和一个页脚。如果我使用表格,它会是这样的:

<table border="1">
<tr> 
    <td rowspan="2">
        left nav.
    </td>
    <td>right 1</td>
</tr>
<tr>
    <td>right 2</td>
</tr>
<tr>
    <td colspan="2">footer</td>
</tr>

但是我无法让左侧 div 一直向下延伸。以下是我最接近的解决方案。这实际上似乎在 ie7 中有效,但在 Opera 或 Firefox 中无效。

我相信这是由于浮动没有扩展父级 div 的长度造成的,因此左侧 div 认为它的父级比实际小。

任何帮助都会很棒。

    <html>
<head>
<style type="text/css">
body
{
height:100;
}



.main{
    height: 100%;
    margin-left: auto;
    margin-right: auto;
    position: absolute;
    width: 100%;
}


.leftDiv
{

    position: relative;
    float: left;
    width: 18%;
    height: 100%;
    background-color: aqua;
}

.topRight
{
    position: relative;
    float: right;
    width: 80%;
    background-color: green;
}
.bottomRight
{
    position: relative;
    float: right;
    width: 80%;
    background-color: red;
}

.footer
{
    width: 100%;
    float: right;
    background: blue;
    position: relative;
}

</style>
</head>

<body>

<div class="main">

    <div class="leftDiv">This should Stretch all the way down the left side</div>
    <div class="topRight">This should be over to the right at the top</div>
    <div class="bottomRight">This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>This should be at the bottom right this is where the main content will go<br/>
lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>
lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>
lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>
lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>lotst of text here<br/>
lotst of text here<br/> </div>

    <div class="footer">footer text.  This should be at the bottom of the screen under the main content.<br/></div>




</div>

</body>
</html>

我自由地清理了一下它。我还将您的页脚 div 放在主 div 之外。

在此布局中,主 div 的内容决定了高度。我给所有内容留出了 20% 的左边距,并将左侧 div 绝对定位在该边距之上。由于主 div 也是左侧 div 的父级,因此将左侧 div 的高度设置为 100% 会使其拉伸到主 div 的高度(其位置具有内容的高度)。

另一个(更干净的)选项是设置bottom: 0px而不是height: 100%在左侧 div。它将底部与容器(主 div)的底部对齐,但我认为这在 ie6 中不起作用。

.topRight, .bottomRight {
    margin: 0px 0px 0px 20%;
}

.main {
    height: 100%;
    position: relative;
}


.leftDiv {        
    position: absolute;
    left: 0px;
    top: 0px;
    width: 18%;
    bottom: 0px;
    background-color: aqua;
}

.topRight {
    background-color: green;
}

.bottomRight {
    background-color: red;
}

.footer {
    background: blue;
}

http://jsfiddle.net/Z44HK/ http://jsfiddle.net/Z44HK/

PS:我希望这些</br>标签仅用于测试,因为它们看起来很丑。 CSS 的发明是为了消除 html 中的此类表示性标签。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

让左栏一直向下延伸 的相关文章

  • 我如何用 javascript/jquery 进行两指拖动?

    我正在尝试创建当有两个手指放在 div 上时拖动 div 的功能 我已将 div 绑定到 touchstart 和 touchmove 事件 我只是不确定如何编写这些函数 就像是if event originalEvent targetTo
  • Img srcset 和尺寸属性

    我正在尝试制作一个简单的网站img标签 将使用新的srcset属性 主要思想是根据屏幕分辨率更改图像 src 工作示例 http pixelteam pl surprise some files index html 问题在于sizes 正
  • Javascript 放大/缩小到鼠标 x/y 坐标

    我设法让鼠标拖动来滚动div 但是用鼠标放大 缩小不完整 它有效 但我希望鼠标指针将图像保持在该位置并同时缩放它 如下所示 我需要使用scrollBy 将滚动返回到缩放之前的上一点 有人知道该怎么做吗 这是某人制作的小提琴https jsf
  • Twitter Bootstrap - 多图像(缩略图)轮播 - 一次移动一个缩略图

    我正在尝试 Twitter bootstrap 3 我对 HTML CSS 和 Javascript 还很陌生 我有一个我创建的轮播 它的代码如下所示 div class container div class carousel slide
  • onclick 函数上的 CSS 选择器

    有没有办法让CSS选择器onclick function 您可以在onclick https stackoverflow com questions 24365416 select element which have specific a
  • 如何在 Bootstrap 4 中垂直对齐?

    我试图在 Bootstrap 4 4 0 0 alpha 6 中将我的大屏幕的内容垂直对齐在中心 在 Mac 桌面上的 Chrome 和 Safari 中 这种情况发生得很好 但在我的 iOS 设备上则不然 文本仍然与顶部对齐 我强制大屏幕
  • css 字体 twitter 像关闭按钮一样,我错过了什么?

    twitter 有一个关闭按钮 它是单个字符 x 我需要类似的东西 但是在我检查之后 span x span 我按照 firebug 告诉我的那样创建 css 规则 close button font family Tahoma Arial
  • 新BFC“清”浮箱

    如示例所示 应用display inline block 到包含块似乎 清除 了其中的浮动框 wrapper inline block display inline block left column background color te
  • 左对齐图像和居中文本在 div 内的同一级别?

    HTML br div class UpperTitle img src align left CableSolve Web Dashboard Version 0 1 1 div br CSS UpperTitle text align
  • 角度 ng-repeat 根据条件添加样式

    我在 div 列表上使用 ng repeat 并且在渲染此 div 的 json 中手动添加项目 我需要定位我在 json 中添加的最后一个 div 它会自动在屏幕上渲染 即 couse 光标所在的位置 其余部分保持在相同位置 但没有给出渲
  • 背景大小:封面在视网膜显示屏上看起来像素化

    可以看到我正在开发的网站here http ourcityourstory com dev 如果你查看 iPad 3 或 iPhone 4 上的 关于 或 联系 部分 背景看起来全都是疯狂的像素化 我有background size set
  • 与 960.gs 的列高度相同吗?

    我有一排 4 列 根据我在每一列中放入的信息量 它们将具有不同的高度 如果你给它们加上背景颜色你就可以看到 我如何给其他列最大高度的列的高度 您可以使用 jQuery 来执行此操作 http www cssnewbie com equal
  • 如何从iframe访问文档中的

    I have an iframe 我在检查器元素中发现 img 标签位于具有 body 标签的 document 中 img src Images landingpage jpg 我需要访问此图像 landing page jpg 以便更改
  • 无限水平滚动图像循环?

    所以我试图在我的网站上创建一个无限滚动动画 但我一直在努力 原始教程在这里 使用 6 张图像 最后重复 4 张图像以实现无缝过渡 https designshack net articles css infinitephotobanner
  • 底部带有三角形的 div 和背景图像

    我想做一个div 有一个底部的三角形 但我需要三角形上的背景图像为了出现 我尝试使用伪元素 after 但它不起作用 homebg after content position absolute top 100 left 0 right 0
  • 如何设置必须输入特定数字的字段?

    我想知道如何创建一个需要输入特定数字或文本的字段 例如 激活码 以及在输入的确认答案的情况下移动到 网页 并且在未确认的情况下移动到 另一页面 的按钮 使用必需的属性
  • 网格布局:创建 CSS,以便元素在调整相邻元素大小时保持位置

    我想在网格布局中构建一个简单的图像库 并且我正在使用类似的东西悬停时缩放 http www javascript fx com navigation imagezoom general help help html缩放悬停图像 但我宁愿使用
  • 中有样式表 吗?

    在内部链接 CSS 文件是一个坏主意吗 body 我读过 如果浏览器在外部找到另一个 CSS 文件 则它会被迫重新开始 CSS 渲染 head 只是因为它可能需要将样式应用于已经渲染的元素 另外 我认为 HTML 无法正确验证 我需要确认这
  • CSS 标签“object-fit:cover”不会在 Chrome 中裁剪/剪辑视频

    CSS tag object fit cover无法按预期在 Chrome 中剪辑 裁剪视频 这种情况仅适用于视频且仅在 Chrome 中发生 图像在 Chrome 中正常 在所有其他经过测试的浏览器中 图像和视频都工作正常 The beh
  • HTML 表格 - 固定列宽和多个可变列宽

    我必须建立一个有 5 列的表 表格宽度是可变的 内容宽度的 50 有些列包含固定大小的按钮 因此这些列应该有一个固定大小 例如 100px 有些列中有文本 所以我希望这些列具有可变的列宽 例如 Column1 tablewidth sum

随机推荐

  • 如何删除 X 个字符之后的所有单词

    我读了这篇文章 sed 删除行中除前 5 个字符之外的剩余字符 https stackoverflow com questions 10718326 sed delete remaining characters in line excep
  • Makefile 匹配任何规则作为中间

    考虑这个简单的 Makefile one two echo one two three echo two three four echo three all hi one 正如预期的那样 make all将产生 echo three thr
  • 如何在 Azure 数据工厂中执行查找?

    我是一名 SSIS 开发人员 我在 SSIS 中研究了很多 SQL 存储过程查找概念 但是当来到 Azure 数据工厂时 我不知道如何使用 SQL 存储过程执行查找 有人可以指导我吗 提前致谢 杰伊 Azure 数据工厂 ADF 更像是一种
  • 在react-router中连接多个查询参数[重复]

    这个问题在这里已经有答案了 我在用react router domv 5 2 0 我想在 URL 中添加多个查询参数 但我不知道如何完成它 我的路线如下
  • 禁用自动更正类型不适用于 UITextfield

    我创造了RegisterViewController包含电子邮件 密码和确认密码字段 在电子邮件字段中 它始终在 QuickType 键盘栏上显示建议的电子邮件 但其他字段不显示任何内容 它如何知道哪个字段是电子邮件或不是 我发誓我没有在文
  • Swift 中的通用完成处理程序

    我有一个方法 它有一个名为performRequest 这需要一个JSONRequest范围 JSONRequest看起来像这样 public typealias JSONCompletionHandler Entity NSError g
  • Play Framework - 如何继承超类?

    我有一个扩展 Model 的 User 类 以及两个我想扩展 User 类的类 用户 java Entity Table name users public class User extends Model implements RoleH
  • 如何在 scikit-learn 中正确执行交叉验证?

    我正在尝试对 k nn 分类器进行交叉验证 但我对以下两种方法中哪一种正确执行交叉验证感到困惑 training scores defaultdict list validation f1 scores defaultdict list v
  • 使用带有附加类型参数的 Curiously Recurring Template Pattern (CRTP)

    我尝试使用 Curiously Recurring Template Pattern CRTP 并提供其他类型参数 template
  • 背景图像仅拉伸 y 轴,保留重复 x

    我有一个图像设置为 div 的背景图像 DIV 大小正在变化 其内部是渐变图像 CSS scroller shadow background image url img ui shadow png background repeat rep
  • 列出所有不带星号的本地 git 分支 [重复]

    这个问题在这里已经有答案了 如果我跑git branch 我得到类似的东西 master dev foo if I do git branch r 它将显示远程上的所有分支 不带星号 其中星号显示我当前签出的分支 如何列出所有本地分支机构而
  • 在 appsettings.json 日志记录上下文中,MinimumLevel 和 Override 意味着什么?

    我正在查看 appsettings jsonSerilog 示例项目 https github com serilog serilog docker blob master web sample src appsettings json 其
  • python - 是否可以创建“def”列表? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我想知道是否可以创建一个 def 列表 连接 20 个按钮的列表 并为每个按钮设置不同的回调 Thanks def在Python中只是
  • 自定义类扩展 FloatingActionButton 时出错

    我创建了一个自定义类并扩展了FloatingActionButton public class customFAB extends FloatingActionButton public customFAB Context context
  • 在 Pytorch 中执行优化时如何对变量应用界限?

    我正在尝试使用 Pytorch 进行非凸优化 试图最大化我的目标 因此在 SGD 中最小化 我想限制因变量 x gt 0 并且 x 值的总和小于 1000 我认为我已经以斜坡惩罚的形式正确实施了惩罚 但我正在努力解决 x 变量的边界问题 在
  • 表单提交 keyCode == "enter" (13)

    I need to submit the content of a form when I press the Enter key but only if the form has no error message I built up t
  • 如何在react中进行fetch?

    下午好 我从服务器获取json 我处理它 但是对渲染的调用发生了2次 Google 在构造函数中创建一个空对象 如果该对象没有属性 则返回 undefined 但我也有数组 应用程序从中崩溃 我附上代码 如何将数据取出状态 是否可以在渲染中
  • NSJSON序列化

    我在使用某些公共 json 服务时遇到问题 以这种方式格式化的服务 jsonFlickrFeed title Uploads from everyone link http www flickr com photos description
  • Android 本地化 es-r419

    我正在本地化我的应用程序 支持的语言 区域之一是 Espanol 419 Android 不支持命名约定values es r419 但它接受values en rGB 我应该使用什么名称才能使其正常工作 我不知道r419从何而来 我唯一能
  • 让左栏一直向下延伸

    我已经为此绞尽脑汁近三天了 我读过很多关于 3col 拉伸 设置清晰和使用绝对位置和相对位置的文章 很多是矛盾的 我认为 我想要一个非常简单的布局 我想要左侧的导航 div 左侧有两个 div 和一个页脚 如果我使用表格 它会是这样的 ta