Text transform on hover css

How to Add an Animated Text Over an Image on Hover With CSS3

It is possible to display an animated text over a faded image on hover using pure CSS.

If you want to mouse over the image and see a text appearing animatedly, then you are in the right place! Let’s see how we can do it step by step.

Create HTML

h2>Animated Text Over a Faded Image on Hover h2> div class="example"> img src="/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" width="300" height="300" alt="tree" /> div class="content"> div class="text">Tree div> div> div>

Add CSS

  • Set the :hover selector. The hovering effect is set using the :hover pseudo-class that selects and styles the element.
  • Set the opacity property. It is the first property you should set, as it specifies the level of transparency of an element. This would hide every element inside the class in the beginning.
  • Set the transition property. In the given example, the transition fades the image slowly, in 400 milliseconds. If you do not specify the transition property, there won’t be any effect, and the image will fade quickly.
  • Add the transition-delay and transition-duration properties. The first specifies the starting process and the second specifies the time taken from the text to move from top to bottom.
.example < position: relative; padding: 0; width: 300px; display: block; cursor: pointer; overflow: hidden; > .content < opacity: 0; font-size: 40px; position: absolute; top: 0; left: 0; color: #1c87c9; background-color: rgba(200, 200, 200, 0.5); width: 300px; height: 300px; -webkit-transition: all 400ms ease-out; -moz-transition: all 400ms ease-out; -o-transition: all 400ms ease-out; -ms-transition: all 400ms ease-out; transition: all 400ms ease-out; text-align: center; > .example .content:hover < opacity: 1; > .example .content .text < height: 0; opacity: 1; transition-delay: 0s; transition-duration: 0.4s; > .example .content:hover .text < opacity: 1; transform: translateY(250px); -webkit-transform: translateY(250px); >

Let’s take the steps with the following example.

Example of creating an animated text going from top to bottom over an image on hover:

html> html> head> title>Title of the document title> style> .example < position: relative; padding: 0; width: 300px; display: block; cursor: pointer; overflow: hidden; > .content < opacity: 0; font-size: 40px; position: absolute; top: 0; left: 0; color: #1c87c9; background-color: rgba(200, 200, 200, 0.5); width: 300px; height: 300px; -webkit-transition: all 400ms ease-out; -moz-transition: all 400ms ease-out; -o-transition: all 400ms ease-out; -ms-transition: all 400ms ease-out; transition: all 400ms ease-out; text-align: center; > .example .content:hover < opacity: 1; > .example .content .text < height: 0; opacity: 1; transition-delay: 0s; transition-duration: 0.4s; > .example .content:hover .text < opacity: 1; transform: translateY(250px); -webkit-transform: translateY(250px); > style> head> body> h2>Animated Text Over a Faded Image on Hover h2> div class="example"> img src="/uploads/media/default/0001/01/b408569013c0bb32b2afb0f0d45e93e982347951.jpeg" width="300" height="300" alt="tree" /> div class="content"> div class="text">Tree div> div> div> body> html>

Result

Animated Text Over a Faded Image on Hover

tree

If you set the text-align property to «left» or «right», the text will show up from the top to bottom on the left and the right sides, respectively.

Читайте также:  Python dive into python pdf

Example of creating an animated text going from bottom to center over an image on hover:

html> html> head> title>Title of the document title> style> .example < cursor: pointer; height: 300px; position: relative; overflow: hidden; width: 400px; text-align: center; > .example .fadedbox < background-color: #666666; position: absolute; top: 0; left: 0; color: #fff; -webkit-transition: all 300ms ease-out; -moz-transition: all 300ms ease-out; -o-transition: all 300ms ease-out; -ms-transition: all 300ms ease-out; transition: all 300ms ease-out; opacity: 0; width: 360px; height: 100px; padding: 130px 20px; > .example:hover .fadedbox < opacity: 0.8; > .example .text < -webkit-transition: all 300ms ease-out; -moz-transition: all 300ms ease-out; -o-transition: all 300ms ease-out; -ms-transition: all 300ms ease-out; transition: all 300ms ease-out; transform: translateY(30px); -webkit-transform: translateY(30px); > .example .title < font-size: 2.5em; text-transform: uppercase; opacity: 0; transition-delay: 0.2s; transition-duration: 0.3s; > .example:hover .title, .example:focus .title < opacity: 1; transform: translateY(0px); -webkit-transform: translateY(0px); > style> head> body> h2>Animated Text Over a Faded Image on Hover h2> div class="example"> img src="/uploads/media/default/0001/01/4982c4f43023330a662b9baed5a407e391ae6161.jpeg" width="400" height="300" alt="house" /> div class="fadedbox"> div class="title text"> House div> div> div> body> html>

