flex如何做响应式设计_响应式设计-您做错了!

flex如何做响应式设计

Responsive design is not just about the web that automatically adjusts to different screen resolutions and resizeable images, but designs that are crucial for web performance.

自适应设计不仅涉及可自动适应不同屏幕分辨率和可调整大小图像的网络,而且对于网络性能至关重要。

In my short journey of working with HTML and CSS, interactions with other developers, I found out that these two words — flexibility and responsiveness have often been used interchangeably to illustrate the core of responsive web design.

在使用HTML和CSS以及与其他开发人员进行交互的短暂旅程中,我发现灵活性和响应性这两个词经常互换使用,以说明响应式Web设计的核心。

Ethan Marcotte coined the term responsive web design and defined it to mean fluid/flexible images/media queries in a May 2010 article in A List Apart.

Ethan Marcotte在2010年5月的A List Apart中的一篇文章中创造了“ 响应式网页设计”一词,并将其定义为表示流畅/灵活的图像/媒体查询。

There are lots of great articles out there about responsive design, what it is, key concepts, principles, and great philosophies surrounding it. In this article, we will not spend time on those but rather look at great techniques that allow us to implement responsive web design more efficiently.

关于响应式设计,它是什么,关键概念,原理以及围绕它的伟大哲学,有很多很棒的文章。 在本文中,我们将不会花时间在这些上,而会研究使我们能够更有效地实现响应式Web设计的出色技术。

Below are the basic responsive design principles, I will tackle the first two.

以下是基本的响应式设计原则 ,我将解决前两个原则

1. Fluid Grids and Layouts: allow contents to easily adapt to the current viewport width used to browse the website. Uses % rather than px for all layout-related lengths.

1. 流体网格和布局:允许内容轻松适应当前用于浏览网站的视口宽度。 对于所有与布局相关的长度,请使用%而不是px。

2. Flexible/Responsive Images: images behave differently than text content, and so we need to ensure that they also adapt nicely to the current viewport.

2. 灵活/响应的图像:图像的行为与文本内容不同,因此我们需要确保它们也能很好地适应当前视口。

3. Media Queries: the ability to change styles on certain viewport widths(breakpoints), allowing us to create a different version of our website for different widths.

3. 媒体查询:能够在某些视口宽度(断点)上更改样式的功能,使我们可以为不同的宽度创建网站的不同版本。

流体网格和布局: (Fluid Grids and Layouts:)

在项目中应如何以及为什么使用“ rem”单元。 (How and Why You Should Use ‘rem’ Units in Your Projects.)

I was so amazed when I realized I can simply change the width, height, padding, margin, and literary any element you could apply pixel unit to with just one adjustment on my media query at the same time instead of writing hundreds on lines of codes in media queries. It’s amazing, yea right!

当我意识到自己只需更改媒体查询的宽度,高度,填充,边距和文学内容即可,而对我的媒体查询只需一次调整,而无需在代码行上编写数百个内容时,我感到非常惊讶在媒体查询中。 太神奇了,是的!

Image for post
How one simple change of the global font-size affects every element on the page.
全局字体大小的一次简单更改如何影响页面上的每个元素。

Now let’s see how this awesome technique works. First understanding how the rem unit works is the key to mastering this simple yet powerful technique.

现在,让我们看看这项出色的技术是如何工作的。 首先了解rem单元的工作方式是掌握此简单而强大的技术的关键。

The rem unit is always in relation to the root font size, so if we set the root font size, other measurements can easily be changed on our page.

rem单位始终与根字体大小有关,因此,如果我们设置根字体大小,则可以在页面上轻松更改其他尺寸。

html {font-size: 10px;}

Now, note the default browser font-size is 16px but we are setting ours to 10px for easy calculations. So 10px equals 1rem, 45px will be 4.5rem. All we have to do is simply divide all the pixels by 10 and that’s our rem.

现在,请注意默认浏览器的字体大小为16px,但为了方便计算,我们将其设置为10px。 因此10px等于1rem,45px将为4.5rem。 我们要做的就是简单地将所有像素除以10,这就是我们的rem。

The only problem is by setting our root font-size to 10px we override the browser font size setting. Some users with bad sight do manually change their browser font size settings to have a bigger font size.

唯一的问题是,通过将我们的根字体大小设置为10px,我们将覆盖浏览器字体大小设置。 一些视力不好的用户会手动更改其浏览器的字体大小设置,以使其具有更大的字体大小。

