Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place css arrow on top of image

Tags:

html

css

i need place small css arrow in top right corner of img, like this enter image description here

Here is my css code for arrow, but I dont know how to put it together.

.cssarrow {
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 20px 20px 0;
    border-color: transparent blue transparent transparent;
}

thx for help

like image 980
Michal Loksik Avatar asked Dec 02 '25 07:12

Michal Loksik


2 Answers

First wrap the image and the arrow by a <div> element as follows:

<div class="wrapper">
    <img src="http://lorempixel.com/250/200" alt="">
    <div class="cssarrow"></div>
</div>

Then use absolute positioning to place the arrow on top-right corner of the wrapper div:

EXAMPLE HERE

.wrapper {
  position: relative;    /* Establish a containing block for the absolute element */
  display: inline-block; /* To make width fit to the content */
}

.wrapper img {
  vertical-align: middle; /* Fix the gap under the inline level element */
}

.cssarrow {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 20px 20px 0;
  border-color: transparent gold transparent transparent;

  position: absolute; /* Remove the element from normal flow */
  top: 0; right: 0;   /* Position the element at top-right corner of the wrapper */
}
like image 97
Hashem Qolami Avatar answered Dec 03 '25 22:12

Hashem Qolami


possible to use pseudo-class DEMO

<div class="wrap">
  <img src="http://placehold.it/350x150" alt="">
</div>

.wrap {
  position: relative;
  display: inline-block;
}

.wrap:after {
  position: absolute;
  top: 0; right: 0;
  content: "";
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 30px 30px 0;
  border-color: transparent blue transparent transparent;
}
like image 42
Alex Wilson Avatar answered Dec 03 '25 22:12

Alex Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!