Home > other >  How to add text into rounded rectangle separating by a circle
How to add text into rounded rectangle separating by a circle

Time:12-22

I have a div like this:

enter image description here

And coded like this:

<div >
    <div >
        <div >
            <img src="larger-logo.jpg"> 
        </div>
    </div>
</div>

And I wanted to add some text on the left side of the circle shape and also to the right side:

enter image description here

So I tried this:

<div >
    <div >
        <div >
            <img src="larger-logo.jpg"> 
        </div>
        <div >
            <h6>Site Name</h6>
            <hr>
            <p>www.sitename.com</p>
            <p>[email protected]</p>
        </div>
        <div >
            <p>Address</p>
            <p>Postal Code</p>
            <p><strong>Phone Number</strong></p>
        </div>
    </div>
</div>

But the result is far from the expected:

enter image description here

So how to add the texts to the right side of circle shape and left side properly?

And here is the css codes:

.mainInfo{
    background-color: #fff;
    border: .01rem round #e0e1ed;
    border-radius: 20px;
    color: #585CA1;
    width:100%;
    height:5em;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
    margin-top: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle {
    position: relative;
    left:20%;
    width: 9em;
    height: 9em;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}

.circle img {
    position: absolute;
    max-width: 85%;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

UPDATE:

I added this CSS:

.mainInfo{
    background-color: #fff;
    border: .01rem round #e0e1ed;
    border-radius: 20px;
    color: #585CA1;
    width:100%;
    height:5em;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
    margin-top: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle {
    position: relative;
    left:20%;
    width: 9em;
    height: 9em;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}

.circle img {
    position: absolute;
    max-width: 85%;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}
.paraDivLeft{
  position: absolute;
  left: 16px;
}

.paraDivRight{
  position: absolute;
  right: 16px;
}

Still Showing Like This:

enter image description here

CodePudding user response:

Can use the CSS layout- The position Property for this. Add the position values as below to the mainInfo, paraDivLeft and paraDivRight classes in the CSS file.

.mainInfo{
    position: relative;
    background-color: #fff;
    border: .01rem round #e0e1ed;
    border-radius: 20px;
    color: #585CA1;
    width:100%;
    height:5em;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
    margin-top: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.paraDivLeft{
  position: absolute;
  left: 16px;
}

.paraDivRight{
  position: absolute;
  right: 16px;
}

CodePudding user response:

I think what you have will mostly work, just change the line height to 1em or something.

Here was my attempt. I also added 'top' and then 'left' or 'right' to move away from the edges with absolute positioning. I also used text-align for each paraDiv sections:

.mainInfo{
    background-color: #fff;
    border: .01rem round #e0e1ed;
    border-radius: 20px;
    color: #585CA1;
    width:100%;
    height:5em;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.75);
    margin-top: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.circle {
    position: relative;
    left:20%;
    width: 9em;
    height: 9em;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0px 0px 17px -5px rgba(0,0,0,0.65);
}

.circle img {
    position: absolute;
    max-width: 85%;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

.paraDivLeft,
.paraDivRight {
    position: absolute;
    display: inline-block;
    padding: 10px;
}

.paraDivLeft {
    left: 20px;
    top: 40px;
    text-align: left;
}

.paraDivRight {
    right: 20px;
    top: 50px;
    text-align: right;
}

.paraDivLeft h6 {
    font-size: 14pt;
    margin: 0;
}

.paraDivLeft p,
.paraDivRight p {
    line-height: 1em;
    font-size: 12pt;
    margin: 0;
}
<div >
    <div >
        <div >
            <img src="larger-logo.png"> 
        </div>
        <div >
            <h6>Site Name</h6>
            <hr>
            <p>www.sitename.com</p>
            <p>[email protected]</p>
        </div>
        <div >
            <p>Address</p>
            <p>Postal Code</p>
            <p><strong>Phone Number</strong></p>
        </div>
    </div>
</div>

  • Related