Setting the 10px font-size on our root removes the ability for these people to see our website properly because they can no longer change the default font size.

在我们的根目录上设置10px字体大小将使这些人无法正确查看我们的网站,因为他们无法再更改默认字体大小。

It will remain 10 pixels no matter the user’s default font-size, this is a bad practice. That is why we’re going to set our font-size to a percentage, which will translate to a percentage of the font-size given by the browser.

无论用户的默认字体大小如何,它都将保留10个像素,这是一个不好的做法。 这就是为什么我们要将字体大小设置为一个百分比,这将转换为浏览器给定的字体大小的百分比。

We are counting on the fact that the default browser font-size is usually 16px, and that remains the absolute default.

我们指望这样的事实,默认浏览器字体大小通常为16px,并且仍然是绝对默认值。

So let’s do simple math, if we put 100% here, this would mean that the root font size is 16 pixels.

因此,让我们做一个简单的数学运算,如果我们将100%放在此处,这意味着根字体大小为16像素。

All we have to do is to divide what we want which is 10, by 16. 10/16 * 100 = 62.5%.

我们要做的就是将我们想要的10除以16。10/ 16 * 100 = 62.5%。

Then that will translate to 10pixels which is what we want.

然后,这将转化为我们想要的10像素。

html {font-size: 62.5%;}

This technique is widely used in the CSS developer community because it’s so simple and yet so powerful.

该技术非常简单,但功能强大,因此在CSS开发人员社区中得到了广泛使用。

灵活/响应的图像 (Flexible/Responsive Images)

The main philosophy behind responsive images is serving the right image to the right screen-size and device using different techniques in HTML or CSS so users do not have to download images that are way too large for their devices.

响应式图像的主要原理是使用HTML或CSS中的不同技术将正确的图像提供给合适的屏幕尺寸和设备,因此用户不必下载对于他们的设备而言太大的图像。

It’s okay to have flexible images that scale nicely with the viewport width, but responsive images take things to a whole new level and that’s because responsive images are not just an aspect of responsive design but even more importantly of web performance.

可以使弹性图像与视口宽度很好地缩放是可以的,但是响应式图像将事情带到了一个全新的高度,这是因为响应式图像不仅是响应式设计的一个方面,而且更重要的是Web性能。

As developers, we really have a responsibility here and responsive images help us solve these problems.

作为开发人员,我们确实有责任,响应式图像可以帮助我们解决这些问题。

While it may be okay to send a 1mb image for the hero section to a desktop computer, it is not okay to do that to a phone, which may have a slow or expensive data plan somewhere in the world like where I am, Nigeria.

虽然可以将英雄部分的1mb图像发送到台式计算机,但不能将其发送到电话,因为电话可能在世界上某个地方(如我所在的地方,尼日利亚)的数据计划缓慢或昂贵。

So instead of sending 1mb to whatever device is consuming the page, it makes more sense to send the 1mb image to a device with a large screen that needs the image and a much smaller version of the image to a device with a small screen that doesn’t need such a large image anyway. Not many developers out there know and take this even seriously.

因此,将1mb图像发送到需要该图像的大屏幕设备,将较小版本的图像发送到一个没有屏幕的小设备,而不是将1mb发送到占用该页面的任何设备,无论如何都不需要这么大的图像。 没有很多开发人员知道并认真对待这一点。

合理地说,主要有三个用例。 (There are mainly three use cases where it makes sense.)

  1. Resolution switching: Here all we do is to serve up the same image for a smaller screen but with a smaller resolution. So basically, the same image but a smaller version for a device that doesn’t need such a big image.

    分辨率切换:这里我们要做的只是在较小的屏幕上以较小的分辨率提供相同的图像。 因此,基本上,相同的图像但较小的版本适用于不需要这么大图像的设备。

Image for post
Screenshot from Jonas Schmedtmann Advanced CSS and SASS course
Jonas Schmedtmann高级CSS和SASS课程的屏幕截图

In the example below, we use the width descriptor to tell the browser the width of the image and it automatically decides which image to download

在下面的示例中,我们使用宽度描述符来告诉浏览器图像的宽度,并自动决定要下载哪个图像

<img srcset=”img/design-1.jpg 300w, img/design-1-large.jpg 1000w” alt=”design” >

