Javascript-форум (https://javascript.ru/forum/)
-   (X)HTML/CSS (https://javascript.ru/forum/xhtml-html-css/)
-   -   Уголок на css через псевдоэлемент (https://javascript.ru/forum/xhtml-html-css/66961-ugolok-na-css-cherez-psevdoehlement.html)

Quark_ 20.01.2017 11:33

Уголок на css через псевдоэлемент
 
Подскажите, плиз, как сделать такой уголок на css с помощью :before?

ksa 20.01.2017 11:49

Цитата:

Сообщение от Quark_
как сделать такой уголок на css с помощью :before?

Как вариант:
- обычный красный квадрат :before
- перекрыть его сверху белым фоном родителя

Black_Star 20.01.2017 12:01

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css" media="screen">
	.block{
		position: relative;
		width: 150px;
		height: 150px;
		background-color: #f00;
	}

	.block:before{
		position: absolute;
		content: "";
		left: 20%;
		top: 20%;
		width: inherit;
		height: inherit;
		z-index: 2;
		background-color: #fff; // цвет должен быть такой же как и твой фон 
	}
</style>
</head>
<body>
	<div class="block"></div>
</body>
</html>

ksa 20.01.2017 13:30

Цитата:

Сообщение от ksa
- обычный красный квадрат :before
- перекрыть его сверху белым фоном родителя

Мой вариант не получится... :no:
Т.к. z-index элемента и его псевдоэлемента будет как у элемента. :(

<style type='text/css'>
div {
	position: relative;
	width: 100px;
	height: 100px;
	margin: 100px;
	z-index: 2;
	background-color: green;
}
div:before {
	content: '';
	display: block;
	position: relative;
	top: -10px;
	left: -10px;
	width: 50px;
	height: 50px;
	z-index: 1;
	background-color: red;
}
</style>
<div></div>

ksa 20.01.2017 13:51

Такой вот шахер-махер предложу...
<style type='text/css'>
div {
	width: 100px;
	height: 100px;
	margin: 100px;
	background-color: green;
}
div:before,
div:after {
	content: '';
	display: block;
	position: relative;
	left: -10px;
	background-color: red;
}
div:before {
	top: -10px;
	width: 50px;
	height: 10px;
}
div:after {
	top: -20px;
	width: 10px;
	height: 50px;
}
</style>
<div></div>

ruslan_mart 20.01.2017 14:02

Я бы сделал так:

div {
  background: #FFF;
  height: 100px;
  position: relative;
  width: 100px;
}
div::before {
  border: 5px solid red;
  border-bottom: none;
  border-right: none;
  box-sizing: border-box;
  content: '';
  height: 20px;
  left: -7px;
  position: absolute;
  top: -7px;
  width: 20px;
}

ksa 20.01.2017 14:11

Цитата:

Сообщение от Ruslan_xDD
Я бы сделал так

Я забываю, что есть бордюры... :D


Часовой пояс GMT +3, время: 05:56.