26

I've this code :

span p { margin: 0; } span { background-color: red; display: inline-block; border-radius: 50%; }
<span> <p>25</p> <p>08</p> </span>

I want to make a perfect circle on my span. I try a border-radius: 50%; but it does not work.

Thanks for the help !

6 Answers 6

43

You can do this by giving the span a fixed width and height:

span p { margin: 0; } span { background-color: red; display: inline-block; border-radius: 50%; width: 50px; height: 50px; text-align: center; }
<span> <p>25</p> <p>08</p> </span>

Sign up to request clarification or add additional context in comments.

1 Comment

add line-height of equal to height - to keep the text vertically in middle
5

You need a predefined width and height on the span to be able to make it round.

span p { margin: 0; } span { background-color: red; display: inline-block; border-radius: 50%; width:40px; height:40px; padding-left:10px; box-sizing: border-box; }
<span> <p>25</p> <p>08</p> </span>

Comments

1

add line-height and width:

span { background-color: #F00; display: inline-block; border-radius: 50%; width: 50px; line-height: 25px; text-align: center; } 

Comments

1

Use this code. HTML:

<span> <p>25</p> </span> <span> <p>08</p> </span> 

CSS:

span { background-color: red; display: inline-block; border-radius: 50%; width: 50px; height: 50px; text-align: center; } 

Comments

1

border-radius: 50% and padding

document.addEventListener('DOMContentLoaded', () => { let el = document.querySelector('#wrapper .container'); setTimeout(() => (el.style.marginTop = '20px'), 500); }, false);
#wrapper { display: flex; justify-content: center; } #wrapper .container { display: flex; flex-direction: column; align-items: center; padding: 6px 16px; font-family: sans-serif; font-size: 15px; font-weight: 500; border-radius: 50%; box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12); transition: margin-top 650ms ease-out, box-shadow 120ms, transform 120ms; will-change: margin-top, box-shadow, transform; user-select: none; cursor: pointer; } #wrapper .container:hover:not(:active) { box-shadow: 0 5px 4px -4px rgba(0, 0, 0, 0.1), 0 2px 10px 0px rgba(0, 0, 0, 0.08), 0 0px 10px 0px rgba(0, 0, 0, 0.08); } #wrapper .container:active { transform: scale(1.4) translateY(5px); box-shadow: 0 9px 11px -5px rgba(0, 0, 0, 0.2), 0 18px 28px 2px rgba(0, 0,0 , 0.14), 0 7px 34px 6px rgba(0, 0, 0, 0.12); }
<div id="wrapper"> <div class="container"> <span>10</span> <span>3</span> </div> </div>

Comments

0

It looks like you incorrectly nested paragraph elements inside of span, which is against HTML5 spec, as span is being defined there as an element, which Content Model is described as Phrasing Content, and that:

Most elements that are categorized as Phrasing Content can only contain elements that are themselves categorized as phrasing content, not any flow content.

And because paragraph element doesn't belong to Phrasing Content list, you can use div instead of span for this purpose, only if you care to be semantically correct.

So coming back to your problem, it can be rewritten as so:

HTML:

<div> <p>25</p> <p>08</p> </div> 

CSS:

p { margin: 0; text-align:center; } div { background-color: red; display: inline-block; border-radius: 50%; width:50px; height:50px; line-height:25px; } 

Where general rule for achieving the circle by using border radius set to 50%, is that you need to make sure that content of such element has the same width and height. You can get that by fixing these values in your css.

Here is JsFiddle presenting that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.