Svg horizontal line between background - javascript
.left-wave-container {
line-height: 0 !important;
width: 100%;
height: 100%;
}
.container {
width: 100vw;
height: 50vh;
background: #2196f3;
}
<div className="left-wave-container">
<div className="svg-container">
<svg xmlns="http://www.w3.org/2000/svg" width="1280" height="430" viewBox="0 0 1280 430"><path d="M0,465V35A96.575,96.575,0,0,0,.64,46.15,94.294,94.294,0,0,0,2.56,56.94C15.71,112.271,78.9,153.52,171,186.521v.159c116.77,41.85,280,70.44,446.67,97.681,6,1,12,2,18,2.93C682.9,295,730.32,302.6,776.9,310.43c3.73.61,7.45,1.25,11.16,1.87,2.72.46,5.431.93,8.131,1.37l7.59,1.291,2.05.35c5.07.869,10.139,1.74,15.179,2.62C890.64,330,957.62,342.71,1018.56,357c5.45,1.29,10.86,2.569,16.21,3.88q13.49,3.28,26.54,6.7,7.53,2,14.9,4l1.2.329c5.65,1.53,11.2,3.1,16.691,4.691,1.2.329,2.36.68,3.54,1,81,23.559,145.33,51.53,182.08,86.95l.28.26V465Z" transform="translate(0 -35)" fill="#2196f3"/>
</svg>
</div>
<div className="container">
</div>
</div>
I'm trying to put together one svg header with a wave with the same background color that it has but in the bottom in specifics viewport sizes one line is displayed between them.
One curious things is, when I don't alter the width of height in the CSS or directly in the svg the horizontal line disappear but it just has the size ah the beggining, no the full viewport (I realize this when I upload the snippet).
Thanks for read!
Drew your wave in Inkscape
Removed SVG from the markup width =" 1280" height ="430"
Now the application will be adaptive at any screen resolution.
Styles did not work because there was <div className =" container ">
write <div class =" container "> correctly
.left-wave-container {
width: 100%;
height: 100%;
line-height: 0 !important;
}
.container {
width: 100%;
height: 100%;
background: #2196f3;
}
<div class="left-wave-container">
<div class="svg-container">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 430">
<path d="m2.7 20.4c-1.2-35.4-1.3 4.9 17.7 35.5 19.1 30.6 57.4 52.9 91.9 68.1 130.2 56.1 261.7 80.2 377.8 101.5 187.9 32.6 388.1 61.4 560.4 103 39.4 9.7 74.8 18.1 117.1 33.6 37.9 13.9 135.6 67.5 100.7 67.1C995.4 425.3 1.6 425.3 1.6 425.3c0 0 2.1-377.7 1.2-404.9z" transform="translate(0 5)" fill="#2196f3" stroke="#2196f3" stroke-width="10"/>
</svg>
</div>
<div class="container">
</div>
</div>
Related
scroll bar with horizontal scroll sticking in the body
I'm asking you for some help because I'm struggling a bit with CSS/JS, it's been a long time since I've practiced. Basically I'm trying to make a section with a "sticky" title that scrolls horizontally with a block just below it that also stays sticky until I finish making this horizontal scrolling. I managed to set up the structure but I think I need to add some more JS or modify what has been done. Currently I have 2 scrollbars I would like to have only one but that acts like I have two. I put you the JSfiddle it will be more clear: https://jsfiddle.net/ps4b10ro const spaceHolder = document.querySelector('.space-holder'); const horizontal = document.querySelector('.horizontal'); spaceHolder.style.height = `${calcDynamicHeight(horizontal)}px`; function calcDynamicHeight(ref) { const vw = window.innerWidth; const vh = window.innerHeight; const objectWidth = ref.scrollWidth; return objectWidth - vw + vh + 150; // 150 is the padding (in pixels) desired on the right side of the .cards container. This can be set to whatever your styles dictate } window.addEventListener('scroll', () => { const sticky = document.querySelector('.sticky'); horizontal.style.transform = `translateX(-${sticky.offsetTop}px)`; }); window.addEventListener('resize', () => { spaceHolder.style.height = `${calcDynamicHeight(horizontal)}px`; }); var swiper = new Swiper('.swiper-container', { direction: 'vertical', mousewheelControl: true, slidesPerView: 1, // freeMode: true, // freeModeSticky: true }); *, *::before, *::after { box-sizing: inherit; } html { box-sizing: border-box; font-size: 100%; } body { margin: 0; font-family: sans-serif; } .container { position: relative; width: 100%; min-height: 100vh; } .space-holder { background-color: #111; position: relative; width: 100%; } .sticky { height: 100vh; position: sticky; top: 0; height: 100vh; width: 100%; overflow-x: hidden; } .horizontal { position: absolute; height: 100%; will-change: transform; } .cards { position: relative; height: fit-content; padding: 0 0 0 150px; display: flex; flex-flow: row nowrap; justify-content: flex-start; align-items: center; } .horizontalText { color: #fff; font-size: 4em; padding: 0 3vw 0 3vw; width: 53vw; height: fit-content; } .etsy { background-color: #fff; margin-top: 22vh; height: 400px; position: sticky; bottom: 350vh; height: 100%; overflow: hidden; } .test { background-color: blanchedalmond; height: 1000px; } <div class="test"></div> <div class="module"></div> <section class="container"> <div class="space-holder"> <div class="sticky"> <div class="horizontal"> <section role="feed" class="cards"> <h2 class="horizontalText">Discovers our products</h2> <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="24" cy="24" r="24" fill="#EDD337"/> </svg> <h2 class="horizontalText">Discovers our universe</h2> <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="24" cy="24" r="24" fill="#EDD337"/> </svg> <h2 class="horizontalText">Discovers our products</h2> <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="24" cy="24" r="24" fill="#EDD337"/> </svg> <h2 class="horizontalText">Discovers our universe</h2> <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"> <circle cx="24" cy="24" r="24" fill="#EDD337"/> </svg> <h2 class="horizontalText">Discovers our products</h2> </section> </div> <section class="etsy sticky"> <section id="emporter container" class="blanc hori"> <div class="wrap"> <div class="defilement"> <a href="/articles/damien-rice"> <div class="cover" style="background:url(https://cdn.blogotheque.net/blogotheque/2019/11/18/fd9c7d252ab9de5569c9fcc96aabaaff.jpg) 50% 50%"> <div><img src="/packs/media/img/play-9e06fa89856b9d33899e081448a066f5.svg" alt=""></div> </div> <h3>Damien Rice</h3> <p>Soirée de Poche #54</p> </a> <a href="/articles/benjamin-booker-25870"> <div class="cover" style="background:url(https://cdn.blogotheque.net/blogotheque/2020/01/02/27cd1d46f726bf3e4c15a79ad42e8e0a.png) 50% 50%"> <div><img src="/packs/media/img/play-9e06fa89856b9d33899e081448a066f5.svg" alt=""></div> </div> <h3>Benjamin Booker</h3> <p>Soirée de Poche #53</p> </a> <a href="/articles/shame"> <div class="cover" style="background:url(https://cdn.blogotheque.net/blogotheque/2019/11/18/ec085ebc867db30fc41f8be3b247ec37.jpg) 50% 50%"> <div><img src="/packs/media/img/play-9e06fa89856b9d33899e081448a066f5.svg" alt=""></div> </div> <h3>Shame</h3> <p>Soirée de Poche #52</p> </a> <a href="/articles/hamilton-leithauser"> <div class="cover" style="background:url(https://cdn.blogotheque.net/blogotheque/2019/12/05/b56f9fbe55b912ad931376338a655440.png) 50% 50%"> <div><img src="/packs/media/img/play-9e06fa89856b9d33899e081448a066f5.svg" alt=""></div> </div> <h3>Hamilton Leithauser</h3> <p>Soirée de Poche #51</p> </a> </div> <div class="navigation"> <!-- <img class="pointer gauche bloque" src="img/agaucheN.svg" alt="" /> --> <svg class="pointer gauche bloque" height="40" viewBox="0 0 40 40" width="40" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd" stroke="#111" stroke-width="2" transform="matrix(1 0 0 -1 0 40)"><circle cx="20" cy="20" r="19"></circle><path d="m22.3823529 14-6.3823529 6.3823529 6.3823529 6.4852942"></path></g></svg> <!-- <img class="pointer droite" src="img/agaucheN.svg" alt="" /> --> <svg class="pointer droite" height="40" viewBox="0 0 40 40" width="40" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd" stroke="#111" stroke-width="2" transform="matrix(1 0 0 -1 0 40)"><circle cx="20" cy="20" r="19"></circle><path d="m22.3823529 14-6.3823529 6.3823529 6.3823529 6.4852942"></path></g></svg> <div class="progress"> <div style="transform: matrix(0.2, 0, 0, 1, 0, 0);"></div> </div> </div> </div> </section> </section> <div class="test"> </div> Thank you in advance for your help and or your advice
Create a dotted path that follows a curve
I have a design I'm trying to port over to code, the design is as follows: I've created the majority of the design in code already (just a prototype so the html/css isn't perfect), but the area I'm struggling with is the dotted progression that you can see within the curved path .frame { width: 375px; height: 750px; background: #171B42; background: linear-gradient(to bottom, #171B42, #171B42 50%, #3C98FF 110%); position: relative; } #earth { position: absolute; bottom: 0; left: 0; right: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%) } .locked { text-align: center; margin: 76px auto; width: 230px; position: relative; } .locked img { width: 60px; margin: 0 26px; } .locked.row-1:after { content: ""; width: 163px; height: 175px; background: url(https://i.imgur.com/u6v9Dkd.png) center center no-repeat; background-size: cover; position: absolute; top: -130px; right: -50px; bottom: 0; z-index: -1; } .locked.row-2:after { content: ""; width: 163px; height: 175px; background: url(https://i.imgur.com/u6v9Dkd.png) center center no-repeat; background-size: cover; position: absolute; top: -127px; left: -46px; bottom: 0; z-index: -1; transform: rotate(180deg); } .path-map { position: absolute; bottom: 180px; left: 0; right: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%); width:375px; } <div class="frame"> <div class="path-map"> <div class="locked row-2"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> </div> <div class="locked row-1"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> </div> </div> <img id="earth" src="https://i.imgur.com/RR8kQx1_d.webp?maxwidth=728&fidelity=grand"/> </div> I'm wondering if anyone has any ideas on how to create that dotted path, it might require some javascript? I'm not entirely sure what the best way of solving this would be outside of just manually adding each dot with position: absolute. Any help would be amazing, thank you!
Here's an example of how this can be done using SVG <path> elements, <use> elements, a <mask> element, the stroke-dasharray attribute, and the stroke-linecap attribute. You can define a single <path> element once, and then reuse it multiple times with different stroke styles or masks applied to it, which is especially handy in this case. body { background: darkblue; } <svg viewBox="0 0 515 515"> <defs> <mask id="mask"> <rect fill="black" x="0" y="0" width="515" height="515"></rect> <rect fill="white" x="0" y="200" width="515" height="315"></rect> </mask> <path id="path" fill="none" d="M138 414C192.333 414 312.8 414 360 414C419 414 504 262 360 262C216 262 261 262 153 262C45 262 39 130 144 130C249 130 327 130 378 130C429 130 452 83 452 -2C452 -87 472 -87 452 -87"></path> </defs> <!-- solid wide line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="20"></use> <!-- solid narrow line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="10"></use> <!-- dotted full line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="5" stroke-dasharray="0 10" stroke-linecap="round"></use> <!-- dotted masked line --> <use href="#path" stroke="rgba(255,255,255,0.8)" stroke-width="5" stroke-dasharray="0 10" stroke-linecap="round" mask="url(#mask)"></use> </svg>
Making the div follow autoresize textarea? [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question PROBLEM I have a comment textarea which i made text responsive thanks to Jack Moores npm package https://www.jacklmoore.com/autosize/. Now this all works fine but i have a div which is usually bottom:75px; and when textarea autoresizes it updates the hight of textarea. This is where the problem occurs i would like to update also bottom of that div for example to keep it from going over textarea. HTML <form action="#"> <textarea type="text" id="text" spellcheck="false" placeholder="Type message..." maxlength="50" ></textarea> </form> <div class="three_dots_messages" onclick="toggleMessagesSettings()"></div> <div class="three_dots_messages_menu"> <div class="three_dots_messages_menu_buttons"> <div class="send_tip_button all_message_buttons" > <span>Send tip</span> <svg xmlns="http://www.w3.org/2000/svg" width="7.886" height="15" viewBox="0 0 7.886 15" style="margin: 2px 0 0 2px ;"> <path id="Icon_awesome-dollar-sign" data-name="Icon awesome-dollar-sign" class="cls-1" d="M5.731,6.838,2.773,5.912a.861.861,0,0,1-.581-.829A.837.837,0,0,1,3,4.219H4.817a1.6,1.6,0,0,1,.937.308.406.406,0,0,0,.534-.059l.953-1a.5.5,0,0,0-.049-.718,3.716,3.716,0,0,0-2.369-.879V.469A.456.456,0,0,0,4.384,0H3.507a.456.456,0,0,0-.438.469V1.875H3a3.133,3.133,0,0,0-2.985,3.5,3.293,3.293,0,0,0,2.3,2.83l2.807.879a.864.864,0,0,1,.581.829.837.837,0,0,1-.808.864H3.075a1.6,1.6,0,0,1-.937-.308.406.406,0,0,0-.534.059l-.953,1a.5.5,0,0,0,.049.718,3.716,3.716,0,0,0,2.369.879v1.406A.456.456,0,0,0,3.507,15h.876a.456.456,0,0,0,.438-.469V13.119a3.108,3.108,0,0,0,2.9-2.13A3.264,3.264,0,0,0,5.731,6.838Z" transform="translate(-0.003)"/> </svg> </div> <div class="chat_rules_button all_message_buttons" > <span>Chat rules</span> <svg xmlns="http://www.w3.org/2000/svg" width="13.125" height="15" viewBox="0 0 13.125 15"> <path id="Icon_awesome-book-dead" data-name="Icon awesome-book-dead" class="cls-1" d="M7.969,3.984A.469.469,0,1,0,7.5,3.516.47.47,0,0,0,7.969,3.984ZM13.125,10.5V.75a.69.69,0,0,0-.75-.75H2.813A2.762,2.762,0,0,0,0,2.813v9.375A2.762,2.762,0,0,0,2.813,15h9.563a.739.739,0,0,0,.75-.75v-.469a.81.81,0,0,0-.281-.562,8.292,8.292,0,0,1,0-2.156.567.567,0,0,0,.281-.562ZM7.031,1.641A2.15,2.15,0,0,1,9.375,3.516a1.778,1.778,0,0,1-.937,1.491v.384a.47.47,0,0,1-.469.469H6.094a.47.47,0,0,1-.469-.469V5.007a1.778,1.778,0,0,1-.937-1.491A2.15,2.15,0,0,1,7.031,1.641Zm-3.375,4.9.185-.431a.233.233,0,0,1,.308-.123l2.88,1.233L9.911,5.988a.233.233,0,0,1,.308.123l.185.431a.233.233,0,0,1-.123.308l-2.06.885,2.06.882a.233.233,0,0,1,.123.308l-.185.431a.233.233,0,0,1-.308.123L7.031,8.244,4.151,9.48a.233.233,0,0,1-.308-.123l-.185-.431a.233.233,0,0,1,.123-.308l2.063-.882L3.779,6.85a.233.233,0,0,1-.123-.308Zm7.5,6.583H2.813a.886.886,0,0,1-.937-.937.939.939,0,0,1,.938-.937h8.344ZM6.094,3.984a.469.469,0,1,0-.469-.469A.47.47,0,0,0,6.094,3.984Z"/> </svg> </div> <div class="muted_users all_message_buttons" > <span>Muted users</span> <svg xmlns="http://www.w3.org/2000/svg" width="16.071" height="15" viewBox="0 0 16.071 15"> <path id="Icon_metro-volume-mute2" data-name="Icon metro-volume-mute2" class="cls-1" d="M18.642,13.15V14.57H17.222l-1.794-1.794L13.634,14.57H12.214V13.15l1.794-1.794L12.214,9.562V8.142h1.421l1.794,1.794,1.794-1.794h1.421V9.562l-1.794,1.794ZM9.535,18.856a.535.535,0,0,1-.379-.157L5.027,14.57H3.106a.536.536,0,0,1-.536-.536V8.677a.536.536,0,0,1,.536-.536H5.027L9.156,4.013a.536.536,0,0,1,.915.379V18.32a.536.536,0,0,1-.536.536Z" transform="translate(-2.571 -3.856)"/> </svg> </div> <div class="close_chat_button all_message_buttons" onclick="toggleMessagesSettings(), toggleMessages() "> <span>Close chat</span> <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 15 15"> <path id="Icon_material-close" data-name="Icon material-close" class="cls-1" d="M22.5,9.011,20.989,7.5,15,13.489,9.011,7.5,7.5,9.011,13.489,15,7.5,20.989,9.011,22.5,15,16.511,20.989,22.5,22.5,20.989,16.511,15Z" transform="translate(-7.5 -7.5)"/> </svg> </div> </div> </div> CSS .three_dots_messages_menu { position: fixed; width: 15%; height: 130px; min-width: 232px; bottom: -250px; background-color: #363636; border-radius: 5px; opacity: 0; transition: 0.3s; } #text { border: 1px solid #d4af37; background-color: #343333; position: fixed; bottom: 15px; margin: 0 auto; font-size: 17px; width: 13%; padding: 12px 30px 5px 10px; color: white; border-radius: 5px; min-width: 190px; min-height: 33px; height: 33px; max-height: 100px; outline: none; resize: none; } SOME INFORMATION AND QUESTIONS I need to keep it position absolute not just fix this with margins. I know i can do this modifying the js of autosize but i am honestly not skilled enough to completely understand everything that is going on. Is there a way to maybe manipulate the DOM so i can make div children of that textarea ? Do you know maybe easy js fix ? JS for autoresize is too big you can view it from the website
It's best if you simply move the menu to a point before the textarea and remove its fixed positioning, so that it automatically remains in place. If you want to adapt it dynamically, Autosize triggers an event where you can hook some code to update its position. var $text = jQuery('#text'), $menu = jQuery('.three_dots_messages_menu'), baseDistance = 75; $text.on( 'autosize:resized', function() { $menu.css( 'bottom', $text.height() + baseDistance + 'px' ); })
Scrolling with multiple SVGs
I am trying to create 4 svg based charts one below another. After charts are loaded, I can see only 2 and half charts which get occupied on web browser without scrolling. I can see scroll bars enabled in left and at the bottom but they don't scroll much. <div overflow="auto"> <svg id="chart1" style="overflow-y:scroll"></svg> <svg id="chart2" style="overflow-y:scroll"></svg> <svg id="chart3" style="overflow-y:scroll"></svg> <svg id="chart4" style="overflow-y:scroll"></svg> </div> Above are 4 svg and below is the css for each of them. #chart1 { width: 100%; height: 100%; position: absolute; } When I minimize the webpage, I can see 4 charts otherwise 2 and half only. What all I have tried: 1. enabling auto-scroll for html, body 2. enabling scroll in svg (similar to above code). 3. increasing html and body height and width. html, body { width: 100%; height: 200%; margin: 0px; padding: 0px; }
Here is a example on jsfiddle, each svg has a data-no, and one common class. It is more easy with this example for you to explain what you expect exactly... https://jsfiddle.net/ericsm/ondtxmp2/ and here the code too : each svg take 100% of body. <HTML> <HEAD> <style type="text/css"> .container-charts { border:solid 8px blue; div : 100%; } .chart { width: 100%; height: 100%; border:dashed 2px green; } html, body { margin: 0px; padding: 0px; } </style> </HEAD> <BODY> <div class="container-charts" overflow="auto"> <svg class="chart" data-no="1"> <ellipse cx="100" cy="80" rx="100" ry="50" style="fill:yellow;stroke:purple;stroke-width:2" /> </svg> <svg class="chart" data-no="2"> <ellipse cx="100" cy="80" rx="100" ry="50" style="fill:blue;stroke-width:2" /> </svg> <svg class="chart" data-no="3"> <ellipse cx="100" cy="80" rx="100" ry="50" style="fill:gray;stroke-width:2" /> </svg> <svg class="chart" data-no="3"> <ellipse cx="100" cy="80" rx="100" ry="50" style="fill:black;stroke-width:2" /> </svg> </div> </BODY> </HTML>
IE & Firefox rendering incorrectly but not in Chrome, Safari & Chromium browsers
All, There is a double walled circle and a text. Ideally the text should be rendered within the circle but in IE & Firefox , the circle is coming down and the text on the top. The issue can be seen using the below code. Any help or advice on how to get it fixed in IE & firefox is much appreciated. <div class="col-xs-4 col-sm-2"> <div style="margin-top: 20px; position: relative; display: inline-block; max-width: 116px; max-height: 116px;"> <svg width="100%" height="100%" viewBox="0 0 418 418" tabindex="-1"> <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g transform="translate(-31.000000, -31.000000)" stroke="#9B9B9B" stroke-width="2" fill="#FFFFFF"> <g transform="translate(32, 32)"> <path d="M208,416 C322.875228,416 416,322.875228 416,208 C416,93.124772 322.875228,0 208,0 C93.124772,0 -9.09494702e-13,93.124772 -9.09494702e-13,208 C-9.09494702e-13,322.875228 93.124772,416 208,416 Z"></path> <path d="M208,398.666667 C313.302292,398.666667 398.666667,313.302292 398.666667,208 C398.666667,102.697708 313.302292,17.3333333 208,17.3333333 C102.697708,17.3333333 17.3333333,102.697708 17.3333333,208 C17.3333333,313.302292 102.697708,398.666667 208,398.666667 Z"></path> </g></g></g> </svg> <span style="font-size: 24px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">400</span> </div> </div>
The styling you have added to the divs pushes the number outside of the SVG. I would just avoid the problem in the first place by using an SVG <text> element that you can position inside the svg. You might have to fiddle with the x and y values a bit. ps: There's also a <circle> element you could use instead of a <path>. <svg width="100%" height="100%" viewBox="0 0 418 418" tabindex="-1"> <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g transform="translate(-31.000000, -31.000000)" stroke="#9B9B9B" stroke-width="2" fill="#FFFFFF"> <g transform="translate(32, 32)"> <path d="M208,416 C322.875228,416 416,322.875228 416,208 C416,93.124772 322.875228,0 208,0 C93.124772,0 -9.09494702e-13,93.124772 -9.09494702e-13,208 C-9.09494702e-13,322.875228 93.124772,416 208,416 Z"></path> <path d="M208,398.666667 C313.302292,398.666667 398.666667,313.302292 398.666667,208 C398.666667,102.697708 313.302292,17.3333333 208,17.3333333 C102.697708,17.3333333 17.3333333,102.697708 17.3333333,208 C17.3333333,313.302292 102.697708,398.666667 208,398.666667 Z"></path> </g> </g> </g> <text x="47%" y="49%" style="font-size: 32px;">400</text> </svg>
I don't know what are your constraints, but to render these circles in particular I'd play with border-radius: 50% and display: flex: .circle { border: 2px solid #888; border-radius: 50%; /* make the border a circle */ display: flex; /* align the content vertically and horizontally */ align-items: center; /* same */ justify-content: space-around; /* same */ } <div class="circle" style="width: 100px; height: 100px;"> <div class="circle" style="width: 90px; height: 90px;"> 400 </div> </div>