朋克css,Use rotate() and skew() together to introduce some clean Punk Rock to your CSS

The web design industry is going to start looking very different very soon. Literally.

With all the tools we’re gaining in CSS, designers are going to have new ability to experiment. I wrote about some of those tools on CSS Tricks: Five Design Fears to Vanquish with CSS Grid.

I’m still convinced that taking inspiration from punk rock design of the 70s and 80s is going to be a trend.

If you want to start small, introduce some angles to your design. This is a simple trick to angle a stripe of content without adding awkward white space.

Start with a regular stripe

88e702ad6a423c53b30557dba5785081.png

We all know this design pattern: full width background and nice promotional content.

We set up very simple markup:

Check this regular stripe

If you're wanting to get into punk-rock design, rotated areas are really cool and you'll look hip and cool.

Add a pinch of very simple CSS and we’re done.

.stripe {

background-image: linear-gradient(240deg, #eaee44, #90ec19);

padding: 5rem;

}

This is a lovely serviceable stripe of content. You also get to dig on a nice linear-gradient while you’re there.

Use transform: rotate() to introduce the angle

3c675b9f6b8a812778b823d26ace43bd.png

The transform CSS property has a load of great functions. One of the easiest functions to use is rotate(). It takes an angle unit such as 45deg and rotates the element by that amount. A positive integer is a clockwise turn and negative is a counter-clockwise turn.

.stripe {

background-image: linear-gradient(240deg, #eaee44, #90ec19);

padding: 5rem;

transform: rotate(-5deg);

}

You’ll notice from the photo that this introduces an issue. This is still a rectangle and by rotating the rectangle, we see the corners.

This doesn’t feel professional, so we need this to stay flush to the browser edge.

skew() to the rescue

7933ce8d5b69c38c9fb5187b86359a56.png

By taking the same angle we used in our rotate() function, we can skew the element back. This angles the left and right sides of our element back to their starting points.

The transform property can take multiple functions, so we apply it on the same line of CSS.

.stripe {

background-image: linear-gradient(240deg, #eaee44, #90ec19);

padding: 5rem;

transform: rotate(-5deg) skew(-5deg);

}

The discerning designer eye will notice one more issue with our implementation. The text is now skewed. This may be something you want. The skewed text bothers me slightly, so let’s unskew it.

Time to unskew the text

15697503d82e0e20c05751534b052996.png

I’m not a huge fan of introducing new markup for styling if I can avoid it, but with the introduction of a content container, we can fix our text skew.

Chances are decent, you had a container here anyway to set a width on your content.

By applying a skew of the negative angle we’ve been using, the text will re-skew back to its initial angle. You can also use this method to un-rotate the text, as well, if that’s your need.

Full Markup:

Check this rotation with the straight edges and non-skewed text!!!

If you're wanting to get into punk-rock design, rotated areas are really cool and you'll look hip and cool.

Full CSS:

.stripe {

background-image: linear-gradient(240deg, #eaee44, #90ec19);

padding: 5rem;

transform: rotate(-5deg) skew(-5deg);

}

.stripe__content {

transform: skew(5deg);

}

This gives us clean lines with a hint of punk rock. See this in action on CodePen.

If you’re still doing things the same way you’ve always done them, it’s time to spice things up. Adding angles is an easy and painless way of tossing some cayenne into your design process.

Stay up to date with Bryan

If you want to stay up to date with all the content I'm producing, be sure to follow me here, but also on other platforms as well.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值