Centering SVGs with absolute positioning - Maintaining aspect ratios

Here is the code I am working with: http://jsfiddle.net/uorto4ny/2/

The challenge I'm facing is trying to keep a fluid sized SVG centered on the page while maintaining its proportions. Currently, it works in Chrome, but in IE and Firefox, one side of the SVG becomes longer than the other, even though they should be equal.

Below is the CSS I am using:

* {
    padding: 0;
    margin: 0;
}
body {
    font-family:"Helvetica Neue", Arial, Helvetica, sans;
    background: #f4f4f4 url('http://www.clker.com/cliparts/c/H/Y/E/V/s/theta-400x400.svg') no-repeat center center fixed;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    background-size: 25% 25%;
}
a {
    position: absolute;
    bottom: 0;
    right: 0;
    margin: 0px 10px 10px 0px;
    padding: 10px 18px;
    text-decoration: none;
    font-size: 12px;
    text-align: center;
    background-color: #FFF;
    color: rgba(0, 0, 0, 0.44);
    border-radius: 5px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    transition: background-color 0.3s ease 0s;
}
a:hover {
    background-color: rgba(87, 173, 104, 1);
    border: 1px solid rgba(87, 173, 104, 1);
    color: white;
}

If anyone can point out what I might be doing incorrectly, I would greatly appreciate it.

Sincerely, James

Answer №1

View a live demo here

To adjust the background size, use the following CSS properties:

-webkit-background-size: 25%;
-moz-background-size: 25%;
-ms-background-size: 25%;
-o-background-size: 25%;
background-size: 25%;

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

"Learn the step-by-step process of generating a transcript with a WebVTT file in JWPlayer

We have integrated JWPlayer into our website and are now looking to add transcript captioning. I have attempted to create a sample application using regular HTML code, but have not been successful. Despite reviewing multiple tutorials, I was unable to ach ...

Issue encountered with ngFor: 'Identifier not defined __type does not have any such member'

Recently, I successfully implemented a sub-component that allows users to dynamically add and remove a set of controls to and from a collection. The inspiration for this solution came from reading through this particular thread on Stack Overflow. While ev ...

Error message encountered while attempting to upload a file with Express-fileupload in a Node.js environment: "Unable to locate specified

I am currently facing an issue while attempting to upload a PDF file, save it in a directory under a specific name for querying purposes, and store that name in an SQL table. I am utilizing Express-fileupload to handle the file upload process, but when I t ...

Discovering the Nearest Textfield Value Upon Checkbox Selection Using JQuery

How can I retrieve the value of the nearest Textfield after selecting a checkbox? This HTML snippet serves as a simple example. In my actual project, I have dynamically generated lists with multiple checkboxes. I require a way to associate each checkbox wi ...

I have implemented a custom-built sidebar component and I'm unsure about the process of adding data to it

After successfully incorporating this SideBar into my Vuex/Laravel project, I encountered a problem. The example code provided used: <div :class="$style.sidebar"/> However, when I tried to modify it to: <div :class="$style.sidebar">Content&l ...

Divide the full width into three divisions, each taking up 33% of the total width

I have been experimenting with using 3 divs to create a table-like layout with 3 columns. I set each div to occupy 33% of the width of the page, and it worked well until I tried to add padding to move the text away from the border. This caused the third di ...

What is the best way to ensure a flexbox image item keeps its aspect ratio?

After exploring numerous questions and answers, it seems that most discussions on flexbox aspect ratio involve using <div> elements instead of <ul><li>. However, I am struggling to find a solution to my specific issue. When utilizing < ...

Utilizing Isotope JS on your Wordpress website

I'm in the process of integrating the .js plugin, Isotope, into my Wordpress installation. It should be positioned at the bottom of this page: To achieve this, I am referring to an example on codepen: https://codepen.io/desandro/pen/mEinp The script ...

Sending a JavaScript variable through a jQuery and HTML form

My current issue involves a list of images within a div: <div id="holiday"> <ul> <li><img src="images/stationery/christmas.jpg" width="68" height="80" /></li> <li><img src="images/stationery/easter.jpg" wi ...

Styling the button in jQuery to switch between disabled and enabled

I'm currently working on creating a disabled/enable button style using jQuery. You can check out my demonstration page on Codepen for reference. In the demo, you'll notice a blue submit button. When you input text into the field, the button bec ...

Creating a connection between a secondary jQuery anything slider and a distinct CSS style on a webpage

Currently, I am attempting to incorporate two anything sliders within the same webpage. My goal is to apply unique styling to each slider. Despite my efforts, I am encountering difficulties in calling upon a second style sheet without it completely overr ...

Tips for successfully passing PHP variables to a JavaScript function

Having trouble passing the selected values of two comboboxes to another PHP file using AJAX. How can I pass both values in one function? <script> function showUser(str,str2) { if (str == "" || str2 =="") { document.getElementById("tx ...

How can I make the central element of my site stand out as dominant when I have three vertical elements evenly divided on full screen?

Is there a way to make the central element take up all the viewport space when the screen is minimized or dragged halfway, with the two side elements being purely aesthetic? I'm wondering if CSS or jQuery has any attributes that can accomplish this. ...

Angular gives priority to input when clicking an element

Please find the stackblitz link attached below. https://stackblitz.com/edit/angular-dgx3pe My goal is to achieve a functionality where clicking on the label element will focus on the input. This should trigger the input:focus class. I believe this can be ...

What causes the appearance of a blue vertical line on the left edge when loading HTML <blockquote> content into a TextView on an Android device?

element, my application displays HTML content in a textview. However, I noticed that the presence of blockquote elements causes an issue with styling. Specifically, I want to format the content within blockquotes similar to paragraph tags. I also aim to ...

Issue with overflow in TailwindCSS design

I'm working on implementing a unique layout using Tailwind CSS for a dashboard. The height of the initial view should match the screen size and remain within those limits at all times. Initially, the blue section of the dashboard will be empty (but ...

How can I align text to the right in a navbar using Bootstrap 5?

My current navbar setup is as follows: <nav class="navbar navbar-expand-lg navbar-light bg-light"> <div class="container-fluid"> <div class="collapse navbar-collapse" id="navbarText"> ...

Compatibility issues arise when trying to use jQuery Mobile in conjunction with jQuery UI

I'm currently developing an HTML5 application that needs to function seamlessly on desktops, tablets, and mobile devices. However, I've encountered a hurdle when it comes to implementing progress bars and dialog boxes. Initially, I was using jQue ...

Adjusting the size of a canvas element based on changes in the browser window dimensions

I'm currently working on developing a website layout in React that consists of: A top bar A right side bar A canvas element that occupies the remainder of the screen space These elements need to adjust to the browser window size changes while fillin ...