But width descriptor is not enough to decide which images to choose, so we add sizes attribute. Sizes are used to inform the browser about the approximate width of the image at different viewport width.

但是宽度描述符不足以决定选择哪个图像,因此我们添加了sizes属性。 大小用于告知浏览器有关不同视口宽度的图像的近似宽度。

<img srcset=”img/design-1.jpg 300w, img/design-1-large.jpg 1000w” alt=”design” sizes=”(max-width:900px) 20vw”, (max-width:600px) 30vw, 300px” >

It’s a good practice to have a fallback, just in case the browser does not understand ‘srcset’.

如果浏览器不了解“ srcset”,则最好进行回退。

<img srcset=”img/design-1.jpg 300w, img/design-1-large.jpg 1000w” alt=”design” sizes=”(max-width:900px) 20vw”, (max-width:600px) 30vw, 300px” ><img src=”img/design-1-large.jpg” alt="design">

2. Density switching: This is a special case of resolution switching but where the screen size does not matter but a screen pixel density does instead. Pixel density is the number of pixels found in an inch or a centimeter. Now, what matters to us is what there are low-resolution screens and high-resolution screens.

2. 密度切换 :这是分辨率切换的一种特殊情况,但是屏幕尺寸无关紧要,而屏幕像素密度却是。 像素密度是以英寸或厘米为单位的像素数。 现在,对我们而言重要的是低分辨率屏幕和高分辨率屏幕。

Image for post
Screenshot from Jonas Schmedtmann Advanced CSS and SASS course
Jonas Schmedtmann高级CSS和SASS课程的屏幕截图

Low-resolution screens are just typical PC screens, if we say an image is 100 pixels high, they will actually use 100 physical pixels on the screen to display these 100 pixels that we specified.

低分辨率屏幕只是典型的PC屏幕,如果我们说一幅图像高100像素,它们实际上将使用屏幕上的100个物理像素来显示我们指定的这100个像素。

High-resolution screens are the ones found in all modern smartphones and even some computers already have them, like the MacBook with retina displays. These are high-resolution screens and can be called 2x screens because they use two physical pixels to display one pixel of our design. This implies that if we want our image to look sharp on high-resolution displays we should use 2x the image size we are serving the low-resolution displays.

高分辨率屏幕是所有现代智能手机中都可以使用的屏幕,甚至有些计算机已经安装了高分辨率屏幕,例如带有视网膜显示屏的MacBook。 这些是高分辨率屏幕,可以称为2x屏幕,因为它们使用两个物理像素来显示我们设计的一个像​​素。 这意味着,如果我们希望图像在高分辨率显示器上看起来清晰,则应使用供低分辨率显示器使用的图像大小的2倍。

In the example below, we use the density descriptor to tell the browser the density of the image and it automatically decides which image to download

在下面的示例中,我们使用密度描述符来告诉浏览器图像的密度,并自动决定要下载哪个图像

<img srcset=”img/logo-1x.png 1x, img/logo-2x.png 2x” alt=”logo” >

3. Art Direction: This happens when you don’t just want to serve the same image but in a smaller resolution, but a whole different image for different screen sizes.

3. 艺术指导:当您不只是希望以较小的分辨率提供相同的图像,而是针对不同的屏幕尺寸提供完全不同的图像时,就会发生这种情况。

Image for post
Screenshot from Jonas Schmedtmann Advanced CSS and SASS course
Jonas Schmedtmann高级CSS和SASS课程的屏幕截图

In this example, we see if the conditions of images inside the <source> are not met, the device will be forced to use the image inside the <img> tag.

在此示例中,我们看到如果<source>内部的图像条件不满足,设备将被迫使用<img>标签内部的图像。

<picture><source srcset=”img/logo-small-1x.png 1px, img/logo-small-2x.png 2x” media=”(max-width: 600px)”><img srcset=”img/logo-1x.png 1x, img/logo-2x.png 2x” alt=”logo” ></picture>

In conclusion, resolution and density switching is when you want to serve the same image but with different resolutions. And art directions is when you want to serve a completely different image.

总之,分辨率和浓度切换是当您要提供相同的图像但具有不同的分辨率时。 而艺术指导就是您要提供完全不同的图像。

Using rem units in my daily web design projects has helped reduce the lines of codes I write in media queries and has given me so much control in my responsive design experience.

