How to center text in a list in CSS? - html

I have the following CSS list definition:
a {
background-color: black;
display:block;
border-radius: 50%;
text-align: center;
top: 50%;
left: 50%;
height: 100px;
width: 100px;
}
Which results in this kinds of buttons:
I would like the text to be right in the middle of those circles instead. Is that possible?

Try to span an element. Try this.
Working codepen example: https://codepen.io/anon/pen/ePMdrL
a{
background:black;
color:#fff;
width:100px;
height:100px;
display:inline-block;
text-align:center;
position:relative;
border-radius:100%;
}
a span{
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}
<span>Link</span>

instead of display:block; this:
a {
/* display:block; <- delete this */
/* put this instead */
display:flex;
align-items:center;
}
reference material:
https://developer.mozilla.org/en-US/docs/Glossary/Flex

You could use the line-height property. Working Codepen example.
.circle {
position: relative;
display: inline-block;
width: 100px;
height: 100px;
line-height: 100px;
border-radius: 50%;
background: black;
color: white;
text-align: center;
}

You can use custom list style, for instance:
ul.leaf {
list-style-image: url('/images/leaf_icon.jpg');
}

Related

Center div on html line

I have a problem with html. I am trying to set a html line and on that line I have to set a div with text. Here is the example, but it is a photo. I would like to get this in html.
I hope someone can help me.
Edit:
I know how to get a line in html and I know how to get this yellow div with the text. The problem is. How do I get the yellow div on the line. This is my current result.
You can do this with Flexbox and pseudo-elements. Here is Fiddle
.element {
display: flex;
align-items: center;
}
.price {
background: #FEC538;
font-size: 30px;
font-weight: bold;
padding: 10px 40px;
border-radius: 50px;
}
.element:before,
.element:after {
content: '';
flex: 5;
height: 3px;
background: #C3C3C3;
}
.element:after {
flex: 1;
}
<div class="element">
<div class="price">Save 35%</div>
</div>
This will do it
<div class='c1'>
<span>save 35%</span>
</div>
.c1{
position:relative;
text-align:center;
}
.c1:before{
content:'';
height:2px;
width:100%;
background:#CDCCCD;
position:absolute;
top:50%;
left:0;
margin:-1px 0 0;
}
.c1 span{
display:inline-block;
padding:5px 15px;
background:#FEC538;
border-radius:20px;
position:relative;
}
see it here : https://jsfiddle.net/IA7medd/6tonuvg6/
That will do..
Html
<div class="center-div"></div>
**Css**
body
{
background-color: #fcfcfc;
}
.center-div
{
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100px;
height: 100px;
background-color: #ccc;
border-radius: 3px;
}
Set width, and set margin:auto;.
div.c2 {
margin:auto;
width:80px;
text-align:center;
/*color*/
background-color: #FEC538;
border-radius: 10px;
}
<div>
<div class=c2>Save 35%</div>
<div>

Trying to modify my CSS Logo with two lines of text in a circle

