About this CSS code
This CSS code creates a tooltip-style box with a downward-pointing arrow using the :after
pseudo-element:
HTML
<div class="demo-arrow">Demo Arrow</div>
CSS
.demo-arrow {
position: relative;
background: #222222; /* Dark background */
color: #ffffff; /* White text */
padding: 10px 20px; /* Padding inside the box */
border-radius: 4px; /* Rounded corners */
}
.demo-arrow:after {
content: '';
position: absolute;
top: 100%; /* Position the arrow just below the box */
left: 50%; /* Center it horizontally */
margin-left: -10px; /* Offset it by half the width of the arrow */
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #222222;
}
Explanation
.demo-arrow
styles the main box.position: relative;
is necessary to position the arrow relative to this box..demo-arrow:after
creates the arrow. A triangle is created using border tricks.width
andheight
are0
, so the visible shape is made entirely from borders.border-left
andborder-right
are transparent, forming the triangle's sloped sides.border-top
is coloured (#222222
, same color as the background of the.demo-arrow
), forming the downward-pointing triangle (the arrowhead).
Arrow at the bottom
Arrow at the bottom with a utf-8 character
Arrow at the top of a container
Aside
Background color
Blackboard design
Breadcrumbs design
Calendar design
Checkboxes as circular buttons
Checkboxes as toggle switches
Cursor properties
Circular image with a shadow effect
Font Awesome pulled icons
Gallery picture frame with a price ribbon
Google pie chart
Google web fonts
Last child and not last child element
Letter spacing
List items with a Font Awesome icon
Neon text
Neon text with a flickering effect
Notebook paper background
Radio buttons as circular buttons
Radio buttons as rating stars
Remove the glow effect from an input field
Search bar with categories
Track (audio/video subtitles)
Web fonts
Whiteboard design