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

关于如何使用div的几个问题-severalquestionsabouthowtoworkwithdivs

imtryingtomakethis:我正试着这样做:Theblackdivmustbewithsomebackground-color,butwithawi

i'm trying to make this:

我正试着这样做:

The black div must be with some background-color, but with a width of 100%. The red div must be with a maximum width of 900px, but with ability to shrink for a minimum of 300px(not less than that). Ignore blue div, did it by mistake. The greed divs, must be of maximum 150px, but able to shrink for a minimum of 100px(not less than that). And the orange div, must fill all this space(600px if green divs 150px(max), and if green divs 100px(min), then it should shrink for a minimum of 100px;).

黑色div必须带有一些背景色,但宽度为100%。红色div必须最大宽度为900px,但能够缩小至少300px(不小于该值)。忽略蓝色div,错误地做了。贪婪div必须最大150px,但能够缩小至少100px(不小于)。并且橙色div必须填满所有这些空间(600px,如果绿色div为150px(最大),如果绿色div为100px(min),那么它应该缩小至少100px;)。

I have a huuuuge problem makin' this to work. I just can't figure it out how to make this shrinkin' think to work properly :/ All I was tryin' is to play with max-width, min-width and width it self, but every single time something is not working as i wish it to work. The only think is working fine, is the black div. Simply by making it 100% width and height size.

我有一个huuuuge问题makin'这个工作。我只是无法弄清楚如何使这个缩小'认为正常工作:/我所有尝试'是最大宽度,最小宽度和宽度自己玩,但每次都有一些不起作用我希望它能发挥作用。唯一的想法是工作正常,是黑色div。只需将其100%宽度和高度尺寸。

I'm trying to make this with css and html only, and of course with cross-browsing as possible

我只想用css和html来做这个,当然还有尽可能的交叉浏览

2 个解决方案

#1


Not sure if I fully understand what you wanted, but something like this?

不确定我是否完全理解你想要的东西,但这样的东西呢?

jsfiddle

HTML

Word
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud"
Sed ut perspiciatis unde omnis iste natus errorsit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur

CSS

#black {
    width: 100%;
    height: 50px; /* just for example */
    background-color: #000; 
    text-align: center; /* center red div, because it is inline block */
}
#red {
    overflow: hidden;
    min-height: 100%;
    min-width: 300px;
    max-width: 900px;
    display: inline-block; /* inline block, so it's width will be based on content inside him */
    background-color: red;
    /* text-align: left; if you don't want have centered text */
}
.first {
    float: left;
}
.second {
    float: right;
}
.green {
    max-width: 150px;
    min-width: 100px; 
    min-height: 100%;
    background-color: green;
    padding-bottom: 100%;
    margin-bottom: -100%;
}
#orange {
    background-color: orange;
    min-height: 100%;
    overflow: hidden;

    max-width: 600px;
    min-width: 100px;
    padding-bottom: 100%;
    margin-bottom: -100%;
}

If one of those green divs is empty, it will probably not work.

如果其中一个绿色div是空的,它可能不起作用。

This in red

这是红色的

overflow: hidden;

and this in green ones and orange

这是绿色和橙色

padding-bottom: 100%;
margin-bottom: -100%;

makes that they'll have always same height.

使他们总是有相同的高度。

This in black

这是黑色的

text-align: center; 

makes that red one will be centered because it is inline-block.

使红色的一个将居中,因为它是内联块。

And making middle div (orange) as last one in html with overflow: hidden in css, makes it to expand the space between those green divs.

并在html中将中间div(橙色)作为最后一个使用溢出:隐藏在css中,使其扩展这些绿色div之间的空间。

EDIT

Edited my code because I read the question wrong

编辑我的代码,因为我读错了

#2


I think your missing link here is the use of media queries.

我认为你在这里缺少的链接是使用媒体查询。

MDN has a great guide:

MDN有一个很棒的指南:

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

Essentially, this lets you change the CSS depending on the width of the page.

从本质上讲,这可以让您根据页面的宽度更改CSS。


推荐阅读
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 知识图谱——机器大脑中的知识库
    本文介绍了知识图谱在机器大脑中的应用,以及搜索引擎在知识图谱方面的发展。以谷歌知识图谱为例,说明了知识图谱的智能化特点。通过搜索引擎用户可以获取更加智能化的答案,如搜索关键词"Marie Curie",会得到居里夫人的详细信息以及与之相关的历史人物。知识图谱的出现引起了搜索引擎行业的变革,不仅美国的微软必应,中国的百度、搜狗等搜索引擎公司也纷纷推出了自己的知识图谱。 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
  • 移动传感器扫描覆盖摘要:关于传感器网络中的地址覆盖问题,已经做过很多尝试。他们通常归为两类,全覆盖和栅栏覆盖,统称为静态覆盖 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • Tomcat/Jetty为何选择扩展线程池而不是使用JDK原生线程池?
    本文探讨了Tomcat和Jetty选择扩展线程池而不是使用JDK原生线程池的原因。通过比较IO密集型任务和CPU密集型任务的特点,解释了为何Tomcat和Jetty需要扩展线程池来提高并发度和任务处理速度。同时,介绍了JDK原生线程池的工作流程。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 导读执行UPDATE时,WEHRE条件列虽已有索引,但还会锁全表,肿么回事?问题描述叶师傅有次上课过程中执行UPDATE测试案例时,发现虽然WHERE条件列已有索 ... [详细]
  • css div中文字位置_超赞的 CSS 阴影技巧与细节
    本文的题目是CSS阴影技巧与细节。CSS阴影,却不一定是box-shadow与filter:drop-shadow,为啥?因为使用其他属性 ... [详细]
  • GO语言 包 if..else.. for循环 switch 数组
    包1.什么是包1.新建一个文件夹,内部写很多go文件,但是包名必须一致,改文件夹就是一个包2.作用和优点包用于组织Go源代码,提供了更好的可重用性与可读性。由于包提供了代码的封装, ... [详细]
  • Android日历提醒软件开源项目分享及使用教程
    本文介绍了一款名为Android日历提醒软件的开源项目,作者分享了该项目的代码和使用教程,并提供了GitHub项目地址。文章详细介绍了该软件的主界面风格、日程信息的分类查看功能,以及添加日程提醒和查看详情的界面。同时,作者还提醒了读者在使用过程中可能遇到的Android6.0权限问题,并提供了解决方法。 ... [详细]
  • 本文讨论了在使用Git进行版本控制时,如何提供类似CVS中自动增加版本号的功能。作者介绍了Git中的其他版本表示方式,如git describe命令,并提供了使用这些表示方式来确定文件更新情况的示例。此外,文章还介绍了启用$Id:$功能的方法,并讨论了一些开发者在使用Git时的需求和使用场景。 ... [详细]
  • 由于同源策略的限制,满足同源的脚本才可以获取资源。虽然这样有助于保障网络安全,但另一方面也限制了资源的使用。那么如何实现跨域呢,以下是实现跨域的一些方法。 ... [详细]
author-avatar
小鱼2502907687
这个家伙很懒,什么也没留下!
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社区 版权所有