Блоки со стрелками (часть 1)

Добавить стрелки к блоку (tooltip) можно с помощью псевдо-элемента :before.

<div class="arrow">
	Пример блока со стрелкой CSS
</div>
HTML
1

Слева

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;    
	left: 8px;    
	bottom: 100%;
	border-bottom-color: #eee;
	border-width: 9px;
	margin-left: 0;
}
CSS

По центру

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;   
	bottom: 100%;
	left: 50%;
	border-bottom-color: #eee;
	border-width: 9px;
	margin-left: -9px;
}
CSS

Справа

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute; 
	bottom: 100%;
	right: 8px;
	border-bottom-color: #eee;
	border-width: 9px;
	margin-right: -1px;
}
CSS
2

Слева

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute; 
 	top: 100%;
	left: 16px;
	border-top-color: #eee;
	border-width: 9px;
	margin-left: -1px;
}
CSS

По центру

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;
 	top: 100%;
	left: 50%;
	border-top-color: #eee;
	border-width: 9px;
	margin-left: -9px;
}
CSS

Справа

.arrow {
	width: 300px;
	padding: 10px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute; 
 	top: 100%;
	right: 8px;
	border-top-color: #eee;
	border-width: 9px;
	margin-right: -1px;
}
CSS
3

Сверху

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;  
	right: 100%;
	top: 8px;
	border-right-color: #eee;
	border-width: 9px;
	margin-top: -1px;
}
CSS

По центру

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;  
	right: 100%;
	top: 50%;
	border-right-color: #eee;
	border-width: 9px;
	margin-top: -9px;
}
CSS

Снизу

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;    
	right: 100%;
	bottom: 8px;
	border-right-color: #eee;
	border-width: 9px;
	margin-bottom: -1px;
}
CSS
4

Сверху

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;    
	left: 100%;
	top: 8px;
	border-left-color: #eee;
	border-width: 9px;
	margin-top: -1px;
}
CSS

По центру

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;    
	left: 100%;
	top: 50%;
	border-left-color: #eee;
	border-width: 9px;
	margin-top: -9px;
}
CSS

Снизу

.arrow {
	width: 300px;
	padding: 20px 10px;
	position: relative;
	background: #eee;
	border-radius: 3px;   
}
.arrow:before {
	content: ""; 
	border: solid transparent;
	position: absolute;    
	left: 100%;
	bottom: 8px;
	border-left-color: #eee;
	border-width: 9px;
	margin-bottom: -1px;
}
CSS
14.03.2019, обновлено 14.01.2022
26949
Предыдущая запись Текст с градиентом
Следующая запись Блоки со стрелками (часть 2)

Комментарии

, чтобы добавить комментарий.

Другие публикации

Contenteditable – текстовый редактор
Если добавить атрибут contenteditable к элементу, его содержимое становится доступно для редактирования пользователю, а...
43704
+34
Табы/вкладки на jQuery
Сделать табы на jQuery очень просто, сделаем HTML разметку и добавим к нему JS код...
31659
+7
Мануал по созданию и форматированию excel файлов в PHPExcel
К сожалению разработчики прекратили поддержку и разработку проекта, но PHPExcel все равно остается популярной...
129294
+37
Видео c YouTube в качестве фона сайта
Пара примеров как сделать блок с адаптивным видео в качестве фона на основе видеоплеера HTML5, YouTube и JQuery.
16344
+1
Перечёркивание текста по диагонали
Несколько примеров как зачеркнуть текст по диагонали с помощью псевдоэлементов CSS :before и :after.
14416
+3
Горизонтальное меню justify
В отличии предыдущего меню, где есть отступы у каждого элемента, часто возникает задача сделать резиновое меню без них. Пункты меню должно идти с одинаковыми интервалами и без отступов по бокам.
8446
-1