I have a sentenced with a solid border around it. When I the sentence, the border changes, adjusting to fit the sentence. I also have a pink circle. I would like the pink circle to be in the top right corner of the border around the sentence no matter the length of the sentence – I want the circle to move dynamically with the border.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewpoint" content="width=device-width,initial-scale=1">
<title>Family Tree Creator</title>
<link href="Style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="nameone">Core water is soooo good!!</div>
<div class="circleone"></div>
</body>
</html>
.nameone {
border: 3px solid darkgray;
display: inline-block;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
padding: 15px;
}
.circleone{
border: 3px solid pink;
border-radius: 50%;
width: 15px;
height: 15px;
}
I’m new to css and html so I tried several variations of placing s inside of one another but nothing
2
Answers
I would apply
flex
to the container (in your examplebody
, but I recommend to create a seperate container div), with the usual settings for centering its only child (see below).Then apply
position: relative
to.nameone
to make it act as the position anchor for the absolutely positioned.circleone
div which you have to move inside the.nameone
div to be its child, withtop
andright
settings as below to place the circle into the top right corner of its parent:Another solution would be to create the circle by adding a pseudo element (
.nameone::after
) in CSS with very similar settings as above, but without the circle div in the HTML code:Taken two screenshots with different text. Guess this is what you wanted
Create a separate
<div>
for the text and place it inside the class.nameone
. Place the circle’s div i.e the class.circleone
before the text div. And style the class.circleone
asfloat:right
in css. Add<div style = "clear:both"></div>
after the class.circleone
in html.For testing purpose, I’ve added the css inside the tags. You can remove it; place it in a separate css file and modify according to your requirement: