热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将3个div列的布局更改为2个div列,下面的第3个列-Changinglayoutof3divcolumnsto2divcolumnsand3rdonebelow

Imtryingtorearrange3divswhendevicewidthisbelow900px.Theyarearrangedasthreecolumns

I'm trying to rearrange 3 divs when device width is below 900px. They are arranged as three columns (2 floating divs and main one in the middle) and i don't know how to make them be 2 columns and third div below them (Image shows what i'm aiming at). Thank you in advance :)

当设备宽度低于900px时,我正在尝试重新排列3个div。它们被安排为三列(2个浮动div和主要的一个在中间),我不知道如何使它们成为2列和它们下面的第三个div(图像显示了我的目标)。先谢谢你 :)

Adding code as you asked :) here is html

你问的问题添加代码:)这里是html








  

and here is css

这是css

#container{
width: 90%;
margin: 0px auto 0px auto ;
}
header{
width: 100%;
height: 200px;
background-color: blue;

}
#left{
float: left;
width: 20%;
height: 500px;
background-color: orange;
}
#right{
float: right;
width: 20%;
height: 500px;
background-color: green;
}
#middle{
width: 80%;
background-color: red;
height: 500px;

}

if i make right div float:none then it moves the middle div

如果我做正确的div浮动:无,那么它移动中间div

5 个解决方案

#1


0  

Welcome to the world of {in an ominous voice} RESPONSIVE DESIGN ! ,

欢迎来到{以不祥的声音}响应设​​计的世界! ,

To perform what you are trying to do you will need to explore Media Queries.

要执行您要执行的操作,您需要探索媒体查询。

Here is an example of what you are trying to do: JSFiddle

以下是您要尝试的示例:JSFiddle

HTML

HTML

left content flexible width
right content fixed width
Bottom content flexible width

CSS

CSS

.container {
  height: 100px;
  overflow: hidden;
}

.left {
   float: left;
  background: #00FF00;
  width: 25%;
  overflow: hidden;
  height: 100%;
}

.right {
  display: inline-block;
  width: 50%;
  background: #0000ff;
  height: 100%;
}

.bottom {
  float: right;
  background: #ff0000;
  display: inline-block;
  width: 25%;
  height: 100%;
}

@media only screen and (max-width: 900px) {
  .container {
    height: auto;
    overflow: hidden;
  }
  .left {
    float: left;
    background: #00ff00;
    width: 25%;
    overflow: hidden;
    height: 100px;
  }
  .right {
    float: none;
    width: 75%;
    background: #0000ff;
    height: 100px;
  }
  .bottom {
    position: relative;
    float: none;
    background: #ff0000;
    width: auto;
    overflow: hidden;
    height: 50px;
    display: inherit;
  }
}

Good luck!

祝你好运!

#2


1  

You need to use media queries https://css-tricks.com/snippets/css/media-queries-for-standard-devices/

您需要使用媒体查询https://css-tricks.com/snippets/css/media-queries-for-standard-devices/

Enjoy

请享用

#3


1  

With media queries and flex.

使用媒体查询和flex。

Here is a snippet, (click on run then full screen).

这是一个片段,(点击运行然后全屏)。

1
2
3

    .flex{
        display: flex;
        flex-wrap: wrap;
    }
    .c{
      height:20px;
      width:20px;
      border: 1px solid green;
      box-sizing: border-box;
      }

    @media(max-width:600px){
     .sub{
        width: 50%;
      }
     .doge{
        width: 100%
      }
    }

#4


0  

It would be helpful to see your sourcecode to tell you why it has not worked. At least you could describe it in more detail. Otherwise I would suspect that clear: both could maybe help you here by redefining a div-class in a media-query. At least this has worked for me.

看到你的源代码告诉你为什么它没有工作会很有帮助。至少你可以更详细地描述它。否则我会怀疑这一点:两者都可以通过在媒体查询中重新定义div类来帮助你。至少这对我有用。

As an example you could just attach float: left for the left column then the middle column would be following on the right side. By redefining the right-column (class) with clear: both the right-column would then be a footer. This is just an example and would not be the best solution indeed.

作为一个例子,您可以为左列添加float:left,然后在右侧跟随中间列。通过使用clear重新定义右列(类):右列将成为页脚。这只是一个例子,并不是最好的解决方案。

#5


0  

Here's my take on it.

这是我的看法。

/* Styles go here */

body,html{
  margin: 0;
  padding: 0;
  height:100%;
}


.wrapper{
  height:100%;
  width:100%;
  padding: 20px;
}

.div1{
  height:100%;
  width:30%;
  float:left;
  background-color:orange;
}

.div2{
  height:100%;
  width:30%;
  float:left;
  margin-left:2%;
  background-color:red;
  
}

.div3{
  height:100%;
  width:30%;
  margin-left:2%;
  float:left;
  background-color:green;
}

@media(max-width:900px){
  
  .wrapper{
  height:100%;
  width:100%;
  clear:both;
}
  
  .div1{
    height:70%;
    width:49%;
    float:left;
    background-color:orange;
  }
  
  .div2{
    height:70%;
    width:49%;
    float:left;
    background-color:red;
    
  }
  
  .div3{
    height:30%;
    width:100%;
    float:left;
    margin:20px 0 20px 0;
    background-color:green;
  }
  
}


推荐阅读
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 使用圣杯布局模式实现网站首页的内容布局
    本文介绍了使用圣杯布局模式实现网站首页的内容布局的方法,包括HTML部分代码和实例。同时还提供了公司新闻、最新产品、关于我们、联系我们等页面的布局示例。商品展示区包括了车里子和农家生态土鸡蛋等产品的价格信息。 ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 十大经典排序算法动图演示+Python实现
    本文介绍了十大经典排序算法的原理、演示和Python实现。排序算法分为内部排序和外部排序,常见的内部排序算法有插入排序、希尔排序、选择排序、冒泡排序、归并排序、快速排序、堆排序、基数排序等。文章还解释了时间复杂度和稳定性的概念,并提供了相关的名词解释。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 展开全部下面的代码是创建一个立方体Thisexamplescreatesanddisplaysasimplebox.#Thefirstlineloadstheinit_disp ... [详细]
  • 标题: ... [详细]
  • 导出功能protectedvoidbtnExport(objectsender,EventArgse){用来打开下载窗口stringfileName中 ... [详细]
  • ScrollView嵌套Collectionview无痕衔接四向滚动,支持自定义TitleView
    本文介绍了如何实现ScrollView嵌套Collectionview无痕衔接四向滚动,并支持自定义TitleView。通过使用MainScrollView作为最底层,headView作为上部分,TitleView作为中间部分,Collectionview作为下面部分,实现了滚动效果。同时还介绍了使用runtime拦截_notifyDidScroll方法来实现滚动代理的方法。具体实现代码可以在github地址中找到。 ... [详细]
  • 本文介绍了响应式页面的概念和实现方式,包括针对不同终端制作特定页面和制作一个页面适应不同终端的显示。分析了两种实现方式的优缺点,提出了选择方案的建议。同时,对于响应式页面的需求和背景进行了讨论,解释了为什么需要响应式页面。 ... [详细]
  • 本文介绍了在HTML中实现表格的页眉页脚布局的解决方案。通过基本的HTML/CSS技术,避免使用内联样式和固定定位,实现了一个标准的页眉页脚布局。提供了一个替代的解决方案,为读者提供了参考。 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
author-avatar
俞承豪那个男人-
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有