Vertical and center-aligned text within responsive transparent overlapping circles achieved through CSS styling

I'm struggling to align my text center and vertically within each circle. I attempted putting the h1 text inside another div with display table, but I am facing issues in containing the text within each circle class. Would you mind taking a look at my example code on CodePen?

HTML:

<div id="circle-wrapper">
<div class="circle1 transparent_class"><h1>Two lines <br />&amp;Two lines</h1></div>
<div class="circle2 transparent_class"><h1>Two lines<br /> Two lines</h1></div>
<div class="circle3 transparent_class"><h1>Two lines<br />&amp; Two lines</h1></div>
<div class="circle4 transparent_class "><h1>Two lines<br /> Two lines</h1></div>
</div><!--close of circle-wrapper-->

CSS:

 #circle-wrapper{
    position:relative;
    top:0;
    left:0; 
    }

    .circle1, .circle2, .circle3, .circle4 {
    position:absolute;
    -moz-border-radius: 50%;
    -webkit-border-radius: 50%; 
    border-radius: 50%;
    width: 32%;
    height: 32%;
    padding-bottom: 32%;
    }

    h1.circle1 h1 {
    display:inline-block;
    display: table-cell; 
    vertical-align: middle; 
    text-align: center;
    }

    .circle1 {
    background-color:#889fbe;
    color:000;
    margin-top:-8%;
    left:10%;
    }

    .circle2 {
    margin-top:10%;
    color:000;
    left:24%;
    background-color:#b1daf6;
    }

    .circle3 {
    margin-top:24%;
    left:10%;
    background-color:#4f4f51;
    }

    .circle4 {
    margin-top:10%;
    left:-8%;
    background-color:#56a0d3;   
    }

    .transparent_class {
    /* IE 8 */
   -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70)";

    /* IE 5-7 */
    filter: alpha(opacity=70);

    /* Netscape */
    -moz-opacity: 0.7;

    /* Safari 1.x */
    -khtml-opacity: 0.7;

    /* Good browsers */
    opacity: 0.7;
    }

http://codepen.io/matriplett/pen/LJcnE

Answer №1

Enclose your h1 inside a div element with the class "wrapper"

<div class="circle1 transparent_class">
<div class="wrapper"><h1>Two lines <br />&amp;Two lines</h1>
</div>
</div>

Adjust the style as follows:

.wrapper{
  margin-top:40%;
  height:100%;
  width:100%;
  display: table;
}

Check out the updated pen here: http://codepen.io/anon/pen/yugBK

Answer №2

Here is an example of how to create a circle design:

  <div id="circle-wrapper">
    <div class="circle circle1 transparent_class">  
      <h1>Two lines <br />&amp;Two lines</h1>
    </div>
    etc. 

To start, add a circle class and set the height on the container element:

#circle-wrapper{
    position:relative;
    top:0;
    left:0; 
    height: 1200px;
}

Next, specify the height and width for the circle and h1 elements:

.circle, h1 {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  height: 400px;
  width: 400px;
}

For a live demo, check out this CodePen link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unveiling the Magic: Enhancing Raphaeljs with Interactive Click Events on a Delicious Slice of the

I'm having trouble responding to a click event on each slice of a Raphael Pie Chart. I've tried implementing the code below, but it doesn't seem to be working. The code is just two lines, commented as "My Code", in the example from the offic ...

CSS - Yet another perplexing question that shouldn't have arisen

While working on building this website in CSS, I hadn't encountered any major issues up until now. Suddenly, I'm facing a problem with basic positioning within my body-3 class div. Instead of pushing it downward and elongating the page as expecte ...

The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE. #menu { position: absolute; left: 50%; bottom ...

Is there a way to eliminate the table-hover effect on specific rows in the table?

Here is some HTML: <table class="table table-striped table-bordered table-condensed table-hover"> .... </tr> <tr ng-repeat-end ng-show="modelRow.activeRow==car.name" class="hidden-table"> <td colspan="6"> ...

Analyzing the styles of :hover/:focus elements provided by the user agent in Chrome and Firefox

