左边固定宽度,右边自适应

浮动布局的方法

<section class="container homeSection" id="mainSection">
<div class="content-wrap">
222
</div>
<div class="rightSide">
333
</div>
</section> <style lang="scss">
.homeSection {
overflow: hidden;
.content-wrap {
float: left;
width: 200px;
background-color: #fff;
}
.rightSide {
margin-left: -200px;
background: #F0AD4E;
}
}
</style>

 绝对定位的方法:

<section class="container homeSection" id="mainSection">
<div class="content-wrap">
<div class="bannerFloor">
122
</div>
</div>
<div class="rightSide">
333
</div>
</section>
<style>
.homeSection {
position: relative;
.content-wrap {
position: absolute;
left: 0;
width: 200px;
}
.rightSide {
position: absolute;
left: 200px;
right: 0;
} }
</styles>

还有就是 flex 布局喽,大家应该都知道,就不写了。

左边固定宽度,右边自适应

浮动方法

以下是html代码,与上面有所不同的是,书写代码的时候,right代码在前面

<section class="container homeSection" id="mainSection">
<div class="rightSide">
333
</div>
<div class="content-wrap">
<div class="bannerFloor">
<p>
你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁
</p>
</div>
</div> </section>
.homeSection {
overflow: hidden; .content-wrap {
background-color: #fff;
margin-right: 200px;
}
.rightSide {
float: right;
width: 200px;
background: #F0AD4E;
}
}
另一种浮动的方法:需要给左边自适应的元素一个父元素, 如文中的content-wrap
<section class="container homeSection" id="mainSection">

        <div class="content-wrap">
<div class="bannerFloor">
<p>
你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁你是谁
</p>
</div>
</div> <div class="rightSide">
333
</div> </section>
.content-wrap {
float: left;
.bannerFloor {
margin-right: 200px;
}
}
.rightSide {
float: left;
width: 200px;
margin-left: -200px;
background: #F0AD4E;
}

同意的,它也有 绝对定位 跟 flex 的方法,不一一的列出来了。

更详细的内容可以访问 http://www.waigai.cn

css布局:左边固定宽度,右边自适应;右边固定宽度,左边自适应的更多相关文章

  1. 如何用纯CSS布局两列,一列固定宽度,另一列自适应?

    大家都知道好多网站都是左右布局的,很多公司在笔试和面试环节也常常问这个问题.一个去网易的师兄说14年腾讯面试的时候问过这个问题,网易在笔试和面试时候也问过这个问题,还有很多互联网公司也都涉及到这个问题 ...

  2. css布局:左边固定宽度,右边自适应宽度或右侧固定,左侧自适应三种方法

    方法一:浮动布局 这种方法我采用的是左边浮动,右边加上一个margin-left值,让他实现左边固定,右边自适应的布局效果 HTML Markup <div id="left" ...

  3. css布局:左边定宽、右边自适应

    方法一 : 左边 左浮动,右边 margin-left *{margin: 0;padding: 0;} .left{ float: left; width: 200px; border: 1px s ...

  4. HTML布局之左右结构,左边固定右边跟据父元素自适应

    HTML布局之左右结构,左边固定右边跟据父元素自适应,兼容IE6+.Firefox.Chrome.Opera.Safari,这里是用表单写的一个demo,其实就在主体布局中也是可以的,比如像后台一些管 ...

  5. css实现左(右)侧固定宽度,右(左)侧宽度自适应 ---清除浮动

    老话长谈,css的不固定适应布局   不管是面试还是在平时的工作中,这样的布局形式一直都在用着,很常见,所以今天我就拿出来在唠叨一下, 既是给自己一个备忘存储,也是一个学习巩固的参考,知道大家都会,还 ...

  6. Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法

    Css中实现一个盒子固定宽度,另一个盒子宽度自适应的方法 网上方法很多,个人认为以下两种思想是最为常用的. 一种是让第一个盒子脱离文档流,第二个盒子离左边有一定距离. 第二种方法是使用flex布局,不 ...

  7. css中如何实现左边的高度随着右边改变而改变

    css中如何实现左边的高度随着右边改变而改变 html结构: <div class="main"> <div class="main_left" ...

  8. CSS 布局实例系列(三)如何实现一个左右宽度固定,中间自适应的三列布局——也聊聊双飞翼

    今天聊聊一个经典的布局实例: 实现一个三列布局,其中左侧和右侧的部分宽度固定,中间部分宽度随浏览器宽度的变化而自适应变化 可能很多朋友已经笑了,这玩意儿通过双飞翼布局就能轻松实现.不过,还请容我在双飞 ...

  9. css布局两边固定中间自适应的四种方法

    第一种:左右侧采用浮动 中间采用margin-left 和 margin-right 方法. 代码如下: <div style="width:100%; margin:0 auto;& ...

  10. DIV+CSS布局中自适应高度的解决方法

    div乱跑问题  (文件<DIV+CSS布局中自适应高度的解决方法.rar>)   float 是个很危险的东西 得小心使用 本来有一很好的关于CSS+DIV的论坛 不过现在关门了 甚是可 ...

随机推荐

  1. self study 权限 permission

    demo 测试成功, import 'package:permission/permission.dart'; Future requirePermission()async { await Perm ...

  2. springboot+mybatis环境的坑和sql语句简化技巧

    1.springfox-swagger实体类无限递归 https://hacpai.com/article/1525674135818 里面有不完美的解决方案 不用动源码的解决方案也有,在swagge ...

  3. Java反射操作成员变量 Class can not access a member with modifiers "*"

    fields[j].set(obj, val); 报: Exception in thread "main" java.lang.IllegalAccessException: C ...

  4. numpy, matplotlib库学习笔记

    Numpy库学习笔记: 1.array()   创建数组或者转化数组 例如,把列表转化为数组 >>>Np.array([1,2,3,4,5]) Array([1,2,3,4,5]) ...

  5. bzoj 4767 两双手 - 动态规划 - 容斥原理

    题目传送门 传送门I 传送门II 题目大意 一个无限大的棋盘上有一只马,设马在某个时刻的位置为$(x, y)$, 每次移动可以将马移动到$(x + A_x, y + A_y)$或者$(x + B_x, ...

  6. 测试框架Unitest的运行原理,以及多个测试类中的执行顺序以及简化方法

    单元测试单元测试(unit testing)是指对软件中的最小可测试单元进行检查和验证.对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体含义,如C语言中单元指一个函数,Java里单元指一 ...

  7. 论文笔记:Siamese Cascaded Region Proposal Networks for Real-Time Visual Tracking

    Siamese Cascaded Region Proposal Networks for Real-Time Visual Tracking 2019-03-20 16:45:23 Paper:ht ...

  8. 【Python】函数总结

    以下为自学笔记内容,仅供参考. 转发请保留原文链接https://www.cnblogs.com/it-dennis/p/10516688.html python中的函数 最近看了python中关于函 ...

  9. POJ1192最优连通子串----树形dp

    中文题面,目的很明显,把相邻的两个点看成是两个点之间有一条边,就能当成树形dp来做了. 用一遍dfs可以找出最大的子树权值和. #include<iostream> #include< ...

  10. Use SourceLink enables a great source debugging experience

    posts Exploring .NET Core's SourceLink - Stepping into the Source Code of NuGet packages you don't o ...