Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position icon at the top right corner of a div

Tags:

html

css

I created this code, but I don't able to put the icon on the right corner of div with class valori.

Here the desired result :

enter image description here

Here the code :

HTML

<div class="circletop">
<div class="numberpr">3° anno</div>
<div class="lordo">Valore lordo stimato</div>
<!--I add div icon here-->
<div class="icon"></div>
<div class="valori"> <?=$min3_anno ." - " . $max3_anno?></div>
</div>

Here my fiddle : https://jsfiddle.net/5g42Lx7n/ I need to add the icon in the top right corner like image.

thanks

like image 981
Em1991 Avatar asked Jan 29 '19 09:01

Em1991


People also ask

How do you put a button in the top right corner of a div?

If you want to move the button to the right, you can also place the button within a <div> element and add the text-align property with its "right" value to the "align-right" class of the <div>.

How do you move icons to top right in CSS?

Try using float: right; and a new div for the top so that the image will stay on top.

How do I align the icon on the right side?

display: To display text and icons side by side, we will use the display: flex property. float: To set the icon on the right side of the div, we use float: right property.

How do you position an element to the right?

If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.


2 Answers

Check https://jsfiddle.net/bgo2e5zk/4/

.icon{position:absolute;right:0;top:-15px}
.valori{position:relative;}


I put the icon inside .valori, then add position:relative to .valori and position:absolute to .icon, and to finish, set top and left to the icon to positioning it.

like image 112
Roy Bogado Avatar answered Sep 21 '22 17:09

Roy Bogado


You can add an icon like your showing image, here is the solution

HTML:-

<div class="circletop">
  <div class="numberpr">3° anno</div>
  <div class="lordo">Valore lordo stimato</div>
  <!--I add div icon here-->
  <div class="icon">my icon</div>
  <div class="valori"> &euro; 65.000 - &euro; 67.000</div>
</div>

CSS:-

.circletop {
  /* circle styles */
  width: 300px;
  height: 300px;
      font-family: Raleway;
  border: 1px solid #222;
  border-radius: 50%;
  margin: 0 auto;
      box-shadow: 0 0 20px #ccc;

  /* become a flex container */
  /* its children will be flex items */
  display: flex;
  /* place items in column */
  flex-direction: column;
  /* center flex items horizontally */
  align-items: center;
  /* center all content vertically */
  justify-content: center;
}

/* simulate one more item to "balance" dex text */
.circletop:before {
  content: "\A0";
  visibility: hidden;
}

.lordo {
    color: #45cec8;
           padding-top: 10px;
    padding-bottom: 25px;
    font-weight: bold;
        font-size: 19px;
}

.valori {
    border-radius: 50px;
    background: #05c6bf;
    padding: 14px;
    width: 100%;
    color: #fff;
    text-align: center;
    box-shadow: 0 0 9px #45cec8;
        font-size: 25px;
    font-weight: bold;
}
.icon {
    position: relative;
    bottom: -19px;
    right: -162px;
}
like image 25
g8bhawani Avatar answered Sep 21 '22 17:09

g8bhawani