I'm trying to fix my website main logo. The name is Cerebro Design, and I would like to put Cerebro up and Design down, exactly like this:
This is the CSS code I have so far:
<div style="margin:auto;
width:500px;
height:500px;
border-radius:250px;
font-size:50px;
color:#fff;
line-height:500px;
text-align:center;
background:#000;">
CEREBRO DESIGN
</div>
#logo{
margin:auto;
width:500px;
height:500px;
border-radius:250px;
font-size:80px;
color:#fff;
text-align:center;
background:#000;
}
#logo-text{
margin-left:70px;
padding-top: 160px;
max-width:30px;
}
<div id="logo">
<div id="logo-text">CEREBRO DESIGN.</div>
</div>
Then you just add the correct font and you should be good to go.
As a note, is better to use external or internal (<style>...</style>) css than using style="..." on an element.
i would use an image for the logo, but if you want to go css way, this could work for you.
Demo
div {
margin:auto;
width:500px;
height:500px;
border-radius:250px;
font-size:50px;
color:#fff;
line-height:500px;
text-align:center;
background:#000;
display: inline-block;
position: relative;
overflow: hidden;
}
div:before, div:after{
display:inline-block;
position: absolute;
color: white;
font-size: 95px;
width:500px;
height:500px;
text-align: center;
left: 0;
}
div:before{
content: 'CEREBRO';
top: -10%;
}
div:after{
content: 'DESIGN.';
top: 10%;
}
Can you share the font you are using? My quick aproach (I'm in a small laptop) would be something like this:
HTML:
<div class="cerebro-logo">
<span class="padding">Cerebro
<span class="design-text">Design .</span>
</span>
</div>
CSS:
.cerebro-logo {
margin:auto;
width:500px;
height:500px;
border-radius:250px;
font-size:70px;
font-family: Helvetica Neue,Helvetica,Arial,sans-serif;
font-weight: 600;
color:#fff;
line-height:80px;
letter-spacing: 10px;
text-align:left;
background:#000;
text-transform: uppercase;
}
.padding {
padding-top: 165px;
padding-left: 50px;
float: left;
}
.design-text {
letter-spacing: 13px;
}
Tip: You can use letter-spacing (for example) to get that spacing effect on the "Design .".
JSFIDDLE link: http://jsfiddle.net/f5qrbbx5/
Just add your text, no need to calculate any margin or padding.
.circle {
width: 500px;
height: 500px;
margin: 20px auto;
background: #000;
border-radius: 50%;
color: #fff;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 94px;
text-align: center;
white-space: nowrap;
}
.circle:before {
content: '';
display: inline-block;
height: 100%;
margin-right: -0.25em;
vertical-align: middle;
}
.circle > * {
display: inline-block;
max-width: 80%;
text-align: left;
vertical-align: middle;
white-space: normal;
}
<div class="circle">
<span>CEREBRO<br>DESIGN.</span>
</div>

Set absolute positioned element width to its content (it is only a text)

I am going to build this
This is my HTML code
<div class="al-head-container">
<div></div>
<span>Center Websites</span>
</div>
This is css :
.al-head-container{
margin: auto;
width: 100%;
padding:0 4%;
position: relative;
box-sizing: border-box;
}
.al-head-container > span{
font: 2.1em titr;
color: #ae7f00;
background-color: #FFFFFF;
position: absolute;
right: 0;
left:0;
}
.al-head-container > div{
width: 100%;
height: 20px;
background-image: url("../image/head-line.jpg");
position: relative;
top: 25px;
}
But this is the result of code
The problem is the span width is set to 100% and its width doesn't fit to its content. it is what I get from the firebug
As you see the text covers the DIV that contains the line.
I tried to set the display:inline-block for span but nothing changed. How do I can make the absolute positioned span width to fit the content?
Why not accomplish this purely in CSS with a single element:
div {
border-top:1px solid lightgrey;
border-bottom:3px solid lightgrey;
height:2px;
position:relative;
margin-top:15px;
}
div:after {
content:attr(data-label);
position:absolute;
top:-10px;
left:50%;
padding:0 20px;
display:inline-block;
background:#fff;
transform: translateX(-50%);
text-align:center;
color:#A37716;
font-size:24px;
}
<div data-label="Center Websites"></div>
I will suggest make a few changes on your code.
You can remove the div element and instead use a pseudo-element later with CSS
<div class="al-head-container">
<span>Center Websites</span>
</div>
Then with CSS make the pseudo-element be the absolute one to place it behind the span:
.al-head-container{
position:relative;
}
.al-head-container > span{
font: 2.1em titr;
position:relative;
z-index:10;
display:inline-block;
padding:0 20px;
height:2.1em;
line-height:2.1em;
color: #ae7f00;
background-color: #FFFFFF;
}
.al-head-container:after{
content:"";
width: 100%;
top:50%;
transform:translateY(-50%);
border-top:dotted 3px red;
position: absolute;
left:0;
}
Check this Demo on Jsfiddle
Note that you can replace the border on the fiddle with your background image
Try this:
.fancy {
line-height: 0.5;
text-align: center;
}
.fancy span {
display: inline-block;
position: relative;
}
.fancy span:before,
.fancy span:after {
content: "";
position: absolute;
height: 5px;
border-bottom: 3px solid gray;
border-top: 1px solid gray;
top: 0;
width: 600px;
}
.fancy span:before {
right: 100%;
margin-right: 30px;
}
.fancy span:after {
left: 100%;
margin-left: 30px;
}
<div class="subtitle fancy">
<span>Center Websites</span>
</div>
Also here you have a working fiddle
try to add margin auto on absolute span
.al-head-container > span{
font: 2.1em titr;
color: #ae7f00;
background-color: #FFFFFF;
position: absolute;
right: 0;
left:0;
margin : auto;
}

css margins not displaying divs in correct places

I have this CSS Code:
html,body {
font-family:Arial;
font-weight:bold;
}
.container {
text-align:center;
}
.box {
width:475px;
display: inline-block;
margin:10px 20px 0 auto;
padding:12px;
border:1px solid black;
min-height:60px;
text-align: center;
float: left;
height: 200px;
}
.box h2 {
font-size:44px;
margin-top:4px;
margin-bottom:0;
}
.box p {
font-size:60px;
border:1px solid black;
margin-bottom:0;
}
but the divs with the two lines of text in make the values/numbers display lower than all the other divs with only one line of text.
how can i make all the values/numbers display in the same place inside the the .box divs?
Here is a fiddle with the full code: http://jsfiddle.net/8kex9/
With your code, you could do something like this: JS Fiddle
Giving them both absolute positions, will cause them to be positioned based on parent, rather than the sibling. You just can't add too many lines of text, or else it will run into each other.
.box h2 {
font-size:44px;
margin-top:4px;
margin-bottom:0;
position: absolute;
width: 465px;
}
.box p {
position: absolute;
font-size:60px;
border:1px solid black;
margin-top: 120px;
width: 465px;
}

Block elements within div in CSS

I'm trying to make 2 divs appear on separate lines within an outside div. Right now I have display:inline-block set for both of them, but I'm not sure how to change this to make them appear on separate lines.
Here is what my code looks right now, I would like John Doe and 100 to appear on separate lines within the leader div:
http://jsfiddle.net/ZnuPR/
HTML
<ul>
<li class="leader">
<div class="ranking">1</div>
<div class="name">John Doe</div>
<div class="score">100</div>
</li>
</ul>
CSS
.leader {
border: 1px solid;
background-color: #E6E6E6;
display: inline-block;
width: 400px;
margin: 2px;
padding: 2px;
background-repeat: no-repeat;
height: 75px;
}
.ranking {
display: inline-block;
margin:2px;
padding:2px;
width:50px;
height:65px;
background-color:green;
color:white;
}
.name {
display: inline-block;
}
.score {
display: inline-block;
}
You could simply float .ranking and then leave .name and .score as display: block.
http://jsfiddle.net/ZnuPR/7/
.ranking {
/* ... */
float: left;
}
The fastest solution is to set the ranking to "float:left;" and the name and score to "display:block;". Block level elements span 100% by default which will make sure the 2 elements are on seperate lines.
.leader {
border: 1px solid;
background-color: #E6E6E6;
display: inline-block;
width: 400px;
margin: 2px;
padding: 2px;
background-repeat: no-repeat;
height: 75px;
}
.ranking {
float:left;
margin:2px;
padding:2px;
width:50px;
height:65px;
background-color:green;
color:white;
}
.name {
display: block;
}
.score {
display: block;
}
http://jsfiddle.net/ZnuPR/2/
I think this is what you mean:
http://jsfiddle.net/ZnuPR/6/
Don't use inline-block and remove the height from the container, it will automatically adjust to the height it needs to be.
http://jsfiddle.net/ZnuPR/8/
Added a .details wrapper and some floats.
.ranking {
float:left; /* Floating */
margin:2px;
padding:2px;
width:50px;
height:65px;
background-color:green;
color:white;
}
.details {
float:left; /* floating */
}
.name {
display: block; /* Changed to block */
}
.score {
display: inline-block;
}
<ul>
<li class="leader">
<div class="ranking">1</div>
<div class="details">
<div class="name">John Doe</div>
<div class="score">100</div>
</div><!-- end details wrapper-->
</li>
</ul>
I think this could be useful:
http://jsfiddle.net/ZnuPR/10/
.leader {
border: 1px solid;
background-color: #E6E6E6;
display: inline-block;
width: 400px;
margin: 2px;
padding: 2px;
background-repeat: no-repeat;
}
.ranking {
width: 100%;
margin:2px;
padding:2px;
width:50px;
height:65px;
background-color:green;
color:white;
}
.name {
width: 100%;
}
.score {
width: 100%;
}
This is what I did:
CSS
.leader {
border: 1px solid;
background-color: #E6E6E6;
display: inline-block;
width: 400px;
margin: 2px;
padding: 2px;
background-repeat: no-repeat;
}
.ranking {
display: inline-block;
margin:2px;
padding:2px;
width:50px;
height:65px;
background-color:green;
color:white;
}
I got rid of display: inline-block and height