What is the best way to center align the div container horizontally?

Trying to center the #container but all methods have failed.

How can I achieve centering using only CSS?

body {
  text-align:center;
}
<div id="app">
<div id="container"><div id="container_red" style="position:absolute;left:0">
        <svg style="opacity:1" class="noiseimg" width="400" height="400">
          <mask id="outlinemask0">
            <circle cx="202.5" cy="200" r="150" fill="#f00"></circle>
          </mask>
          <g mask="url(#outlinemask0)">
            <circle cx="200" cy="200" r="200" fill="rgba(153,0,0,1)"></circle>
            <mask id="backcirclemask0">
            <circle cx="200" cy="200" r="200" fill="#fff"></circle>
            </mask>
            <g mask="url(#backcirclemask0)">
              <g id="rect-group0">
                <rect x="60" y="160" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="40" y="30" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="310" y="200" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="310" y="300" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="320" y="140" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="140" y="370" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="110" y="360" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="130" y="220" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="360" y="390" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="340" y="380" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="310" y="20" width="10" height="10" fill="rgba(102,0,0,1)"></rect><rect x="220" y="170" width="10...

Answer №1

The alignment of the svg element has been adjusted using flex properties for centering, hopefully this modification is beneficial.

body {
  text-align:center;
  display : flex;
  justify-content:center;
  align-items:center;
  min-height: 100vh;
}
<div id="app">
<div id="container"><div id="container_red">
        <svg style="opacity:1" class="noiseimg" width="400" height="400">
          <mask id="outlinemask0">
            <circle cx="202.5" cy="200" r="150" fill="#f00"></circle>
          </mask>
          <g mask="url(#outlinemask0)">
            <circle cx="200" cy="200" r="200" fill="rgba(153,0,0,1)"></circle>
            <mask id="backcirclemask0">
            <circle cx="200" cy="200" r="200" fill="#fff"></circle>
            </mask>
            <g mask="url(#backcirclemask0)">
              <g id="rect-group0">
                [Insert Long List of Rectangles Here]
              </g>
            </g>
          </g>
        </svg>
      </div><div id="container_green">
        <svg style="opacity:1" class="noiseimg" width="400" height="400">
          <mask id="outlinemask1">
            <circle cx="197.5" cy="200" r="150" fill="#f00"></circle>
          </mask>
          <g mask="url(#outlinemask1)">
            <circle cx="200" cy="200" r="200" fill="rgba(0,153,0,1)"></circle>
            <mask id="backcirclemask1">
            <circle cx="200" cy="200" r="200" fill="#fff"></circle>
            </mask>
            <g mask="url(#backcirclemask1)">
              <g id="rect-group1">
                  [Insert Long List of Rectangles Here]
              </g>
            </g>
          </g>
        </svg>
      </div></div>
</div>

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

Trouble with setting HTML table width

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <table border="1" width="100%"> <tr> <td>bbbbbbbbbbbbbbbbbbbbbbbbbbb ...

Struggling with the installation of SimpLESS

I encountered an issue while attempting to install SimpLESS on my Windows 7 64bit PC. Upon running the installer, I was met with an error message stating: "Could not query info: Invalid HTTP Status Code (403)". Despite my efforts to search for a solution o ...

In bootstrap 3.0, columns are arranged in a vertical stack only

As a newcomer to web design, I've been struggling to figure out why my basic grid in Bootstrap 3 isn't working as expected. No matter what I try, my columns stack vertically instead of side by side and always resize to fill the browser window. Th ...

The Vue.js modal is unable to resize below the width of its containing element

My challenge is to implement the Vue.js modal example in a larger size. I adjusted the "modal-container" class to be 500px wide, with 30px padding and a max-width of 80%. However, I'm facing an issue where the "modal-mask" class, containing the contai ...

Sending a different name for the jQuery parameter

I'm looking to select CSS settings based on the presence of a data tag. What would be the correct approach for this? var datadirection = 'left'; //default direction if( $(this).attr('data-right') ){ datadirection = 'righ ...

