维多利亚风格的网络线条:相同宽度的元素
Victorian-style lines for the web: Elements of identical width

原始链接: https://jacobfilipp.com/victorian-line/

## 从复古图形创建重复CSS边框 本教程演示如何使用Inkscape(或Adobe Illustrator)将19世纪的图形边框转换为网站的无缝重复CSS边框。过程从寻找无版权图像开始——具体来说,来自*Recueil des divers caractères…*(1808)的边框。 核心步骤包括:**矢量化**所选边框图像,**分离**每个重复元素,并**标准化**它们的宽度以实现一致的重复。Inkscape工具,如“Trace Bitmap”(位图描摹)、“Split Path”(分割路径)和“Paste-Size Separately”(分别粘贴尺寸),用于实现这一点。元素被分组和对齐以确保尺寸统一。 最后,编写CSS以防止边框在元素中间被截断。通过使用`round()`函数确保元素的宽度*始终*是重复元素宽度的倍数(例如,22px)来实现。然后将SVG用作重复的背景图像。潜在的`max-width`约束问题可以通过在`

`中包装边框或使用`!important`覆盖`max-width`来解决。目标是实现模仿不完美历史印刷的“有机”外观。

## 维多利亚风格网页线条讨论 一场Hacker News讨论围绕着为网页设计创建维多利亚风格的重复线条元素,灵感来自jacobfilipp.com的一篇文章。初始帖子展示了宽度相同的元素。 评论者们争论最佳实现方法。一位用户指出,示例图像的有机、连接的特性无法通过简单的独立形状很好地表现。另一位则提倡使用钢笔工具手动重新描绘图像以获得精确的曲线,而不是依赖自动图像描边。 第三种建议提出使用CSS的`border-image-repeat: round;`来处理矢量图像,提供灵活性和控制力,包括不同“端部”图像(重复元素的末端部分)的选项。这次对话突出了实现视觉上吸引人的结果时,自动化与手动控制之间的权衡。
相关文章

原文

In this tutorial, we will take graphical borders from the 1800s and turn them into a repeating CSS border for your website. The following technique will work for border made of almost-identical repeating elements. We’ll use the free Inkscape illustration software.

The end result will be this kind of border that neatly fills the parent element, no matter what the parent’s width is. Go ahead and pull at the “resize” tab to make it wider or narrower:

We will follow these steps:

  • Vectorizing the image of a border
  • Separating each repeating element from its neighbours
  • Rearranging the elements so they can repeat easily using CSS
  • Creating CSS code to ensure we’ll never cut off our border mid-element

Getting the image

We’re going to work with the borders at Recueil des divers caractères, vignettes et ornements de la fonderie et imprimerie de J. G. Gillé from 1808 – organically grown and Copyright Free!

In the above screenshot, the borders that work for our needs are 79, 81, 84, 85, 86 and 88. The others would work if you crop them to drop their central/edge elements which have different widths from the repeating portion.

Choose a border that is made up of the same width characters repeating.

I’ve chosen this one for our exercise:

We zoom in on it and take a screenshot.

Vectorizing

We will turn this flat image into a vector (SVG) so that we can easily separate the wreaths and space them out for even repetition.

Import the image into the Inkscape program (although Adobe Illustrator will also work)

Go to Path->Trace To Bitmap

You will end up with a black and white vector like this:

Separating the elements

Now, we split this one big path into parts. Go to Path->Split Path and you’ll end up with a bunch of non-overlapping little portions.

You can see the blue outlines showing distinct paths now:

But look at the red arrows where some of the wreaths have merged together. This is due to the way the original print was done – where the ink overlapped between separate elements.

We can split up that merged path by creating a rectangle on top (shown in red), selecting both the rectangle and the path, and then going to Path->Difference to cut the underlying path, then go to Path->Split Path to divide them into 2 separate paths.

You can also split the shape along thin curve by drawing with the Pen tool (don’t close the curve – just press ENTER to leave a line segment). Then, select the curve and the underlying path and go to Path->Fracture.

Go on and cut all the shapes away from each other

Then, go on and select the paths that make up each pattern element (select them, then group them with CTRL+G). When you’re done grouping, you’ll get paths that roughly correspond to individual pattern elements:

Making each wreath the same width

Next, we want each element to be the same width so we can predictably repeat the pattern every X pixels.

Figure out a good average width & height for one of these elements. I do it by selecting one and looking at the Width and Height in px at the top bar. In the example, the repeating element is 22.924px wide by 21.815px high.

Let’s go ahead and make each element 22px wide. Select one object and change its width manually to 22px while keeping the height “locked” to the same aspect ratio with the lock icon.

Select your one object and copy it. Then, select all the other objects:

Go to Edit->Paste->Size Separately. This will give all of them the same height & width as the “reference object” you just copied. This is just a fast way to force all of them to have the same width – there are probably other ways to do the same thing.

Then we go to Object->Align and Distribute->Grid

The settings in the screenshot will distribute them horizontally with no spaces in between. If your pattern is the kind that looks good with spaces between the elements, then you can enter 1 or 2 px in that “X:” field.

We apply the grid and get elements of the same width and height, touching:

You can adjust height, and vertical offset to break up the pattern a little if you want:

I realize this is way more effort than using 1 wreath and repeating the same image as many times as we need. The goal of using the scanned wreaths and adjusting them is to create an “organic” look that imitates imperfect printing.

Give them whatever fill-colour you want and export as “Plain SVG”

Creating CSS that never cuts off mid-element

Next, we are going to set up the SVG pattern as a repeating background on an <hr> element. If we simply let the pattern repeat across 100% of the element’s width it’ll often cut off mid-element:

The key part of our CSS: only letting <hr> have a width value that’s a multiple of 22px (the width of each repeating element). The width will never be set to a value that cuts off an element.

We can do this with the CSS round() function:

width: round(down,100%,22px);

Above, we are setting the width of the element to 100% of its parent, but rounding it down to the closest multiple of 22px.

Here is what the full code looks like, with the “background-image” declaration, horizontal repetition and width:

hr {
		width: round(down,100%,22px);
		background-image: url( 'exported-image.svg' );
		background-repeat: repeat-x;
		height: 25px;
		border: 0;
	}

Note: if the <hr> element has a max-width declared upstream, it might still create cutoff problems. Max-width always takes precedence over the rounded width we set here, and cuts off the repeating border regardless.

You’ll get cut-off effects like this:

One solution is to surround your <hr> element in a <div> – that way it is the div element that’ll get clamped down to the max-width and will leave the hr to be rounded properly. Another solution is to add an !important max-width onto the <hr> definition, like max-width: round( down, "max-width of the parent", 22px)

You can scale up the repeating elements by setting background-size: auto 55px; (height = 55px, width = scale up proportionally), but you’ll have to also set height: 55px, and set the width to round() down to an appropriately-scaled up pixel width.

联系我们 contact @ memedata.com