-1

how can I put the cross on the top right side of my page? For now it appears on the left side.

.close {
    vertical-align: middle;
    border: none;
    color: inherit;
    border-radius: 50%;
    background: transparent;
    position: relative;
    width: 32px;
    height: 32px;
    opacity: 0.6;
}
.close:focus,
.close:hover {
    opacity: 1;
    background: rgba(128, 128, 128, 0.5);
}
.close:active {
    background: rgba(128, 128, 128, 0.9);
}
.close::before,
.close::after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    height: 20px;
    width: 4px;
    background-color: currentColor;
}
.close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}
.close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

My snipped code :https://jsfiddle.net/Lcqy3srg/3/

Zokulko
  • 516
  • 2
  • 8

2 Answers2

0

float

Use float: right on .close

MDN

/*Button to quit the form*/

.close {
  vertical-align: middle;
  border: none;
  color: inherit;
  border-radius: 50%;
  background: transparent;
  position: relative;
  width: 20px;
  height: 20px;
  opacity: 0.6;
  float: right;
}

.close:focus,
.close:hover {
  opacity: 1;
  background: rgba(128, 128, 128, 0.5);
}

.close:active {
  background: rgba(128, 128, 128, 0.9);
}


/* tines of the X */

.close::before,
.close::after {
  content: " ";
  position: absolute;
  top: 50%;
  right: 0;
  height: 20px;
  width: 3px;
  background-color: currentColor;
}

.close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
<div>
  <button class="close" aria-label="Close"></button>
</div>

position

Using position: absolute and right: 0px will result in the same effect. It however requires more work, and might not work in many cases where you need to use a position other than absolute. (for example in this case, it gives a scroll bar because it was intended to use relative)

MDN

/*Button to quit the form*/

.close {
  vertical-align: middle;
  border: none;
  color: inherit;
  border-radius: 50%;
  background: transparent;
  position: absolute; /*Changed to absolute*/
  width: 20px;
  height: 20px;
  opacity: 0.6;
  right: 0px;
}

.close:focus,
.close:hover {
  opacity: 1;
  background: rgba(128, 128, 128, 0.5);
}

.close:active {
  background: rgba(128, 128, 128, 0.9);
}


/* tines of the X */

.close::before,
.close::after {
  content: " ";
  position: absolute;
  top: 50%;
  right: 0;
  height: 20px;
  width: 3px;
  background-color: currentColor;
}

.close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
<div>
  <button class="close" aria-label="Close"></button>
</div>
Some guy
  • 148
  • 10
-1

you simply can add div "content" as parent of div "close"

 .content {

    position:absolute ;
    top:0;
    right:0;
}

Code screenshot:

enter image description here

RBT
  • 21,293
  • 19
  • 144
  • 210
Sanae
  • 1
  • 1