Reputation: 13571
I have an html file like this.
<html>
<head>
</head>
<body>
<div class="final_time">
<p class="final_time_text">some text here</p>
</div>
</body>
</html>
Here is its corresponding css file.
.final_time {
width: 20px;
height: 20px;
background-color: green;
border-radius: 50%;
position: absolute;
right: 15%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
}
.final_time_text {
width: 200px;
left: -20px;
}
How can I move .final_time_text
a little bit left so that it aligns to the center of .final_time
?
I mean I want something like this.
I originally thought that setting left: -20px
can make it shift left a little bit, but I was wrong.
Here's the code in JSFiddle: https://jsfiddle.net/rf2vnozq/4/
Upvotes: 0
Views: 614
Reputation: 3549
I think setting position:relative to .final_time_text will do what you want but it would be better to centerlize it using flex box
like this :
.final_time {
width: 20px;
height: 20px;
background-color: green;
border-radius: 50%;
/*increase distance of green circle and text*/
margin-bottom:10px;
}
.final_time_text {
width: 200px;
text-align:center;
}
.container{
display:flex;
flex-direction:column;
align-items:center;
position: absolute;
right: 15%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
}
<html>
<head>
</head>
<body>
<div class="container">
<div class="final_time">
</div>
<p class="final_time_text">some text here</p>
</div>
</body>
</html>
Upvotes: 2
Reputation: 148
just add relative position to the text css
.final_time {
width: 20px;
height: 20px;
background-color: green;
border-radius: 50%;
position: absolute;
right: 15%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
}
.final_time_text {
position: relative;
width: 200px;
left: -50px;
}
<html>
<head>
</head>
<body>
<div class="final_time">
<p class="final_time_text">some text here</p>
</div>
</body>
</html>
Upvotes: 2