我正在使用 AngularJS 和 SCSS 编写网站代码。我正处于开发的移动阶段,我很快发现(对于这个元素)我需要一种方法来使用 @media 查询来定位多个断点。所以我通过 this SO answer 找到了和 this CSS Tricks Post以及关于 SO 的其他多个答案。然后我将找到的解决方案实现到一个测试用例中,请参阅下面的测试片段。
main {
background-color: grey;
height: 100%;
min-height: 1000px;
@media (max-width: 992px) {
background-color: red
}
@media (max-width: 768px) {
background-color: lightcoral
}
@media (max-width: 992px), (max-width: 992px) and (orientation: landscape) {
background-color: lightgreen;
}
@media (max-width: 768px),
(max-width: 768px) and (orientation: landscape) {
background-color: lightblue;
// Reset the min-height here, because we no longer have the sticky search bar.
min-height: 450px;
}
}
<main>
<h1>Page Title</h1>
<h2>Some Descriptive information</h2>
<div>Content</div>
</main>
但我一直无法让它工作。最终,我想要做的是当用户在平板电脑或手机上处于横向时应用样式。但是,我不知道我是否做对了,或者是否正确使用了 或 运算符。
显然行不通,嗯,第一个语句(例如:(max-width: 992px))有效,但第二个语句的计算结果不为真。根据 Mozilla 的说法:
Comma-separated lists behave like the logical operator or when used in media queries. When using a comma-separated list of media queries, if any of the media queries returns true, the styles or style sheets get applied. Each media query in a comma-separated list is treated as an individual query, and any operator applied to one media query does not affect the others. --- Mozilla Documentation
即使我将代码分成两个单独的媒体查询:
@media (max-width: 992px) {
background-color: lightgreen;
}
@media (max-width: 992px) and (orientation: landscape) {
background-color: lightgreen;
}
还是不行。所以我不知道我是否瞄准了错误的宽度(在横向时)或者我做错了什么。其他前端开发人员能告诉我为什么我的逗号分隔媒体查询不起作用吗?
编辑:这是原生 SCSS 代码:
main {
background-color: $mono-90;
height: 100%;
min-height: 1000px;
@media screen and (max-width: map_get($grid-breakpoints, 'md')) {
// Reset the min-height here, because we no longer have the sticky search bar.
min-height: 450px;
}
@media
(max-width: map_get($grid-breakpoints, 'lg')),
(max-width: map_get($grid-breakpoints, 'lg')) and (orientation: landscape){
background-color: lightgreen;
}
@media
(max-width: map_get($grid-breakpoints, 'md')),
(max-width: map_get($grid-breakpoints, 'md')) and (orientation: landscape){
background-color: lightblue;
}
@media
(max-width: map_get($grid-breakpoints, 'sm')),
(max-width: map_get($grid-breakpoints, 'sm')) and (orientation: landscape){
background-color: lightcoral;
}
}
编辑:根据@Godwin 的建议,我将我的@media 查询简化为:
main {
background-color: $mono-90;
height: 100%;
min-height: 1000px;
@media screen and (max-width: map_get($grid-breakpoints, 'md')) {
// Reset the min-height here, because we no longer have the sticky search bar.
min-height: 450px;
}
@media screen and (max-width: map_get($grid-breakpoints, 'lg')) {
background-color: lightgreen;
}
@media screen and (max-width: map_get($grid-breakpoints, 'md')) {
background-color: lightblue;
}
@media screen and (max-width: map_get($grid-breakpoints, 'sm')) {
background-color: lightcoral;
}
}
但是,它不适用于 iPad Landscape (1024x768)。我不希望它在笔记本电脑上显示,但确实希望它在横向位置的 iPad 上显示。
最佳答案
However, it doesn't work on iPad Landscape (1024x768). I don't want it to show on Laptops, but do want it to show on iPads in Landscape position.
我不确定你用它定义了什么,因为你没有在你的例子中隐藏任何东西所以我要引用:
What I am trying to do, ultimately, is have styles that are applied when the user is in landscape on a tablet, or phone.
Orientation on MDM定义如下:
This value does not correspond to actual device orientation.
它仅指示视口(viewport)是处于横向(显示器宽度大于高度)还是纵向(显示器高度大于宽度)模式。
您说横向的 iPad 分辨率为 1024x768,因此要以横向模式定位 iPad 或手机,您可以设置一个媒体查询,以最大宽度为 1024px 且处于横向模式的所有设备为目标(显示器宽度大于高度):
main {
background-color: grey;
height: 100%;
min-height: 1000px;
width: 100%;
@media screen and (max-width: 1024px) and (orientation: landscape) {
background-color: lightblue;
}
}
您可以在 this codepen 上查看示例.
如果您的视口(viewport)宽度大于 1024 像素,main 元素无论如何都将是灰色的。
如果您调整浏览器窗口的大小,使视口(viewport)的宽度等于或小于 1024 像素,并且考虑横向视口(viewport)(显示器宽度大于高度),例如横向模式下的 iPad (1024x768) ,媒体查询将触发并应用蓝色背景:
如果您将浏览器窗口的大小调整为仍然有一个等于或小于 1024 像素但高度大于宽度的视口(viewport),则该视口(viewport)不再被视为处于横向模式,而是切换为纵向模式。此时,不再触发媒体查询,我们回退到灰色元素:
所以关于你的问题,这个例子是一个媒体查询,用于将样式应用于横向模式下使用平板电脑或手机的用户。
关于html - 逗号分隔的媒体查询列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38336336/
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我正在使用ruby1.9解析以下带有MacRoman字符的csv文件#encoding:ISO-8859-1#csv_parse.csvName,main-dialogue"Marceu","Giveittohimóhe,hiswife."我做了以下解析。require'csv'input_string=File.read("../csv_parse.rb").force_encoding("ISO-8859-1").encode("UTF-8")#=>"Name,main-dialogue\r\n\"Marceu\",\"Giveittohim\x97he,hiswife.\"\
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我正在学习http://ruby.railstutorial.org/chapters/static-pages上的RubyonRails教程并遇到以下错误StaticPagesHomepageshouldhavethecontent'SampleApp'Failure/Error:page.shouldhave_content('SampleApp')Capybara::ElementNotFound:Unabletofindxpath"/html"#(eval):2:in`text'#./spec/requests/static_pages_spec.rb:7:in`(root)'