0

I want to put the circle in the middle of picture or div id=canvas

but ,it doesn't appear on the map.


I gave the background-color then it appears..

but it's not in the middle of map.

.circle{
 width: 100px;
 height: 100px;
 border-radius: 50%;
    position: absolute;
    z-index: 3;
    background-color:blue
}
<div id="mainBoard" class="board" style="margin:100px 0px 0px 0px;position:relative; width:100%;height:100%;">
<div id="canvas" style="border-style:solid;border-color:red;">
<img style="position:relative;top 0;left 0; width:100%" 
 src="https://staticmapmaker.com/img/google@2x.png">
 <div class='circle' style='top:50%;left:50%;'></div>
</div>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
whitebear
  • 11,200
  • 24
  • 114
  • 237

4 Answers4

1

Add border or background so you can see.

Use transform: translate(-50%, -50%);

.circle{
        width: 100px;
        height: 100px;
        border-radius: 50%;
        position: absolute;
        z-index: 3;
        background: red;
        transform: translate(-50%, -50%);
    }

.circle{
 width: 100px;
 height: 100px;
 border-radius: 50%;
    position: absolute;
    z-index: 3;
    background: red;
    transform: translate(-50%, -50%);
}
<div id="mainBoard" class="board" style="margin:50px 0px 0px 0px;position:relative; width:100%;height:100%;">
<div id="canvas" style="border-style:solid;border-color:red;">
<img style="position:relative;top 0;left 0; width:100%" 
 src="https://staticmapmaker.com/img/google@2x.png">
 <div class='circle' style='top:50%;left:50%;'></div>
</div>
</div>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lalji Tadhani
  • 14,041
  • 3
  • 23
  • 40
1

Use calc() to find position. The formulas are top:calc((100% - <object_height_value>)/2) and left:calc((100% - <object_width_value>)/2)

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  position: absolute;
  z-index: 3;
  background-color: blue;
  top: calc((100% - 100px)/2);
  left: calc((100% - 100px)/2);
}
<div id="mainBoard" class="board" style="margin:100px 0px 0px 0px;position:relative; width:100%;height:100%;">
  <div id="canvas" style="border-style:solid;border-color:red;">
    <img style="position:relative;top 0;left 0; width:100%" src="https://staticmapmaker.com/img/google@2x.png">
    <div class='circle'></div>
  </div>
</div>
Aleksandr Belugin
  • 2,149
  • 1
  • 13
  • 19
1

You could simply use background-image.

.map {
  width: 200px;
  height: 200px;
  
  background-position: 50%;
  background-image:
    radial-gradient(circle, blue 10%, transparent 10%), 
    url(https://staticmapmaker.com/img/google@2x.png); 
}
<div class="map"></div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
-1

Whats about this? Now you have the circle in the center.

#mainBoard {
  margin: 50px 0px 0px 0px;
  position: relative; 
  width: 100%;
  height: 100%;
}

#canvas {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  border: 2px solid red;
}

.circle{
  width: 5%;
  height: 3%;
  border-radius: 50%;
  position: absolute;
  z-index: 3;
  background-color:blue
}

img {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
}
<div id="mainBoard" class="board">
 <div id="canvas">
  <img src="https://staticmapmaker.com/img/google@2x.png">
  <div class="circle"></div>
 </div>
</div>
Mr. Jo
  • 4,946
  • 6
  • 41
  • 100