Frame effect on hover

Frame effect on hover

Today we will look at a simple but interesting effect of the emergence of a frame from the center, when you hover over a button. Any shape can be used as a target.

Button positioning

HTML markup consists of a tag button and the parent container.

    

The effect of the appearance of a frame on hover.

Anticipating the newbies’ question – “Why do we need a container?”, I suggest looking at the picture above. By default, the button is pressed to the upper left corner of the browser. To control the positioning of the button, you need an outer shell. The container is the parent and the button is its child. We want to position the button just below the top of the browser window and centered horizontally. CSS properties responsible for positioning an element are assigned to its parent – the container.


.container{
    margin-top: 40px; /* отступ сверху */
    display: flex; /* гибкий контейнер */
    justify-content: center; /* по центру по горизонтали */
}

The effect of the appearance of a frame on hover.

Styling a button

Let’s make our button more beautiful – assign CSS tag properties button… Be sure to set the tag button relative positioning, so that the pseudo-elements can be positioned relative to itself.


button {
    font-family: 'Roboto Condensed'; /* название шрифта */
    text-transform: uppercase; /* трансформация в заглавные буквы */
    font-weight: 900; /* толщина шрифта */
    color: #fff; /* цвет текста на кнопке */
    font-size: 30px; /* размер шрифта */
    background-color: #ad1ca1; /* цвет кнопки */
    padding: 30px 60px; /* расстояние от текста до края кнопки */
    border: 2px solid #000; /* толщина стиль и цвет обводки кнопки */
    position: relative; /* относительное позиционирование */
}

The effect of the appearance of a frame on hover.

Create a border inside a button

To create a border inside a button, thanks to pseudo-elements before и after, we don’t need to create a real element for a nice special effect. Via before draw the top and bottom lines of the frame.


button:before {
    content: ''; /* отображает псевдоэлемент */
    position: absolute; /* абсолютное позиционирование */
    top: 5%; /* позиция линии сверху */
    right: 3%; /* позиция линии справа */
    bottom: 5%; /* позиция линии снизу */
    left: 3%;/* позиция линии слева */
    border-top: solid 2px; /* толщина верхней линии */
    border-bottom: solid 2px; /* толщина нижней линии */
    transition: 0.2s; /* плавный hover эффект */
    transform: scaleX(1); /* ширина рамки 100% */
}

The effect of the appearance of a frame on hover.

Using the pseudo element after, create the top and bottom lines of the frame.


button:after {
    content: '';
    position: absolute;
    top: 5%;
    right: 3%;
    bottom: 5%;
    left: 3%;
    border-left: solid 2px;
    border-right: solid 2px;
    transition: 0.2s;
    transform: scaleY(1);
}

The effect of the appearance of a frame on hover.

Border appears on hover

The white frame (picture below) should appear when you hover the mouse over the button. Therefore, we will hide it by replacing the values ​​of y scaleX и scaleY properties transform, to zero.

The effect of the appearance of a frame on hover.


transform: scaleX(0);
transform: scaleY(0);

When you hover the mouse over the button, the value will change stairs from 0 to 1 and then we will see this beautiful effect.


button:hover:before,
button:hover:after{
    transform: scale(1);
}

Take a look at an example at CodePen

Previous article Next article

Copying of materials is allowed only with the indication of the author (Mikhail Rusakov) and an indexed direct link to the site (http://myrusakov.ru)!

Add to my friends VK: http://vk.com/myrusakov.
If you want to rate me and my work, then write it in my group: http://vk.com/rusakovmy.

If you do not want to miss new materials on the site,
then you can subscribe to updates: Subscribe to updates

If you still have any questions, or you have a desire to comment on this article, then you can leave your comment at the bottom of the page.

Recommend this article to your friends:

If you liked the site, then post a link to it (on your site, on the forum, in contact):

  1. Button:

    It looks like this: How to create your website

  2. Text link:

    It looks like this: How to create your website

  3. BB-code of the link for forums (for example, you can put it in the signature):

Related Posts

Property Management in Dubai: Effective Rental Strategies and Choosing a Management Company

“Property Management in Dubai: Effective Rental Strategies and Choosing a Management Company” In Dubai, one of the most dynamically developing regions in the world, the real estate…

In Poland, an 18-year-old Ukrainian ran away from the police and died in an accident, – media

The guy crashed into a roadside pole at high speed. In Poland, an 18-year-old Ukrainian ran away from the police and died in an accident / illustrative…

NATO saw no signs that the Russian Federation was planning an attack on one of the Alliance countries

Bauer recalled that according to Article 3 of the NATO treaty, every country must be able to defend itself. Rob Bauer commented on concerns that Russia is…

The Russian Federation has modernized the Kh-101 missile, doubling its warhead, analysts

The installation of an additional warhead in addition to the conventional high-explosive fragmentation one occurred due to a reduction in the size of the fuel tank. The…

Four people killed by storm in European holiday destinations

The deaths come amid warnings of high winds and rain thanks to Storm Nelson. Rescuers discovered bodies in two separate incidents / photo ua.depositphotos.com Four people, including…

Egg baba: a centuries-old recipe of 24 yolks for Catholic Easter

They like to put it in the Easter basket in Poland. However, many countries have their own variations of “bab”. The woman’s original recipe is associated with…

Leave a Reply

Your email address will not be published. Required fields are marked *