Make web-safe colors using Bash
When computer monitors have a limited color palette, web designers often use a set of web-safe colors to create websites. Although modern websites displayed on newer devices can display more colors than the original web-safe palette, I sometimes like to refer to web-safe colors when creating web pages. This way I know my page will look good everywhere.
You can find web safe palettes online, but I wanted to have my own copy for easy reference. You can also create one using a for
loop in Bash.
Bash for loop
The syntax of the for loop in Bash is as follows:
1 |
|
For example, suppose you want to print all numbers from 1 to 3. You can quickly write a for
loop on the Bash command line to do the job for you:
1 |
|
The semicolon is the standard Bash statement delimiter. They allow you to write multiple commands in one line. If you were to include this for
loop in a Bash script file, you could replace the semicolons with newlines and write the for
loop like this:
1 |
|
I like it Putting do
and for
on the same line makes it easier for me to read:
1 |
|
Multiple for loops at once
You can put a loop Put in another loop. This helps you iterate over multiple variables and do more than one thing at a time. Suppose you want to print out all combinations of the letters A, B, and C with the numbers 1, 2, and 3. You can do this in Bash using two for
loops, like this:
1 |
|
If you put these lines in a Bash script called for.bash
file and run it, you'll see nine lines showing all combinations of letters paired with each number:
1 |
|
Traverse Web Safe Colors
Web safe colors are derived from hex Colors #000
(black, where red, green, and blue are all zero) to #fff
(white, where red, green, and blue are all highest), each The steps for hexadecimal values are 0, 3, 6, 9, c, and f.
You can generate a list of all combinations of web-safe colors using three for
loops in Bash, which loop over the red, green, and blue values.
1 |
|
If you save this in a new Bash script called websafe.bash
and run it, you'll see an iteration of the hex values for all the web-safe colors:
1 |
|
要制作可用作 Web 安全颜色参考的 HTML 页面,你需要使每个条目成为一个单独的 HTML 元素。将每种颜色放在一个 <div>
元素中,并将背景设置为 Web 安全颜色。为了使十六进制值更易于阅读,将其放在单独的 <code>
元素中。将 Bash 脚本更新为如下:
1 |
|
当你运行新的 Bash 脚本并将结果保存到 HTML 文件时,你可以在浏览器中查看所有 Web 安全颜色的输出:
1 |
|
Colour gradient.
这个网页不是很好看。深色背景上的黑色文字无法阅读。我喜欢使用HTML样式,以确保在颜色矩形上以白色文本显示十六进制值,并且背景为黑色。我使用了HTML网格样式将每行六个框进行排列,并为了美观效果,在框之间留有适当的间距。
你需要在循环之前和之后包含其他的HTML元素来添加额外的样式。在顶部的HTML代码中定义样式,并在底部的HTML代码中关闭所有已打开的HTML标签
1 |
|
这个完整的Bash脚本生成了一个用HTML格式制作的Web安全颜色指南。当需要引用网络安全颜色时,运行脚本并将结果保存至 HTML 页面。你可以在浏览器中查看 Web 安全颜色演示,以作为你下一个 Web 项目的简单参考
1 |
|
(题图:MJ/abf9daf2-b72f-4929-8dd8-b77fb5b9d39b)
The above is the detailed content of Make web-safe colors using Bash. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





Windows Subsystem for Linux The first option is to use Windows Subsystem for Linux or WSL, which is a compatibility layer for running Linux binary executables natively on Windows systems. It works for most scenarios and allows you to run shell scripts in Windows 11/10. WSL is not automatically available, so you must enable it through your Windows device's developer settings. You can do this by going to Settings > Update & Security > For Developers. Switch to developer mode and confirm the prompt by selecting Yes. Next, look for W

At the beginning of this year, when Microsoft and Canonical released Windows 10 Bash and Ubuntu user space, I tried to do some preliminary performance tests on Ubuntu on Windows 10 compared to native Ubuntu. This time I published more about the benchmark comparison between native pure Ubuntu and Windows 10. The Linux subsystem test for Windows completed all tests and was released with the Windows 10 Anniversary Update. The default Ubuntu user space is still Ubuntu14.04, but it can be upgraded to 16.04. So the test is first tested on 14.04, and after completion, the system will be upgraded to 16.04

Programmers often use the Bash command language to create shell scripts to automate manual tasks. For example, they create Bash scripts for various configurations, file operations, generating build results, and various DevOps-related activities. Almost all Unix-like or Unix-based operating systems provide users with a pre-installed Bash interpreter, so we can use Bash to write more portable automation scripts. As we already know, Bash scripting refers to writing a series of commands using the syntax of the Bash command language, built-in Bash commands, and core operating system CLI programs such as GNU Core Tools. A standard and old-fashioned Bash script usually executes some commands and displays plain text on the terminal

Here we will see how to get the number A raised to the power B using a bash script. The logic is simple. We have to use the "**" operator or the power operator to do this. Let us see the following program to understand this concept clearly. Example#!/bin/bash#GNUbashScripta=5b=6echo "$(($a**$b))" output 15625

BourneAgainShell (BASH for short) is the most popular SHELL implementation on GNU/Linux. It was born in 1980. After decades of evolution, it has evolved from a simple terminal command line interpreter into a multi-functional interface deeply integrated with the GNU system. . Bash, a type of Unix shell. The first official version was released in 1989. It was originally planned to be used on the GNU operating system, but it can run on most Unix-like operating systems, including Linux and MacOSXv10.4, which use it as the default shell. It has also been ported to Cygwin and MinGW on Microsoft Windows, or can be used on MS-

Last week Microsoft announced BugBash, a campaign designed to engage Windows insiders with tasks to (hopefully) improve Windows 11 development in the long and short term. Originally on March 16, there were around 26 missions available to complete, but that has now grown to a staggering 75. Here's the kicker, though: BugBash will end on March 22nd, along with the opportunity to earn BugBash-specific stickers that will appear in your Feedback Hub. To participate in the Windows11 BugBash, you need to grab the latest Windows 11 preview build from the Dev channel, which is build2

Having a solid foundation in programming is obviously an essential quality for a good software engineer. Whether it's an interpreted language like Python or a compiled language like C++, it's crucial to master at least one programming language. However, this is only one aspect of becoming a truly well-rounded engineer. If you lose your way in the shell environment, those basic knowledge will be useless. Flexible use of commands in Bash will take you to areas that traditional programming languages cannot reach. Sometimes, you don't actually need to use a more powerful programming language. By using just the Shell, you can accomplish the tasks you need faster and easier, and without the need for additional dependencies. In this article, we will explore some very useful Bash commands

When computer monitors have a limited color palette, web designers often use a set of web-safe colors to create websites. While modern websites displayed on newer devices can display more colors than the original web-safe palette, I sometimes like to refer to web-safe colors when creating web pages. This way I know my page will look good everywhere. You can find the Web Safe Palette online, but I wanted to have my own copy for easy reference. You can also create one using a for loop in Bash. Bashfor loop The syntax of a for loop in Bash is as follows: for variable in collection; do statement; done For example, suppose you want to print all numbers from 1 to 3. You can quickly use Bas