While inspecting a webpage, I can see the :focus/:hover behavior for every browser, but I am unable to view it in the inspect styles section. When I examine an input field or any other focusable element, and toggle the :focus checkbox, I notice that the d ...

Adaptable navigation options

So, I've been facing a challenge with my Bootstrap 4 navigation bar. The nav-items are going right across the navbar but I want the spacing between each nav item to adjust based on the viewport size to prevent any items from falling outside of view. I ...

Add an array to every item on the list using individual unordered lists

I need help with a JavaScript code that will add elements from an array to each list on my webpage. The goal is to add numbers 1 through 4 to the list items, but only up to the number of items in the array. If there are only three list items, I want the sc ...

What are some effective ways to resize the fontawesome glyph icon on my twitter-bootstrap website while maintaining proper alignment?

Are you able to figure out the code change needed on this under construction web page? There is a white box next to the company name at the top left, check it out here The site is twitter-bootstrap based with a white box "glyph icon" from FontAwesome. I&a ...

What is the best way to center my navbar logo and have the navigation links encapsulate it on either side?

I am looking to achieve a design where my navbar brand is centered with the navigation links positioned on the left and right of it. When the screen size reaches md, I want the nav links to disappear into a burger menu while still keeping the nav brand vis ...

New to CSS/Ruby - What causes two adjacent buttons to have varying sizes?

The varying sizes of my search and login buttons located beside each other are puzzling me. Could it be due to the fact that the search button is enclosed within a submit_tag argument while the login button is not? If this is indeed the case, how can I mak ...

Adjust the width of the navigation bar

Currently, I am attempting to center the menu bar and ensure that it perfectly fits the text. For reference, here is the website that I'm currently working on: I have already discovered a way to center the menu items as shown below: .menu { tex ...

Adjust the background to scroll to the bottom of the image first and then change it to be fixed

Here is the code I have written: body{ margin:0; padding:0; line-height: 1.5em; background-image: url(http://fehlbelichtet.stefanwensing.de/wp-content/uploads/sites/6/2016/04/alte-strasse-endlos.jpg); background-repeat:no-repeat; background-attachment: ...

Issue with Vue custom range slider where cursor position is not accurately displayed

I recently developed a unique input range slider using Vue.js. While most aspects of the slider are functioning correctly, I have encountered an issue with the cursor position not aligning properly while sliding the range slider. Ideally, the cursor shou ...

Tips for eliminating overlapping borders in a table using CSS

I've encountered an issue with my table where the border becomes darker and thicker at the intersection of two cells. Is there a way to resolve this problem? I have included my CSS code below. .custom-table-2 { border-collapse: separate; /*border- ...

Adjust the size of the text and the textarea at the same time

I am trying to resize text simultaneously while resizing the textarea in my code. I am using jQuery for this functionality. However, I believe there is an issue with the click function being separated. Any advice on how to fix this would be greatly appreci ...

What is the method for reversing the colors on a specific portion of an element?

Picture this scenario: you have a square shaped div with the following styling: div { background: red; height: 5rem; width: 5rem; } How would you modify its styling so that the color of the bottom half of the red square is inverted? ...

Steps for displaying a division on clicking a hyperlink

I am currently working on my main menu layout in HTML, and here is the code snippet: <div id="main-container"> <div id="main-wrapper"> <div id="logo"> <h1 id="title">port ...

What is the method for dynamically assigning a CSS class to an ASP.NET control through programming?

I was curious about how I could dynamically apply a CSS class to an ASP.NET Control (specifically a TextBox) through C# on the backend. For instance: <asp:TextBox ID="firstName" CssClass="input left" runat="server" Text="First Name" /> I want to ad ...

Issue with jQuery where it returns "undefined" when trying to access the CSS display property

On my page, there are several divs with default display styles set in an external .css file. When a certain condition is met, I use jQuery to turn one on and the others off using the fadeIn() and fadeOut() methods. However, I've noticed that in Firef ...

Minimal - Combining a module with a parent component

To provide some background, I am utilizing bootstrap nav pills as triggers for bootstrap collapsibles. This is a simplified representation of the LESS code for bootstraps nav pills: .nav-pills { > li { // Active state &.active > a ...