在我的日常Web设计项目中使用rem单位有助于减少我在媒体查询中编写的代码行,并在响应式设计经验中给予了我太多控制。

If you want to dive deeper into these concepts, you should take a look at the Advanced CSS and SASS… course by Jonas Schmedtmann, I give all the credits to him.

如果您想更深入地研究这些概念,则应该看看Jonas Schmedtmann的Advanced CSS and SASS…课程 ,我将所有功劳归功于他。

Image for post
UX Para Minas Pretas (UX For Black Women), a Brazilian organization focused on promoting equity of Black women in the tech industry through initiatives of action, empowerment, and knowledge sharing. Silence against systemic racism is not an option. Build the design community you believe in.UX Para Minas Pretas (UX For Black Women),这是一个巴西组织,致力于通过采取行动,赋权和知识共享的举措来促进科技行业中的黑人女性平等。 对系统性种族主义保持沉默是不可行的。 建立您相信的设计社区。

翻译自: https://uxdesign.cc/responsive-design-youre-doing-it-wrong-d88a52e1d5f7

flex如何做响应式设计

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/275967.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

30万手表推荐_今年六十岁生日,儿子说要送只30万的手表,请问有哪些推荐?...

关注腕表部落&#xff0c;尽享腕表生活一位读者向笔者提出这样一个问题&#xff1a;今年六十岁生日&#xff0c;儿子说要送只30万的手表&#xff0c;请问有哪些推荐&#xff1f;首先要恭喜这位老爷子&#xff0c;一来是生日马上就要到了&#xff0c;二来是还有这么孝顺而且慷慨…

写 Node.js 代码,从学会调试开始

大家好&#xff0c;我是若川&#xff08;点这里加我微信 ruochuan12&#xff0c;长期交流学习&#xff09;。今天推荐这篇调试文章&#xff0c;熟悉我的读者都知道我写的源码文章都多次强调要调试&#xff0c;而且写了调试方法。点击下方卡片关注我、加个星标&#xff0c;或者查…

创建用户友好的表单

Forms are a common way to engage with users and could be a user’s first impression of your product. Since forms aren’t always the user’s favourite thing, it is essential to make filling out forms as easy as possible. Let’s go over a few tips for creati…

细节决定成败—关于.net的.dll.refresh文件

一直在做.net的项目&#xff0c;c/s的、b/s的&#xff0c;一直没有注意这个东西。众所周知&#xff0c;.net的程序生成后会在bin目录下生成.dll文件&#xff0c;而.dll.refresh这个文件从何而来呢&#xff1f;那天无聊地google了下才知&#xff0c;这个东东是在你的项目中引用第…

环境在c盘_如何给女朋友解释为什么 Windows 上面的软件都把自己安装在 C 盘

