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.pswp.cn/news/275967.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275967.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275967.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

怎么查看和獲取SQL Server實例名

查看實例名時可用 1、服務—SQL Server(實例名)&#xff0c;默認實例為(MSSQLSERVER) 或在連接企業管理時-查看本地實例 2、通過注冊表 HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SQL Server/InstalledInstance 3、用命令 sqlcmd/osql sqlcmd -L sqlcmd -Lc osql -L 獲…

30萬手表推薦_今年六十歲生日,兒子說要送只30萬的手表,請問有哪些推薦?...

關注腕表部落&#xff0c;盡享腕表生活一位讀者向筆者提出這樣一個問題&#xff1a;今年六十歲生日&#xff0c;兒子說要送只30萬的手表&#xff0c;請問有哪些推薦&#xff1f;首先要恭喜這位老爺子&#xff0c;一來是生日馬上就要到了&#xff0c;二來是還有這么孝順而且慷慨…

關注博客

https://blog.51cto.com/oldboyhttps://blog.51cto.com/yw666轉載于:https://blog.51cto.com/11732716/2348556

寫 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;去學習或放…

開發中的問題——環境相關

開始了解Android差不多兩周了&#xff0c;作為一名.net開發者&#xff0c;首次接觸Java類的技術&#xff0c;免不了會碰到一些問題&#xff0c;開博的第一篇就來說說自己遇到的問題以及一些感受。關于Android開發環境的搭建&#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…

c++ 整數取反_c++ 取反運算符“~”

取反符將二進制表示的數字中的0變為1, 1變為0但是需要注意的是c中對int型進行取反操作時&#xff0c;將前面的前導0也進行了取反(int型變量為32bit)。比如1的二進制表示是00000000 00000000 00000000 00000001~(00000000 00000000 00000000 00000001) 11111111 11111111 11111…

第五課 路由之初識路由

1.路由快速入門 1.1 概念 是指把數據從一個地方傳送到另一個地方的行為和動作&#xff0c;而路由器&#xff0c;正是執行這種行為動作的機器。它的英文名稱為Router&#xff0c;是一種連接多個網絡或者網段的網絡設備&#xff0c;它能將不同網絡或者網段之間的數據信息進行“翻…

Console Snacks[摘自Advanced Rails Recipes]

1. Write Console Methods在~/.irbrc定義ActvieRecord::Base.connection.select_all方法1.# ~/.railsrc2.def sql(query)3.ActiveRecord::Base.connection.select_all(query)4.end1.# ~/.irbrc2.if ENV[RAILS_ENV]3.load File.dirname(__FILE__) /.railsrc4.end這樣就可以在直…

如何使用 React 和 React Hooks 創建一個天氣應用

大家好&#xff0c;我是若川&#xff08;點這里加我微信 ruochuan12&#xff0c;長期交流學習&#xff09;。今天推薦一個練手的React項目&#xff0c;創建天氣應用&#xff0c;相信很快能看完。昨天發送書掉粉18人&#xff0c;是我沒想到的&#xff0c;送書一般是出版社按閱讀…