網頁開發中,打造引人入勝的網頁體驗至關重要。使用CSS對圖像進行樣式設置是這一努力的核心。本指南深入探討了CSS,著重介紹了"aspect-ratio"、"object-fit"和"object-position"這三個屬性,以幫助設計師創建視覺上引人入勝的網頁項目。
在網頁設計領域,圖像不僅僅是視覺元素;它們是強大的故事講述者和吸引注意力的元素。打造一個引人入勝且視覺上令人愉悅的網站往往取決于您對圖像樣式的掌握程度。CSS提供了許多工具來實現這一目的,但在本指南中,我們將專注于三個基本的CSS屬性,它們真正能夠改變您的圖像樣式設計:"aspect-ratio"、"object-fit"和"object-position"。
CSS屬性'aspect-ratio'允許您設置圖像的寬高比。這意味著無論視口大小如何變化,圖片都會自動調整到為其定義的縱橫比。寬高比用于計算自動大小和其他布局操作。
為了使寬高比生效,至少需要指定一個盒子的尺寸。如果沒有提供寬度或高度值,寬高比將不會產生任何影響。
語法
aspect-ratio: 4 / 2;
aspect-ratio: 1;
/* fallback to 'auto' for replaced elements */
aspect-ratio: auto 3/4;
aspect-ratio: 9/6 auto;
/* Global values */
aspect-ratio: inherit;
aspect-ratio: initial;
aspect-ratio: revert;
aspect-ratio: revert-layer;
aspect-ratio: unset;
aspect-ratio的值
"object-fit"屬性指定了元素如何響應其內容框的高度和寬度。它被設計用于與"object-position"屬性一起使用,用于照片、電影和其他可嵌入的媒體類型。當單獨使用"object-fit"時,我們可以通過對其在框內的壓縮或拉伸方式進行無縫控制,從而裁剪內聯圖片。
語法
object-fit: contain;
object-fit: fill;
object-fit: cover;
object-fit: scale-down;
object-fit: none;
/* Global values */
object-fit: inherit;
object-fit: initial;
object-fit: revert;
object-fit: revert-layer;
object-fit: unset;
object-fit的值
當使用"object-fit"屬性,比如"object-fit: cover;"時,通過裁剪一些圖像,圖像會放大以適應父容器。CSS屬性"object-position"用于對齊包含在其中的任何選定元素,比如圖片<img>。
img {
object-position: right top;
}
語法
屬性接受兩個值,第一個值用于水平對齊,第二個值用于垂直對齊。這兩個值可以用百分比(%)、像素(px)和CSS注冊的關鍵詞(top、left、right、bottom和center)來定義。
/* Positional values */
object-position: 50% 50%; /* default position */
object-position: right bottom;
object-position: 20px 95px;
object-position: center 20px; /* mix and match */
object-position: 60% top; /* mix and match */
/* Global values */
object-position: inherit;
object-position: initial;
object-position: unset;
在網頁開發的世界中,創造引人入勝的網頁體驗始終是首要任務。在這一努力的核心,是使用CSS進行圖像樣式設置的藝術,這是設計師們在打造視覺上引人入勝的網頁項目時必備的關鍵技能。在本指南中,我們探索了三個重要的CSS屬性:aspect-ratio、object-fit和object-position,這些屬性使開發人員能夠將圖像樣式提升到一個新的水平。
寬高比的概念是CSS的相對較新的補充,它允許設計師定義圖像的寬高比,確保它們能夠無縫適應不同的視口大小。這個屬性為響應式設計提供了強大的工具,增強了整體用戶體驗。
另一方面,object-fit提供了對圖像在其內容框中的行為精確控制的能力。無論您需要拉伸、縮放還是保持寬高比,對象適應都可以實現您所需的視覺效果。
為了補充object-fit,object-position屬性允許設計師在容器中精確定位圖像,增加了一層定制化,可以極大地提升網站的美觀效果。
SS是Cascading Style Sheets的縮寫,一般翻譯為層疊樣式表,是用來表現HTML(標準通用標記語言的一個應用)或XML(標準通用標記語言的一個子集)等文件樣式的計算機語言。
CSS不僅可以靜態的修飾網頁,還可以配合各種腳本語言動態地對網頁各元素,能夠對網頁中元素位置的排版進行像素級精確控制等等。
作為前端開發者,你對CSS一定不會陌生。1994年,CSS首次被提出,到目前為止已經過去了近30年。
前幾天,一份CSS年度報告出爐,讓我們一起看看CSS的最新動態吧。
本次報告受訪人員主要來自美國、俄羅斯、加拿大、西班牙、荷蘭、波蘭和澳大利亞等國家,調查人員分布在世界各地。
本次調查的受訪者絕大多數是有5-20年工作經驗的人員。年齡在24-34歲之間,這也是大部分技術開發者的年齡段。
根據分類劃分,顯示了各種特性的采用率。外圈的尺寸代表了了解這個特性的用戶數量, 而內圈的尺寸代表了實際使用這個特性的用戶數量。
受訪者更喜歡使用什么布局方式進行元素布局呢?在今年的調查中,Grid上升的趨勢依然很快。Flex布局是一維布局,Grid布局是二維布局。Flex布局一次只能處理一個維度上的元素布局,一行或者一列。Grid布局是將容器劃分成了“行”和“列”,產生了一個個的網格,有不少人認為,Grid比Flex更強大。
Shape似乎一直不溫不火,相比2020年的調查,Shape的使用程度有所下降。object-fit看起來受到了受訪者的歡迎,object-fit CSS屬性指定可替換元素的內容應該如何適應到其使用的高度和寬度確定的框,輕松地解決了圖片的適配問題。
使用者通常都如何進行頁面交互呢?pointer-events 最常用,pointer-events CSS屬性指定在什么情況下 (如果有) 某個特定的圖形元素可以成為鼠標事件的target。CSS滾動捕捉可以用來創建一個可滾動的容器,防止滾動時出現尷尬的滾動位置,創建更好的滾動體驗。
關于CSS框架,調查顯示,2021年Tailwind CSS的滿意度和關注度最高,而使用度和認知度最高的是Bootstrap。
常用的工具函數庫有Prettier 、Autoprefixer 、Stylelint 、PurgeCSS、 cssnano和PurifyCSS。
在使用環境方面,受訪者最常在Chrome瀏覽器中進行測試,CSS 已經越來越趨于多終端設備化,電腦桌面、智能手機和平板是主力軍。
這份調查結果和你的CSS使用習慣類似嗎?你對CSS有新的認知了嗎?歡迎討論哦。
secure boot 和FIT Image是前段時間接觸到的,其實早就該總結下了,奈何懶癌犯了,拖了好久才寫出來。
之前也有人問我,工作后最大的感受是什么?我的回答是:“快速學習”。
就嵌入式來講,大多數應屆生在校期間可能都沒做過完整的項目,僅憑在校期間學習的內容很難勝任公司的要求。
就底層驅動來講,雖然我之前也學習過韋東山老師的上s3c2440的課程,但是到了公司才發現,這些內容其實都已經過時了。
但并不是說這些內容都沒有必要去學習了。在學習的過程中,認為最重要的是培養我們的自學能力。
很多初學者在剛開始學習時,可能就敗在了搭建環境上。搭建環境時遇到問題不知道怎么辦?
我們日常開發中遇到的90%的問題,在網上都有人遇到過,也有相應的解決辦法。學會利用bing,google,stackoverflow等搜索工具是一項很重要的技能。
如果遇到了網上沒有的問題怎么辦?軟件問題要先搞清楚原理,再去看代碼邏輯。硬件問題看官方手冊。像Linux kernel,ARM等都提供了完善的手冊,大部分問題在手冊中都有相應說明。
好了,扯遠了。下面回歸正題。
本文主要介紹了FIT Image起源,制作方法,its的語法結構,bootm 啟動FIT Image的方式。
本文這篇文章是對后面介紹的secure boot做鋪墊。ARMv8 secure boot一種實現的方式就是利用了FIT Image的特性。
內核經過編譯后,會生成一個elf的可執行程序,叫vmlinux,這個就是原始的未經任何處理加工的原版內核elf文件。不過,最終燒寫在嵌入式設備上的并不是這個文件。而是經過objcopy工具加工后的專門用于燒錄的鏡像格式Image。
原則上Image就可以直接被燒錄到Flash上進行啟動執行,但linux的內核開發者覺得Image還是太大了,因此對Image進行了壓縮,并且在Image壓縮后的文件的前端附加了一部分解壓縮代碼,構成了一個壓縮格式的鏡像文件就叫zImage。
解壓的時候,通過zImage鏡像頭部的解壓縮代碼進行自解壓,然后執行解壓出來的內核鏡像。
Uboot要正確啟動Linux內核,就需要知道內核的一些信息,比如鏡像的類型(kernel image,dtb,ramdisk image),鏡像在內存的位置,鏡像的鏈接地址,鏡像文件是否有壓縮等等。
Uboot為了拿到這些信息,發明了一種內核格式叫uImage,也叫Legacy uImage。uImage是由zImage加工得到的,uboot中有一個工具mkimage,該工具會給zImage加一個64字節的header,將啟動內核所需的信息存儲在header中。uboot啟動后,從header中讀取所需的信息,按照指示,進行相應的動作即可。
header格式可以參考:include/image.h。mkimage源碼在tools/mkimage
有了Legacy uImage后,為什么又搞出來一個FIT uImage呢?
在Linus Torvalds 看來,內核中arch/arm/mach-xxx充斥著大量的垃圾代碼。因為內核并不關心板級細節,比如板上的platform設備、resource、i2c_board_info、spi_board_info等等。大家有興趣可以看下s3c2410的板級目錄,代碼量在數萬行。
因此,ARM社區引入了Device Tree,使用Device Tree后,許多硬件的細節可以直接透過它傳遞給Linux,而不再需要在kernel中進行大量的冗余編碼。
為了更好的支持單個固件的通用性,Uboot也需要對這種uImage固件進行支持。FIT uImage中加入多個dtb文件 和ramdisk文件,當然如果需要的話,同樣可以支持多個kernel文件。
內核中的FDT全程為flattened device tree,FIT全稱叫flattened image tree。FIT利用了Device Tree Source files(DTS)的語法,生成的Image文件也和dtb文件類似(稱作itb)。
這樣的目的就是能夠使同一個uImage能夠在Uboot中選擇特定的kernel/dtb和ramdisk進行啟動了,達成一個uImage可以通用多個板型的目的。
制作FIT Image需要用到兩個工具,mkimage和的dtc。dtc要導入到環境變量$PATH中,mkimage會調用dtc。
mkimage的輸入為 image source file,它定義了啟動過程中image的各種屬性,擴展名為.its。its只是描述了Image的屬性,實際的Image data 是在uImage中,具體路徑由its指定。
如下是kernel 的its文件,后面會介紹各項內容的含義。
/*
* Simple U-Boot uImage source file containing a single kernel
*/
/dts-v1/;
/ {
description="Simple image with single Linux kernel";
#address-cells=<1>;
images {
kernel@1 {
description="Vanilla Linux kernel";
data=/incbin/("./vmlinux.bin.gz"); # Image data 具體路徑
type="kernel";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="crc32";
};
hash@2 {
algo="sha1";
};
};
};
configurations {
default="config@1";
config@1 {
description="Boot Linux kernel";
kernel="kernel@1";
};
};
};
mkimage的輸出是一個后綴為.itb的二進制文件,包含了所有需要的數據(kernel,dtb,ramdisk)。itb文件制作好之后,就可以直接加載到嵌入式設備上,通過bootm命令啟動。
總結下制作FIT Image的4個必要文件:
/ o image-tree
|- description="image description"
|- timestamp=<12399321>
|- #address-cells=<1>
|
o images
| |
| o image@1 {...}
| o image@2 {...}
| ...
|
o configurations
|- default="conf@1"
|
o conf@1 {...}
o conf@2 {...}
...
該節點中描述了Image鏡像必要的信息.
o image@1
|- description="component sub-image description"
|- data=/incbin/("path/to/data/file.bin")
|- type="sub-image type name"
|- arch="ARCH name"
|- os="OS name"
|- compression="compression name"
|- load=<00000000>
|- entry=<00000000>
|
o hash@1 {...}
o hash@2 {...}
...
o hash@1
|- algo="hash or checksum algorithm name"
|- value=[hash or checksum value]
o configurations
|- default="default configuration sub-node unit name"
|
o config@1 {...}
o config@2 {...}
...
o config@1
|- description="configuration description"
|- kernel="kernel sub-node unit name"
|- ramdisk="ramdisk sub-node unit name"
|- fdt="fdt sub-node unit-name" [, "fdt overlay sub-node unit-name", ...]
|- fpga="fpga sub-node unit-name"
|- loadables="loadables sub-node unit-name"
如下是一個有多種kernels, ramdisks and FDT blobs鏡像多套配置的its文件。它包含了3種配置,每種配置使用了不同的kernel、ramdisk和fdt,默認配置項由“default”指定,當然也可以在運行時指定。
/*
* U-Boot uImage source file with multiple kernels, ramdisks and FDT blobs
*/
/dts-v1/;
/ {
description="Various kernels, ramdisks and FDT blobs";
#address-cells=<1>;
images {
kernel@1 {
description="vanilla-2.6.23";
data=/incbin/("./vmlinux.bin.gz");
type="kernel";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="md5";
};
hash@2 {
algo="sha1";
};
};
kernel@2 {
description="2.6.23-denx";
data=/incbin/("./2.6.23-denx.bin.gz");
type="kernel";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="sha1";
};
};
kernel@3 {
description="2.4.25-denx";
data=/incbin/("./2.4.25-denx.bin.gz");
type="kernel";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="md5";
};
};
ramdisk@1 {
description="eldk-4.2-ramdisk";
data=/incbin/("./eldk-4.2-ramdisk");
type="ramdisk";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="sha1";
};
};
ramdisk@2 {
description="eldk-3.1-ramdisk";
data=/incbin/("./eldk-3.1-ramdisk");
type="ramdisk";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="crc32";
};
};
fdt@1 {
description="tqm5200-fdt";
data=/incbin/("./tqm5200.dtb");
type="flat_dt";
arch="ppc";
compression="none";
hash@1 {
algo="crc32";
};
};
fdt@2 {
description="tqm5200s-fdt";
data=/incbin/("./tqm5200s.dtb");
type="flat_dt";
arch="ppc";
compression="none";
load=<00700000>;
hash@1 {
algo="sha1";
};
};
};
configurations {
default="config@1";
config@1 {
description="tqm5200 vanilla-2.6.23 configuration";
kernel="kernel@1";
ramdisk="ramdisk@1";
fdt="fdt@1";
};
config@2 {
description="tqm5200s denx-2.6.23 configuration";
kernel="kernel@2";
ramdisk="ramdisk@1";
fdt="fdt@2";
};
config@3 {
description="tqm5200s denx-2.4.25 configuration";
kernel="kernel@3";
ramdisk="ramdisk@2";
};
};
};
在服務器上,可以使用mkimage工具制作 FIT Image。
如下是kernel_fdt.its,下面將使用該文件制作itb。
/*
* Simple U-Boot uImage source file containing a single kernel and FDT blob
*/
/dts-v1/;
/ {
description="Simple image with single Linux kernel and FDT blob";
#address-cells=<1>;
images {
kernel@1 {
description="Vanilla Linux kernel";
data=/incbin/("./vmlinux.bin.gz");
type="kernel";
arch="ppc";
os="linux";
compression="gzip";
load=<00000000>;
entry=<00000000>;
hash@1 {
algo="crc32";
};
hash@2 {
algo="sha1";
};
};
fdt@1 {
description="Flattened Device Tree blob";
data=/incbin/("./target.dtb");
type="flat_dt";
arch="ppc";
compression="none";
hash@1 {
algo="crc32";
};
hash@2 {
algo="sha1";
};
};
};
configurations {
default="conf@1";
conf@1 {
description="Boot Linux kernel with FDT blob";
kernel="kernel@1";
fdt="fdt@1";
};
};
};
$ mkimage -f kernel_fdt.its kernel_fdt.itb
DTC: dts->dtb on file "kernel_fdt.its"
$
$ mkimage -l kernel_fdt.itb
FIT description: Simple image with single Linux kernel and FDT blob
Created: Tue Mar 11 16:29:22 2008
Image 0 (kernel@1)
Description: Vanilla Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Size: 1092037 Bytes=1066.44 kB=1.04 MB
Architecture: PowerPC
OS: Linux
Load Address: 0x00000000
Entry Point: 0x00000000
Hash algo: crc32
Hash value: 2c0cc807
Hash algo: sha1
Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
Image 1 (fdt@1)
Description: Flattened Device Tree blob
Type: Flat Device Tree
Compression: uncompressed
Data Size: 16384 Bytes=16.00 kB=0.02 MB
Architecture: PowerPC
Hash algo: crc32
Hash value: 0d655d71
Hash algo: sha1
Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
Default Configuration: 'conf@1'
Configuration 0 (conf@1)
Description: Boot Linux kernel with FDT blob
Kernel: kernel@1
FDT: fdt@1
在當前目錄下就可以找到kernel_fdt.itb,itb文件就可以加載到設備上啟動。
> tftp 900000 /path/to/tftp/location/kernel_fdt.itb
Using FEC device
TFTP from server 192.168.1.1; our IP address is 192.168.160.5
Filename '/path/to/tftp/location/kernel_fdt.itb'.
Load address: 0x900000
Loading: #################################################################
###########
done
Bytes transferred=1109776 (10ef10 hex)=> iminfo
## Checking Image at 00900000 ...
FIT image found
FIT description: Simple image with single Linux kernel and FDT blob
Created: 2008-03-11 15:29:22 UTC
Image 0 (kernel@1)
Description: Vanilla Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x009000ec
Data Size: 1092037 Bytes=1 MB
Architecture: PowerPC
OS: Linux
Load Address: 0x00000000
Entry Point: 0x00000000
Hash algo: crc32
Hash value: 2c0cc807
Hash algo: sha1
Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
Image 1 (fdt@1)
Description: Flattened Device Tree blob
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x00a0abdc
Data Size: 16384 Bytes=16 kB
Architecture: PowerPC
Hash algo: crc32
Hash value: 0d655d71
Hash algo: sha1
Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
Default Configuration: 'conf@1'
Configuration 0 (conf@1)
Description: Boot Linux kernel with FDT blob
Kernel: kernel@1
FDT: fdt@1=> bootm
## Booting kernel from FIT Image at 00900000 ...
Using 'conf@1' configuration
Trying 'kernel@1' kernel subimage
Description: Vanilla Linux kernel
Type: Kernel Image
Compression: gzip compressed
Data Start: 0x009000ec
Data Size: 1092037 Bytes=1 MB
Architecture: PowerPC
OS: Linux
Load Address: 0x00000000
Entry Point: 0x00000000
Hash algo: crc32
Hash value: 2c0cc807
Hash algo: sha1
Hash value: 264b59935470e42c418744f83935d44cdf59a3bb
Verifying Hash Integrity ... crc32+ sha1+ OK
Uncompressing Kernel Image ... OK
## Flattened Device Tree from FIT Image at 00900000
Using 'conf@1' configuration
Trying 'fdt@1' FDT blob subimage
Description: Flattened Device Tree blob
Type: Flat Device Tree
Compression: uncompressed
Data Start: 0x00a0abdc
Data Size: 16384 Bytes=16 kB
Architecture: PowerPC
Hash algo: crc32
Hash value: 0d655d71
Hash algo: sha1
Hash value: 25ab4e15cd4b8a5144610394560d9c318ce52def
Verifying Hash Integrity ... crc32+ sha1+ OK
Booting using the fdt blob at 0xa0abdc
Loading Device Tree to 007fc000, end 007fffff ... OK
[ 0.000000] Using lite5200 machine description
[ 0.000000] Linux version 2.6.24-rc6-gaebecdfc (m8@hekate) (gcc version 4.0.0 (DENX ELDK 4.1 4.0.0)) #1 Sat Jan 12 15:38:48 CET 2008
對于FIT Image,bootm有多種啟動方式。
1. bootm <addr1>
2. bootm [<addr1>]:<subimg1>
3. bootm [<addr1>]#<conf>[#<extra-conf[#...]]
4. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2>
5. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2> [<addr3>]:<subimg3>
6. bootm [<addr1>]:<subimg1> [<addr2>]:<subimg2> <addr3>
7. bootm [<addr1>]:<subimg1> - [<addr3>]:<subimg3>
8. bootm [<addr1>]:<subimg1> - <addr3>
對于有多種鏡像,多套配置的itb,都是以configurations 中default 指定的配置啟動。
bootm 200000
也可以手動指定使用那套配置
bootm 200000#cfg@1
也可以手動搭配不同的鏡像節點啟動
bootm 200000:kernel@1 800000:ramdisk@2
bootm 200000:kernel@1 800000:ramdisk@1 800000:fdt@1
bootm 200000:kernel@2 200000:ramdisk@2 600000
bootm 200000:kernel@2 - 200000:fdt@1
如果bootm的時候不指定地址,則會使用CONFIG_SYS_LOAD_ADDR配置的地址。
本文對FIT Image作了簡單的介紹,更詳細的內容可以參考官方文檔。后面有時間會動手制作一個FIT Image在板子上跑下。
FIT Image可以兼容于多種板子,而無需重新進行編譯燒寫。 對于有多個kernel節點或者fdt節點等等,兼容性更強。同時,可以有多種configurations,來對kernel、fdt、ramdisk來進行組合。
https://www.elecfans.com/emb/20190402899374.html
http://www.wowotech.net/u-boot/fit_image_overview.html
howto.txt
command_syntax_extensions.txt
source_file_format.txt
*請認真填寫需求信息,我們會在24小時內與您取得聯系。