Easy fix for 3 circles (images) placed in a row with equal distance between them and perfectly aligned

I've been spending the last 3 days trying to accomplish this specific task: 3 circular images arranged horizontally with equal spacing Occupying 70% of the central screen area Height and width based on percentages for browser resizing adjustment It ...

Element in the Middle

I have just started learning HTML and CSS, and I'm curious to know how I can center the links Home, About, and Contact in the header. HTML: <body> <header> <h1><a href="#">HBT</a> </h1& ...

Using jQuery to create a dynamic fullscreen background image that responds to mouse movement

I am currently working on creating a dynamic full screen background that responds to the movement of the mouse. The idea is that as you move the mouse around, the background image will shift accordingly. For instance, if you were to move the mouse to the ...

Node.js causing issues with executing jQuery front-end code properly

I created an automatic image scroller div consisting of a ul with small images. The aim is to have a basic scroller that starts running once the page loads. It functions perfectly when I test the code (HTML, CSS, and a JS file with jQuery) locally in a bro ...

Tips for automatically closing a dropdown menu when it loses focus

I'm having some trouble with my Tailwind CSS and jQuery setup. After trying a few different things, I can't seem to get it working quite right. In the code below, you'll see that I have placed a focusout event on the outer div containing th ...

Apply a chosen style to the element that was clicked on, while removing the style from the rest

Here is an example of my ul li structure: <div id="categoryTree"> <ul> <li id="cat_15"> <a class="hasSubCat" href="javascript:void(0);"><img src="images/icons/folder.gif" border="0" alt="Folder" title=" Folder ">N ...

Creating a responsive and expandable table using HTML and JavaScript

I need help with making my html table resizable in a vertical direction. The cells can overflow if there isn't enough space, so I want to allow users to stretch the table by dragging and extending the bottom edge. Can anyone provide guidance on how to ...

What is the best way to position my NavBar items to the right using the Bootstrap v5.2 framework?

I am working on a project for my course and need some help. My goal is to have the brand stay aligned to the left, while other items align to the right. I have been able to achieve this without a toggler using justify-content-end, but with a toggler, I a ...

Is the background image unable to fill up the entire screen?

I'm currently facing an issue with my webpage's background not covering the entire vertical space. Despite trying different solutions and referring to previous posts, I haven't been able to resolve it yet. Here is the relevant code: <div ...

numerous requirements for formatting utilizing Css modules

Can someone help me figure out how to set multiple conditions using a ternary operator to style an element with Css modules? I'm struggling to find the right syntax. Is it even possible? import style from './styles.module.sass' const Slider ...

Creating a 3x3 grid with CSS grid is great, especially when you want to place items in specific columns within the grid

I'm attempting to design a layout that has a unique structure: The blue rectangles are represented by divs. It's like a 3x3 grid, but with spaces in the 3rd and 4th columns of the grid. How can I incorporate these gaps using CSS grid to achieve ...

What is the best way to target and manipulate the transform property of multiple div elements in JavaScript?

Looking at this code snippet, my goal is to have all the boxes rotate 180deg with a single click, without needing to apply different ID names: function rotateAllBoxes() { var boxes = document.getElementsByClassName("box"); for (var i = 0; i < box ...

Only apply the CSS rule to all pages except for one

I'm a beginner when it comes to css. In my wordpress website editor (Onetone theme), I added the following rule to my 'custom css field': html, body {margin: 0; height: 100%; overflow: hidden} It's working well...the scrollbar is gone ...

Creating a hover effect for displaying image masks

My website features a profile page displaying the user's photo. I am attempting to create a functionality where when the user hovers over their photo, a transparent mask with text appears allowing them to update their profile picture via a modal. How ...

When it comes to Shopify Schema, the section settings are functional within the <style> tag, whereas the block settings do not seem to have the same

While working on updating a section with multiple blocks, I encountered an unusual issue. My goal was to incorporate a new block into an existing section. The schema has been set up correctly, and everything is functioning as anticipated. However, the prob ...