本文经授权转载自漫画编程(ID&#xff1a;mhcoding)周末&#xff0c;我在家里面看电视&#xff0c;女朋友正在旁边鼓捣她的电脑&#xff0c;但是好像并不是很顺利&#xff0c;于是就有了以下对话。计算机存储我们使用的计算机中&#xff0c;保存信息的介质有两类&#xff1a;一…

能让你纵享丝滑的SSR技术,转转这样实践

大家好&#xff0c;我是若川&#xff08;点这里加我微信 ruochuan12&#xff0c;长期交流学习&#xff09;。今天推荐这篇图文并茂的SSR技术文章。这是江西前端群里一个小伙伴的文章。群里小伙伴很多都在知名大厂&#xff0c;但他们都很低调。点击下方卡片关注我、加个星标&…

魅族魅蓝mirror简单打开usb调试模式的步骤

经常我们使用安卓手机链接电脑的时候&#xff0c;或者使用的有些应用比如我们企业营销团队经常使用的应用引号精灵&#xff0c;以前使用的老版本就需要开启USB调试模式下使用&#xff0c;现经常新版本不需要了&#xff0c;如果手机没有开启USB调试模式&#xff0c;电脑则无办法…

hp-ux 单用户 启动_UX备忘单:搜索与浏览

hp-ux 单用户 启动重点 (Top highlight)When designing search results and interest sites, you have to keep in mind what ‘mode’ your user is in. Are they in ‘searching mode’ or ‘browsing mode’? This will help you determine how to design your platform to…

细数开源历史上的九个重大事件

开放源码&#xff08;开源&#xff09;的精神在于使用者可以使用、复制、散布、研究和改进软件。这可以追溯到20世纪60年代&#xff0c;至今已有半个世纪了。伯乐在线-职场博客的这篇文章将列举开源历史上的九大重要事件。虽然本文不是专门对开源产品&#xff0c;但还是说到了一…

有赞大数据平台安全建设实践

一、概述 在大数据平台建设初期&#xff0c;安全也许并不是被重点关注的一环。大数据平台的定位主要是服务数据开发人员&#xff0c;提高数据开发效率&#xff0c;提供便捷的开发流程&#xff0c;有效支持数仓建设。大数据平台的用户都是公司内部人员。数据本身的安全性已经由公…

请先设置tkk_理光MP2014扫描至文件夹的设置方法

理光旗下的2014系列入门级A3黑白复印机市场保有量较大&#xff0c;该系列机型加装M16网卡后可以方便的实现扫描至文件夹功能&#xff0c;经常有客户咨询该机型的扫描设置方法&#xff0c;下面我就以MP2014D为例来演示一下该机型的SMB扫描设置方法&#xff1a;首先是在电脑上建立…

听说现在都考这些React面试题

大家好&#xff0c;我是若川。最近刷脉脉看见圈里都在聊面试&#xff0c;吐槽最多的还是万年考点 React 和 Vue。不过关于两者的比较似乎有点针尖对麦芒的赶脚。确实&#xff0c;面试的偏重点往往映射公司对该框架的重视程度&#xff0c;但也不能一概而论&#xff0c;去学习或放…

荒岛余生为什么没有打开包裹_您会带到荒岛什么办公桌设置?

荒岛余生为什么没有打开包裹Throughout life, you experience a lot of desks and a lot of desk setups. Real or virtual, at the office or at home, temporal or permanent — just a way to call it, nothing is permanent— a big one with a great office view or a sma…

第五课 路由之初识路由

1.路由快速入门 1.1 概念 是指把数据从一个地方传送到另一个地方的行为和动作&#xff0c;而路由器&#xff0c;正是执行这种行为动作的机器。它的英文名称为Router&#xff0c;是一种连接多个网络或者网段的网络设备&#xff0c;它能将不同网络或者网段之间的数据信息进行“翻…

如何使用 React 和 React Hooks 创建一个天气应用

大家好&#xff0c;我是若川&#xff08;点这里加我微信 ruochuan12&#xff0c;长期交流学习&#xff09;。今天推荐一个练手的React项目&#xff0c;创建天气应用&#xff0c;相信很快能看完。昨天发送书掉粉18人&#xff0c;是我没想到的&#xff0c;送书一般是出版社按阅读…

拟态防御_纯素食汉堡的拟态

拟态防御If people are so against the idea of pigs and chickens being chopped up why would they want to buy fake bacon with realistic visual streaks of pork fat, or soy meat that tries to replicate the streaky texture of cooked chicken flesh? Surely these …

delphi 算术溢出解决方法_性能优化系列:JVM 内存划分总结与内存溢出异常详解分析...

前言那些使用过 C 或者 C 的读者一定会发现这两门语言的内存管理机制与 Java 的不同。在使用 C 或者 C 编程时&#xff0c;程序员需要手动的去管理和维护内存&#xff0c;就是说需要手动的清除那些不需要的对象&#xff0c;否则就会出现内存泄漏与内存溢出的问题。如果你使用 J…

微信小程序如何发送 http 请求

2019独角兽企业重金招聘Python工程师标准>>> 为什么要使用云函数发送 http 请求小程序云函数5 个可信域名不受限制需要备案无需备案在一些特殊情境, 比如域名没有备案或域名 5 个以上就需要使用云函数发送 HTTP 请求了. 如何使用云函数发送 HTTP 请求? 在云函数中能…

H5 页面列表缓存方案

大家好&#xff0c;我是若川&#xff08;点这里加我微信 ruochuan12&#xff0c;长期交流学习&#xff09;。今天给大家介绍一下关于h5页面的列表缓存方案。感谢屏幕前的你一直关注着我。点击下方卡片关注我、加个星标&#xff0c;或者查看源码等系列文章。学习源码整体架构系列…

不只是coding_不只是外表

不只是coding“We just need it to look more professional…”“我们只需要看起来更专业...” “We don’t have the graphic expertise you do…”“我们没有您所需要的图形专业知识……” “I just don’t know how to make it look good…”“我只是不知道如何使它看起来…