For maximum browser compatibility, extensions such as -webkit- for Safari, Google Chrome, and Opera (newer versions), -moz- for Firefox, -o- for older versions of Opera are used with the transition and transform properties.

Источник

Эффекты при наведении на текст CSS

Эффекты при наведении на текст CSS

Подборка эффектов при наведении на текст пригодиться для украшения сайта, а так же чтобы выделить нужные элементы, например, подчеркивание текста, заголовков, выделение цветом и многое другое.

При наведении на текст меняется цвет CSS

Эффект изменения цвета при наведении необходим, когда нужно выделить определенный фрагмент текста или абзац. Этот эффект так же подойдет и для ссылки.

Пример

HTML

CSS

 p.change-text < color: #f66d52; /* Цвет текста */ font-size: 2em; /* Размер текста */ font-weight: bold; padding: 20px 0px; text-transform: uppercase; line-height: 1; -webkit-transition: all 0.5s ease; transition: all 0.5s ease; >p.change-text:hover < color: #5265f6; /* Меняем цвет текста */ >

Зачеркнутый текст CSS

Эффект при наведении с зачеркнутым текстом подойдет для того, чтобы выделить фрагмент текста или обратить внимание пользователя на него. Цвет текста и линии одинаковый.

Читайте также:  Css position absolute centered

Пример

HTML

CSS

 p.line-through < color: #f66d52; /* Цвет текста */ font-weight: 400; text-transform: uppercase; font-size: 1em; text-decoration:none; >p.line-through:hover < text-decoration:line-through; /* Добавляем зачеркивание */ >

Зачеркнутая ссылка или текст при наведении другим цветом CSS

Эффект зачеркивания ссылки при наведении пригодится, когда ссылку нужно выделить в тексте, а также для меню на сайте. Такой эффект также можно применить и к тексту. Цвет зачёркивающей линии можно менять по своему усмотрению.

Пример

HTML

CSS

 /* Ссылка */ a.crossed-link < color: #f66d52; /* Цвет сылки */ font-weight: 400; text-transform: uppercase; text-decoration: none; font-size: 1em; position: relative; display: inline-block; >a.crossed-link:before < content: ''; position: absolute; width: 100%; height: 1px; /* Высота зачеркивающей линии */ background: #666; /* Цвет зачеркивающей линии */ top: 45%; animation: out 0s cubic-bezier(1, 0, 0.58, 0.97) 1 both; >div.crossed:hover a.crossed-link:before < animation: in 0.2s cubic-bezier(1, 0, 0.58, 0.97) 1 both; >/* Текст */ p.crossed-text < color: #ffa000; /* Цвет текста */ font-weight: 400; text-transform: uppercase; font-size: 1em; position: relative; display: inline-block; >p.crossed-text:before < content: ''; position: absolute; width: 100%; height: 1px; /* Высота зачеркивающей линии */ background: #666; /* Цвет зачеркивающей линии */ top: 45%; animation: out 0s cubic-bezier(1, 0, 0.58, 0.97) 1 both; >div.crossed:hover p.crossed-text:before < animation: in 0.2s cubic-bezier(1, 0, 0.58, 0.97) 1 both; >/* Анимация */ @keyframes in < 0% < width: 0; left: 0; right: auto; >100% < left: 0; right: auto; width: 100%; >> @keyframes out < 0% < width: 100%; left: auto; right: 0; >100% < width: 0; left: auto; right: 0; >> @keyframes show < 0% < opacity: 0; transform: translateY(-10px); >100% < opacity: 1; transform: translateY(0); >> 

Появление тени для текста при наведении CSS

Эффект появления тени для текста подойдет для того, чтобы выделить определенный фрагмент текста на сайте, можно добавить и смену цвета текста,каак показано в примере, чтобы элементы стали более разнообразными и интересными для пользователя.

Пример

HTML

CSS

 .shadow-text < color: #f66d52; /* Цвет текста */ font-size: 2em; /* Размер текста */ font-weight: bold; padding: 20px 0px; text-transform: uppercase; line-height: 1; -webkit-transition: all 0.5s ease; transition: all 0.5s ease; >.shadow-text:hover < color: #ffa000; /* Меняем цвет текста */ -webkit-text-shadow: 2px 2px 2px #000; -moz-text-shadow: 2px 2px 2px #000; text-shadow: 2px 2px 2px #000; >

Анимация с подчёркивающей и исчезающей линией у ссылки CSS

Этот эффект при наведении подойдет как для ссылки, так и для заголовка и текста, если это необходимо. С помощью такого эффекта можно выделить ключевые моменты и сделать сайт интереснее.

Пример

