html - Centering a text in div not working -
Hi, I'm trying to focus the text in the first circle div. I think it is currently in the center of the divi, but when there are more than 200 characters, it looks like the bottom I have a red circle background and trying to make the text in the center regardless of the characters . Thank you in advance!
. Main {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Display: inline-block;} .man .label {display: inline-block;} .bg {background: red; Padding: 10px; font-weight: bold; Color: #fff; Display: Inline-block; Border-radius: 60%;} .bg .label {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Width: 10px; Display: Inline-block; Margin: Auto;} & lt; Div class = "main" & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 200 & lt; / Span & gt; & Lt; / Div & gt; & Lt; Span class = "label" & gt; It should be other text & lt; / Span & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 0 & lt; / Span & gt; & Lt; / Div & gt; & Lt; Span class = "label" & gt; It should be other text & lt; / Span & gt; & Lt; / Div & gt;
Try setting width : 100% at .bg .label as follows:
.main {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Display: inline-block;} .man .label {display: inline-block;} .bg {background: red; Padding: 10px; font-weight: bold; Color: #fff; Display: Inline-block; Border-radius: 60%;} .bg .label {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Width: 100%; Display: Inline-block; Margin: Auto;} & lt; Div class = "main" & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 200 & lt; / Span & gt; & Lt; / Div & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 0 & lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt; edit : If you want to keep the same width for the circle and still keep the text at center, You width: 10px; You can change .bg in :
.bg {/ * ... * / width: 35px; Padding: 10 px 0; Text align: center; / * ... * /} Then the complete snippet will look something like this:
. Main {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Display: inline-block;} .man .label {display: inline-block;} .bg {background: red; Width: 35px; Padding: 10 px 0; Text align: center; font-weight: bold; Color: #fff; Display: Inline-block; Border-radius: 60%;} .bg .label {vertical-align: top; Margin-top: 3px; Margin-down: 5px; Width: 100%; Display: Inline-block; Margin: Auto;} & lt; Div class = "main" & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 200 & lt; / Span & gt; & Lt; / Div & gt; & Lt; Div class = "bg" & gt; & Lt; Span class = "label" & gt; 0 & lt; / Span & gt; & Lt; / Div & gt; & Lt; / Div & gt;
Comments
Post a Comment