Creating a circular shape with text layered on top that spans the full width using CSS

I'm currently attempting to replicate this specific layout: Website design

In this design, the red circle is quite wide and extends beyond the edge of the screen. I also plan to place text on top of it, which will serve as my website's logo.

My attempt at recreating it can be found here: https://jsfiddle.net/s0q8Ljr5/1/


#container {
width: 100%;
margin: 0 auto;
padding: 0;
position: relative;
}

#nav-bg {
width: 90vw;
height: 90vw;
margin: 0 auto;
padding: 0;
margin-top: -45vw;
background: red;
border-radius: 50%;
position: absolute;
}

#title {
margin: 0 auto;
text-align: center;
position: absolute;
margin-top: 20px;
}

However, I am encountering some challenges with getting the circle to extend as far as I want while maintaining its centered position. Additionally, the text is not perfectly centered, and I am uncertain about the compatibility of using the "vw" property for width and height across different browsers.

Any assistance or suggestions would be greatly appreciated! Thank you.

Answer №1

If you want to achieve this effect, consider using SVG or clip-path. There are various approaches to creating it, so take a look at this example:

body {
  margin: 0;
}

#container {
  background-color: red;
  height: 100px;
  padding-bottom: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.nextDiv {
  height: 100vh;
  position: relative;
}

.cutEffect {
  position: absolute;
  width: 100%;
  left: 0;
  top: 0;
  transform: translateY(-90%);
  font-size: 0;
}
<div id="container">
  <div id="nav-bg"></div>
  <h1 id="title">Title goes here</h1>
</div>
<div class="nextDiv">
  <svg class="cutEffect" viewBox="0 0 100 20" fill="white">
    <path d="M 0 0 L 0 20 L 100 20 L 100 0 Q 50 30 0 0"></path>
  </svg>
</div>

Answer №2

Your use of viewport properties is good, but it seems you have used the same values for both height and width. It would be better to differentiate between width(vw) and height(vh)

#container {
  width: 100%;
  margin: 0 auto;
  padding: 0;
  position: relative;
}

#nav-bg {
  width: 80vw;
  height: 80vh;
  margin: 0 auto;
  margin-top: -45vh;
  background: red;
  border-radius: 60%;
  position: relative;
}

#title {
  top: 65%;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
<div id="container">

  <div id="nav-bg"></div>
  <h1 id="title">Title goes here</h1>

</div>

You may want to consider this approach:

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

The cursor in a contenteditable element fails to return to its original position after adding a new line and then deleting it

I have come across a basic HTML code snippet: span { outline: none; } hello <span contenteditable="true"> world </span> Upon testing, I observed that each time I press ENTER within the contenteditable span, the cursor moves to a new ...

Changing the heading tag type dynamically using CSS

When working with code in an HTML file, consider the following: <h1> Caption </h1> Would you be able to modify it using CSS like this?: <h2> Caption </h2> ...

Eliminate JavaScript comments with Regex in PHP

Looking to reduce the size of HTML code with the help of PHP and Regex. Here is the minify function: public static function sanitize_output($buffer) { $search = array( '/ {2,}/', '/<!--.*?-->|\t|(?:\r?& ...

Using jQuery to create a complex hierarchy of div elements

I need assistance in creating this HTML structure using jQuery: <div id="container"> <div id="row0"> <div id="start0"></div> <div id="end0"></div> </div> <div id="row1"> & ...

Reverse the impact of the preceding CSS directive

In this screenshot example, the padding at the bottom in Material-UI has been increased from 16px to 24px using the CSS rule below: .MuiCardContent-root:last-child { padding-bottom: 24px; } https://i.sstatic.net/IWaIu.png I want to revert it back to ...

What is the best way to integrate a CSS file into Vue.js 2?

At the moment, I'm diving into Vue.js 2 but I've hit a roadblock. Can anyone advise me on how to incorporate external CSS in Vue.js 2? I would greatly appreciate any solutions you can offer. Thank you! ...

Animating the reordering of slides in Angular using ng-repeat

I implemented a carousel slider in Angular utilizing ng-repeat with orderBy:'id'. However, I encountered an issue where the id changes when clicking the next slide button. Check out my JSFiddle here Within a div, I have ng-repeat: <div clas ...

Tips for effectively managing Navbar color adjustment while scrolling in Angular?

I'm currently working on an Angular project and I am looking to incorporate a navbar with a transparent background that changes color when scrolled. I am utilizing bootstrap classes for this particular task. The HTML code for my Navbar heading is as ...

Troubleshooting inconsistent htaccess changes across different pages?

After much trial and error, I have successfully managed to run PHP code within a document that has either an .htm or .html extension. The solution that worked for me was adding the following line of code: AddType application/x-httpd-php .php .html .htm N ...

Concealing the navigation bar on an ASP.NET webpage following user login

I recently completed my first web application using ASP.NET. https://i.sstatic.net/8HRQj.png Now, I have the top navigation (red arrow) displayed on all pages of my web app. How can I hide it from specific pages so that users only see the side navigation ...

I'm experiencing challenges with the layout of an HTML document

I am looking to create individual boxes for each of these images, rather than coloring the entire row. One approach I've tried is using a div tag with a class called "caja-img" that specifies a specific width. HTML <div class="col-md"> &l ...

Having trouble arranging the elements when swapping within a pop-up modal

When I drag and drop two divs inside a modal popup, their positions shift down during the animation. I am struggling to fix this issue. HTML Code: <title> Tile Swapping with Animation</title> <body> <button type="button" class=" ...

Conceal Content from Onsite Search

Is it possible to conceal text from on-page browser searches (e.g. Ctrl+F) in a dependable manner while keeping it visible? I thought that adding aria-hidden="true" would address the issue, but the text remains searchable by browsers. ...

Increase the value by one of the number enclosed in the <h3> element

I have a variable number of <h3> tags with the same class .love_nummer <h3 class="love_nummer">1</h3> Each of these tags contains a number, and alongside each .love_nummer tag is another tag with the class .give_love <h3 class="give ...

What is the best way to align this rendered Django template in the center using Bootstrap?

In previous tutorials, it was mentioned that divs with the "container" class in Bootstrap are supposed to automatically center. However, I am experiencing issues with this in the current version. <!DOCTYPE html> <html lang="en" dir="ltr> & ...

Alter the input title in Vue by clicking on a list item

I currently have an input field that is connected to an unordered list containing two list items. I want to be able to change the name/ID of the input field with a simple click on one of the list items. Since the list items are not links or buttons, my go ...

Show information when table is clicked

I currently have a 9 x 9 table with unique content in each cell. Is there a way to enable the following functionality: Upon clicking on the text within a specific cell, all related content would be displayed right below that same cell? For instance, if ...

Limiting the Number of Categories in WordPress

Is it possible to display half of the WordPress categories in a visible <div> and the other half in a hidden one? The following HTML code shows two menus, one visible and one hidden, which can be displayed by clicking on a button: <nav class=&quo ...

The final item in the inline list vanishes when a new list is added

I wrote a PHP script that creates an array of images from a specific folder: <?php $imagesDir = 'thumbnails/'; $images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE); echo json_encode($images); ?> Th ...

Adjusting the width of columns in a flex layout using Bootstrap 4

On mobile, I am attempting to rearrange some elements in a different order. Currently, this is what I have: https://i.stack.imgur.com/fY3PQ.png Below is the HTML code: <main> <div data-color="yellow"></div> <div class="wrapper"& ...