0

I would am attempting to take something I've seen before and recreate it with html/css. Here is a mockup I've made in Word.

Hello World, circular accent

Almost everything I find is about text inside circles, not an accent behind, like this drawing. I would like to have the circle and the text centered as much as possible.

Here is the best of my attempts: https://jsfiddle.net/FNdXz/559/

#container
{
  height:400px;
  width:400px;
  background-color: #ccc;
  display: table-cell;
}

#inner
{
  height:200px;
  width:200px;
  background:transparent;
  border-radius: 100px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
  margin-left:25%;
  margin-top:25%;
  border: 1px solid white;
}

#test {
  color: black;
  text-align: center;
  vertical-align: middle;
  font-size: 50px;
}

#sub-test {
  color: blue;
  text-align: center;
  font-size: 30px;
}
<div id="container">
    <div id="test">
      Hello World
    </div>
    <div id="sub-test">
      Test, this is only a test
    </div>
    <div id="inner">
    </div>
</div>

Obviously, I can worry about fonts and coloring later - but I'm really struggling with the positioning and could use help from a pro.

atschaal
  • 355
  • 1
  • 14

4 Answers4

1
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
#container
{
  height:400px;
  width:400px;
  background-color: #ccc;
  display: table-cell;
}

#inner
{
  height:200px;
  width:200px;
  background:transparent;
  border-radius: 100px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
  margin-left:25%;
  margin-top:10%;
  border: 1px solid white;
  position : relative;
}

#test {
  color: black;
  text-align: center;
  vertical-align: middle;
  font-size: 50px;
  position : absolute;
  margin-top : 100px;
  margin-left : 70px;

}

#sub-test {
  color: blue;
  text-align: center;
  font-size: 30px;
  position : absolute;
  margin-top : 160px;
  margin-left : 50px;
}
</style>
</head>
<body>
<div id="container">

    <div id="test">
      Hello World
    </div>
    <div id="sub-test">
      Test, this is only a test
    </div>
    <div id="inner">
    </div>
</div>
<body>
</html>

Hope this is what you are requesting for

1

Creating a circle with svg is straightforward. You can center everything in the container using flexbox.

Then center the svg behind the text using position: absolute and a lower z-index.

#container {
  height: 400px;
  width: 400px;
  background-color: #ccc;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#container>div {
  z-index: 1;
}

#test {
  color: black;
  font-size: 50px;
}

#sub-test {
  color: blue;
  font-size: 30px;
}

svg {
  position: absolute;
  z-index: 0;
}
<div id="container">
  <div id="test">
    Hello World
  </div>
  <div id="sub-test">
    Test, this is only a test
  </div>
  <svg height="200" width="200">
  <circle cx="100" cy="100" r="100" stroke="white" stroke-width="1" fill="transparent"/>
</svg>
</div>
sol
  • 22,311
  • 6
  • 42
  • 59
0

You need to utilize the position and z-index settings. With the position being set to absolute, you can define the margin from the top, right, bottom, and left sides of the parent container. z-index determines what "layer" to appear on - the higher the value, the higher precedence it gets. See the updated CSS here.

#container
{
  height:400px;
  width:400px;
  background-color: #ccc;
  display: table-cell;
  position: relative;
}

#inner
{
  height:200px;
  width:200px;
  position: absolute;
  top: -2%;
  left: -2%;
  z-index: 1;
  background:transparent;
  border-radius: 100px;
  -moz-border-radius: 100px;
  -webkit-border-radius: 100px;
  margin-left:25%;
  margin-top:25%;
  border: 1px solid white;
}

#test {
  position: absolute;
  color: black;
  text-align: center;
  vertical-align: middle;
  font-size: 50px;
  top: 30%;
  left: 15%;
  z-index: 2;
}

#sub-test {
  position: absolute;
  top: 45%;
  left: 15%;
  z-index: 2;
  color: blue;
  text-align: center;
  font-size: 30px;
}
SteveK
  • 995
  • 5
  • 17
0

Another idea is to simply use radial-gradient:

#container {
  padding:50px 0;
  width: 400px;
  background:radial-gradient(circle at center,transparent 40%,#fff 40%,#fff calc(40% + 1px),transparent calc(40% + 1px)),
  #ccc;
  display: table-cell;
}

#test {
  color: black;
  text-align: center;
  vertical-align: middle;
  font-size: 50px;
}

#sub-test {
  color: blue;
  text-align: center;
  font-size: 30px;
}
<div id="container">
  <div id="test">
    Hello World
  </div>
  <div id="sub-test">
    Test, this is only a test
  </div>
</div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415