I tried to set this button to center of x-axis using css but it does not work.
How can i do that ?
https://jsfiddle.net/9e9rb6L5/
this is html code.
<div class="one">
<div class="two">start now</div>
</div>
and this is css.
.one{
height: 66px;
line-height: 36px;
text-align: center;
margin: 0 auto;
}
.two{
float: left;
background-color: #3498db;
color: white;
font-size: 24px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 20px;
padding-right: 20px;
}
Try this:
You need to add width: fit-content;
in .one class.
.one{
height: 66px;
line-height: 36px;
display:block;
margin:0 auto;
width: fit-content;
text-align:center;
}
.two{
float: left;
background-color: #3498db;
color: white;
font-size: 24px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 20px;
padding-right: 20px;
}
<div class="one">
<div class="two">start now</div>
</div>
display:table
in .one class.one{
height: 66px;
line-height: 36px;
display:table;
margin:0 auto;
text-align:center;
}
.two{
float: left;
background-color: #3498db;
color: white;
font-size: 24px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 20px;
padding-right: 20px;
}
<div class="one">
<div class="two">start now</div>
</div>
flex
property..one{
height: 66px;
line-height: 36px;
text-align: center;
margin: 0 auto;
display:flex;
justify-content:center;
}
.two{
float: left;
background-color: #3498db;
color: white;
font-size: 24px;
padding-top: 15px;
padding-bottom: 15px;
padding-left: 20px;
padding-right: 20px;
}
<div class="one">
<div class="two">start now</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With