All posts tagged “Heart”

How To Create Heart Shape with CSS

CSS3 elevates the feasibility of what we can build on websites using just HTML and CSS. You can find amazing examples that we have previously featured. But let’s not get too far ahead of ourselves, a complicated design will need codes that may give you a headache.

heart shape css

Instead, we are going to create something simple to help you understand shapes and positioning with CSS first, before venturing to more advanced designs. Since Valentine’s day is just around the corner, let’s create a heart shape using HTML and CSS.

The Basics

Basically, we can create a new shape by joining one or more basic shapes, like rectangles and circles. If we examine a heart shape we can find that it is made up of two circles and a rectangle combined. HTML elements are essentially a square or rectangle. Thanks to CSS3 border radius we can transform a rectangle into a circle easily.

Begin by adding a <div> element as the foundation of our heart shape.

 <div class="heart-shape"></div> 

Then, we make it a square by specifying the width and the height equally. Choose a background color you like.

 .heart-shape{ position: relative; width: 200px; height: 200px; background-color: rgba(250,184,66, 0.8); } 

Next up, we will make the circles.

Rather than add new elements, we will make use of the pseudo-elements, :before and :after. We first set the :before pseudo-elements as our first circle. We make it a square with equal size on the width and height just like we did with the div. We then transform it into a circle by giving it border-radius of 50% and put it on the left side of the square.

 .heart-shape:before{ position: absolute; bottom: 0px; left: -100px; width: 200px; height: 200px; content: ''; -webkit-border-radius: 50%; -moz-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%; background-color: rgba(250,184,66, 0.8); } 

Together with the square we will have a result like this:

After that, we create the second circle with the pseudo-element :after with the same styles as the first circle we created. Then, we also position it on the top of the square.

 .heart-shape:after{ position: absolute; top: -100px; right: 0px; width: 200px; height: 200px; content: ''; -webkit-border-radius: 50%; -moz-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%; background-color: rgba(250,184,66, 0.8); } 

The results are as follows:

We can combine these two same styles by grouping the pseudo-element selectors as follows:

 .heart-shape:before, .heart-shape:after{ position: absolute; width: 200px; height: 200px; content: ''; -webkit-border-radius: 50%; -moz-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%; background-color: rgba(250,184,66, 0.8); } .heart-shape:before{ bottom: 0px; left: -100px; } .heart-shape:after{ top: -100px; right: 0px; } 

Ta-da! We have a heart shape, although it’s not in the right direction yet. To straighten it up, we will use CSS3 Transformation.

Transformation can be given to the main elements of shape; here, that means the square. When transformed, the pseudo-element will automatically change its position following the main element.

Here we will rotate the heart so it is seen "standing".

 .heart-shape{ -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); } 

And this is what our heart looks like now.

The Result:

The complete code of the heart shape above is as follows, in HTML:

 <div class="heart-shape"></div> 

And on our CSS, it will be like this:

 .heart-shape{ position: relative; width: 200px; height: 200px; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); background-color: rgba(250,184,66, 1); } .heart-shape:before, .heart-shape:after{ position: absolute; width: 200px; height: 200px; content: ''; -webkit-border-radius: 50%; -moz-border-radius: 50%; -o-border-radius: 50%; border-radius: 50%; background-color: rgba(250,184,66, 1); } .heart-shape:before{ bottom: 0px; left: -100px; } .heart-shape:after{ top: -100px; right: 0px; } 

Notice that we now set the alpha channel of the rgba(250,184,66, 1) in the background to 1 to remove the transparency. Now this is what our Heart looks.

Now that we have a perfect heart shape, we can replace the background to another color (e.g. pink or red) with ease. The only downside here is that we could not add a border to the shape due to the stacked elements. Adding a border line will make the heart look weird.

Conclusion

With CSS3 creating a shape like a Heart shape is now easily doable. The border-radius property allows us to make elements or even a pseudo-element into a circle. With CSS3 transformation, we can rotate or move the coordinates of the object with ease.

You are limited only by your creativity and imagination!





hongkiat.com

Rebecca Atwood’s Tidal Textiles: The Brooklyn fabric designer keeps her Cape Cod coastline past close to heart

Rebecca Atwood's Tidal Textiles

They say that the sound of waves along the shoreline is soothing because it transports the mind back to the womb. Rebecca Atwood brings this meditative quality to the home with her newest fabric collection, launching today, 21 January 2015. Though……

Continue Reading…


Cool Hunting

25 Free Festive Fonts – Write Your Best Wishes Straight From the Heart

The article contains 25 free fonts to write your holiday greetings with or to use them in your holiday design projects.
MonsterPost

The Single Malts at the Heart of Dewar’s Blended Whisky: A look inside three distinct distilleries that define the iconic brand

The Single Malts at the Heart of Dewar's Blended Whisky


There’s a reason why Dewar’s is most likely your father’s, and grandfather’s, whisky. It’s more than their heritage (which dates back to 1846) and it extends well beyond their …

Continue Reading…


Cool Hunting

Test Drive: All-New 2015 Ford F-150: We take the all-around impressive aluminum truck for an on- and off-road ride through the heart of Texas

Test Drive: All-New 2015 Ford F-150


Until just a few days ago, the only people to have driven the all-new 2015 Ford F-150 were employees and select dealers of the storied American automaker. In fact, few outside of Detroit had even laid…

Continue Reading…


Cool Hunting

Rugged Accessories and Bags by Mercy Supply: Leather and canvas products made in the heart of Michigan and built to last in all conditions

Rugged Accessories and Bags by Mercy Supply


The old adage “They don’t make them like they used to” insinuates that modern products don’t stand up to the test of time like those of yesteryear. While this might be true for many manufactured items of the day, Michigan’s recordOutboundLink(this,…

Continue Reading…


Cool Hunting

DIY Bubblegum Kit: A gooey personalized treat for kids, and kids at heart

DIY Bubblegum Kit


Just in at Australia’s Third Drawer Down shop is a DIY bubblegum kit perfect for kids—or adults who love a little childlike fun. Inside the box is everything needed to…

Continue Reading…


Cool Hunting

This age-gap animation will break your heart

Read more about This age-gap animation will break your heart at CreativeBloq.com


This animation will break your heart and then put it back together again




Creative Bloq

KNOCK Inc: We Heart Trees 2014

This year, for their annual Arbor Day initiative, KNOCK Inc put together a Buzzfeed-style quiz that tells users what CelebriTree they are. Results are rewarded with a shareable illustration—sometimes animated (see below). And for every entry KNOCK will donate $ 1 to help save trees and preserve nature. Their goal is to get 2014 to participate, so check it out at We Heart Trees and get involved.

Knock: We Heart Trees / on Design Work Life

Knock: We Heart Trees / on Design Work Life

Knock: We Heart Trees / on Design Work Life

Knock: We Heart Trees / on Design Work Life


Design Work Life