eCommerce is a very competitive space. Brands are literally fighting it out to provide the best possible UX to their visitors in order to beat the competition. Combine that with the heightened expectations of modern consumers (50% won’t wait longer than 3 seconds before abandoning a poorly-designed e-commerce site) and you’ll understand why it’s vital […]
Are you new to email marketing or wish to improve your current results? It is a huge topic indeed, but to succeed, you need to start small. With this post, you will make it easily: here we are explaining the …
Let’s say someone asks you to add a double border to some random geometric SVG shapes. For some reason, you can’t use any graphic editor — they need to be generated at runtime — so you have to solve it with CSS or within the SVG syntax.
Your first question might be: Is there anything like stroke-style: double in SVG? Well, the answer is not yet and it’s not that easy. But I’ll attempt it anyway to see what methods I can uncover. I’ll explore the possibilities of three different basic shapes: circle, rectangle, and polygon. Pointing the ones that can keep a transparent color in the middle of the two lines.
Spoiler alert: all the results have their downsides, at least with CSS and SVG, but let me walk you through my intents.
The simple solutions
These don’t work with all shapes, but they are the easiest of the solutions.
outline and box-shadow
The CSS properties outline and box-shadow only apply to the bounding box of the shape or SVG, and so both are great solutions only for squares and rectangles. They also allow flexible colors using custom properties.
It only takes two lines of CSS with outline, plus it keeps the background color visible through the shape.
🙁 Solution only for one shape.
✅ Simple code
✅ Borders are smooth
✅ Transparent background
box-shadow only needs one line of CSS, but we have to make sure that each shape has its own SVG as we can’t apply box-shadow directly to the shapes. Another thing to consider is that we have to apply the color of the background in the declaration.
🙁 Solution only for one shape
✅ Simple code
✅ Borders are smooth
🙁 No transparent background
SVG gradients
SVG radial gradients only work on circles ☺️. We can directly apply the gradient on the stroke, but it’s better to use variables as we have to declare the colors many times in the code.
🙁 Solution only for one shape
✅ Simple code
🙁 Borders are smooth
🙁 No transparent background
Solutions for all shapes
These will work with all shapes, but the code could become bloated or complex.
filter:drop-shadow()
Finally, one solution for all shapes! We must have each shape in its own <svg> since the filter won’t apply directly to the shapes. We are using one declaration in CSS and have flexible colors using variables. The downside? The borders don’t look very smooth.
✅ One solution for all shapes
✅ Simple code
🙁 Borders look pixelated
🙁 No transparent background
SVG filters
This is a very flexible solution. We can create a filter and add it to the shapes through SVG’s filter attribute. The complicated part here is the filter itself. We’ll need three paintings, one for the outside border, one for the background flood, and the last one to paint the shape on the front. The result looks better than using drop-shadow, but the borders are still pixelated.
✅ One solution for all shapes
🙁 Complex code
🙁 Borders look pixelated
🙁 No transparent background
Reusing shapes
There are a couple of possible options here.
Option 1: Transforms
This solution requires transforms. We place one figure over the other, where the main figure has a fill color and a stroke color, and the other figure has no fill, a red stroke, and is scaled and repositioned to the center. We defined our shapes on the <defs>. The trick is to translate half of theviewBoxto the negative space so that, when we scale them, we can do it from the center of the figure.
✅ One solution for all shapes
🙁 Duplicated code
✅ Borders are smooth
✅ Transparent background
Option 2: <use>
I found a clever solution in the www-svg mailing list by Doug Schepers that uses SVG <use>. Again, it requires defining the shapes once and referring to them twice using <use>. This time the main shape has a bigger stroke. The second shape has half the stroke of the main shape, no fill, and a stroke matching the background color.
✅ One solution for all shapes
🙁 Duplicated code
✅ Borders are smooth
🙁 No transparent background
Here are the full results!
Just so you have them all in one place. Let me know it you can think of other possible solutions!
This isn’t actually a podcast actually talking about what CodePen is. Well, it kinda is. But actually it’s Stephen and Chris talking about and planning for what they would say if they only had five minutes (or so) to explain what CodePen is. So we need to hash out what the most important things are, what to lede with, and how to cover all the most vital things with clarity in such a short amount of time. We’ll have to get around to actually trying to shoot a video like this soon!
Jetpack Boost is a brand spankin’ new plugin from the Jetpack / Automattic gang. Jetpack has some very powerful performance features it offers, like giving you a global CDN for your images and core-WordPress-specific CSS and JavaScript. That particular feature is still a part of the Jetpack core plugin, but many performance-specific features are moving their way over to Jetpack Boost. Like Lazy Image loading (a huge performance win) is now in Jetpack Boost and you can turn it on with the flip of a switch. The most amazing, and brand new, feature of Jetpack Boost is that it does Critical CSS handling for you, which is also a big performance win and very difficult to do by hand.
Private Sub Plus_Btn_Click(sender As Object, e As EventArgs) Handles A_Plus_Btn.Click, C_Txb.Click
Dim Txb As TextBox
If x < MAX Then
x += 1
Else
x = 5
End If
For i As Integer = 1 To x
For j As Integer = 1 To x
Txb = New TextBox
Txb.Size = New Drawing.Size(100, 20)
Txb.Location = New Point(10 + 100 * i, 10 + 25 * j)
Txb.Name = "Txb" & i & "," & j
AddHandler Txb.TextChanged, AddressOf TextBox_TextChanged
boxes(i) = Txb
Me.Controls.Add(Txb)
Next
Next
End Sub
Private Sub TextBox_TextChanged(sender As Object, e As EventArgs)
Dim box As TextBox = DirectCast(sender, TextBox)
Me.Text = box.Name & ": " & box.Text
End Sub
Private Sub Minus_Btn_Click(sender As Object, e As EventArgs) Handles A_Minus_Btn.Click, C_Txb.Click
Dim Txb As TextBox
If x > MIN Then
x -= 1
Else
x = MIN
End If
For i As Integer = 1 To x
For j As Integer = 1 To x
Txb = New TextBox
Txb.Size = New Drawing.Size(100, 20)
Txb.Location = New Point(10 + 100 * i, 10 + 25 * j)
Txb.Name = "Txb" & i & "," & j
AddHandler Txb.TextChanged, AddressOf TextBox_TextChanged
boxes(i) = Txb
Me.Controls.Add(Txb)
Next
Next
End Sub
I want to make TextBox into array and increase/decrease with buttons.
ex) dim x=1 [+] [-]
x = 1:
[]
x = 2:
[][]
[][]
x = 3:
[][][]
[][][]
[][][]
...
But it's made with the code I wrote above, but it doesn't remove.
And it's not array system, it's hard to manage.