HTML

CSS

 .underline-one < color: #00bfff; /* Цвет обычной ссылки */ position: relative; cursor: pointer; text-decoration: none; /* Убираем подчеркивание */ >.underline-one:after < content: ""; display: block; position: absolute; right: 0; bottom: -3px; width: 0; height: 2px; /* Высота линии */ background-color: black; /* Цвет подчеркивания при исчезании линии*/ transition: width 0.5s; /* Время эффекта */ >.underline-one:hover:after < content: ""; width: 100%; display: block; position: absolute; left: 0; bottom: -3px; height: 2px; /* Высота линии */ background-color: red; /* Цвет подчеркивания при появлении линии*/ transition: width 0.5s; /* Время эффекта */ >

Анимация с подчёркивающей линией у ссылки CSS

Анимация с подчёркивающей линией у ссылки CSS подойдет как для ссылок, так и для заголовков и текста. Необходимо будет обернуть ссылку в дополнительный див, чтобы задать ему нужные свойства.

Читайте также:  Debian install php with nginx

Пример

HTML

CSS

 .link-ease-in-out a < display: inline-block; color: #00bfff; /* Цвет обычной ссылки */ line-height: 1; text-decoration: none; /* Убираем подчеркивание */ cursor: pointer; >.link-ease-in-out a:after < background-color: #f66d52; /* Цвет линии при наведении на нее курсора мыши */ display: block; content: ""; height: 2px; /* Высота линии */ width: 0%; -webkit-transition: width .3s ease-in-out; -moz--transition: width .3s ease-in-out; transition: width .3s ease-in-out; >.link-ease-in-out a:hover:after, .link-ease-in-out a:focus:after

Изменение фона и цвета ссылки CSS

Этот эффект при наведении одинаково подойдет как для ссылки, так и для того, чтобы выделить фрагмент текста. Его можно использовать, чтобы привлечь внимание посетителей и сделать свой сайт еще более интересным.

Пример

HTML

CSS

Увеличение текста при наведении CSS

Иногда нужно увеличить текст при наведении, этого можно добиться с помощью свойства transform с функцией scale(). Свойство transition отвечает за плавное увеличение текста, с помощью него устанавливаем время масштабирования. В зависимости от того, в каком положении находится текст, его масштабирование будет происходить по разному.

Пример

HTML

 

Lorem Ipsum

Lorem Ipsum

Lorem Ipsum

CSS

 /* Текст слева */ .gain-left < transition: 1s; /* Время эффекта */ text-align: left; >.gain-left:hover < transform: scale(1.2); /* Увеличиваем масштаб */ >/* Текст по центру */ .gain-center < transition: 1s; /* Время эффекта */ text-align: center; >.gain-center:hover < transform: scale(1.2); /* Увеличиваем масштаб */ >/* Текст справа */ .gain-right < transition: 1s; /* Время эффекта */ text-align: right; >.gain-right:hover < transform: scale(1.2); /* Увеличиваем масштаб */ >

Как добавить линию к заголовку с помощью :before и :after

Часто бывает, что необходимо добавить линию к заголовку, либо сверху, либо снизу. Конечно можно ограничиться простым свойством border-bottom, его можно настроить используя генератор границ блока, но при этом нельзя задать ширину линии отдельно от заголовка, а так же придать ей движение. Но когда это необходимо, можно сделать линию с помощью с помощью :before и :after.

Пример

Lorem Ipsum

HTML

CSS

 h3.title-example < font-size: 1em; /* Размер шрифта */ color: #5a5a5a; /* Цвет заголовка */ text-align: center; /* Текст по центру */ >/* CSS код для линии над заголовком */ h3.title-example:before < content: ''; display: block; height: 1px; /* Высота линии */ background: #f66d52; /* Цвет линии */ width: 150px; /* Ширина линии до наведения */ margin: 0 auto 10px; /* Отступ с боков по центру и снизу */ transition: 1s; /* Время, за которое линия возвращается после наведения */ >h3.title-example:hover:before < width: 250px; /* Ширина линии при наведении */ transition: ease-out 1s; /* Время, за которое линия расширяется при наведении */ >/* CSS код для линии под заголовком */ h3.title-example:after < content: ''; display: block; height: 1px; /* Высота линии */ background: #f66d52; /* Цвет линии */ width: 150px; /* Ширина линии до наведения */ margin: 10px auto 0; /* Отступ с боков по центру и сверху */ transition: 1s; /* Время, за которое линия возвращается после наведения */ >h3.title-example:hover:after < width: 250px; /* Ширина линии при наведении */ transition: ease-out 1s; /* Время, за которое линия расширяется при наведении */ >

Источник

Оцените статью