When two rectangles are created at the same coordinates (x, y) in SVG, it results in an unexpected border appearing

.rect-x {
  fill: red;
}

.rect-y {
  fill: pink;
}
<svg viewBox="0 0 1024 768">
  <rect class="rect-x" x="0" y="0" width="100" height="100"></rect>
  <rect class="rect-y" x="0" y="0" width="100" height="100"></rect>
</svg>

Screenshot showing the issue:

https://i.sstatic.net/QUwcg.png

Can you explain why this is happening?

Any suggestions on how to resolve it?

Answer №1

To enhance the sharpness of your SVG, consider disabling antialias rendering.

svg {
  shape-rendering: crispEdges;
}

.rect-x {
  fill: red;
}

.rect-y {
  fill: pink;
}

svg {
  shape-rendering: crispEdges;
}
<svg viewBox="0 0 1024 768">
  <rect class="rect-x" x="0" y="0" width="100" height="100"></rect>
  <rect class="rect-y" x="0" y="0" width="100" height="100"></rect>
</svg>

Answer №2

For those looking to eliminate antialiasing, consider including shape-rendering="crispEdges"

.rect-x {
  fill: red;
}

.rect-y {
  fill: pink;
}
<svg viewBox="0 0 1024 768">
  <rect class="rect-x" x="0" y="0" width="100" height="100"></rect>
  <rect class="rect-y" x="0" y="0" width="100" height="100"></rect>
  
  <rect class="rect-x" x="200" y="0" width="100" height="100" shape-rendering="crispEdges"></rect>
  <rect class="rect-y" x="200" y="0" width="100" height="100" shape-rendering="crispEdges"></rect>
</svg>

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

Attempting to implement a polygon-shaped button with material-UI and React framework

https://i.sstatic.net/Nlxrr.jpg This is a design I am experimenting with for the poly button above. I have tried various styling methods. Does anyone have any ideas? ...

In order to position content at the center of a <div> element

Just recently delving into the world of Bootstrap, I've hit a roadblock. Here's my current conundrum: <div class="container px-4 py-5" id="hanging-icons"> <h2 class="pb-2 border-bottom">Work Experie ...

What is the best way to place an <a> tag and a <p> tag side by side in an HTML

I have a question on organizing this HTML code: <ol class="results-list"> <% @results.sort_by { rand }.each do |result| %> <li class="<%= 'checked-out' if result.catalog_item.library_status == 'Checked out&apos ...

Issue with Arabic characters displaying incorrectly in Outlook 2007

I have encountered an issue with my newsletter application where the newsletters are in Arabic. When viewed in the browser, everything looks fine. However, when opened in Outlook 2007, strange text appears instead. Interestingly, if the email is marked as ...

Creating a curved container with CSS styling

I've attempted to create a design resembling the image below, but I'm not achieving the desired result. Can someone provide me with assistance? Any help would be greatly appreciated. https://i.sstatic.net/J4LzC.png <!DOCTYPE ht ...

Obtain the bounding box of an SVG element while it is not visible

I've been grappling with this issue for more than a day now, but I'm still unable to find a solution. My challenge lies in the need to scale an SVG image for responsive design purposes. Since I have to manipulate the SVG code on the client side, ...

Solving the CSS Trick: Responsive Data Table (featuring inline editing) Display Glitch

In my quest to create a responsive table with inline editing, I turned to Chris's guide at CSS-Tricks (check it out here). To see how it all comes together, take a look at this Plunker demo. On mobile screens, the responsiveness is on point. https: ...

What is the best way to ensure text starts on a new line when paragraphs and images are floating and aligned?

Does anyone have a clearer title idea? Feel free to edit. To better illustrate my point, I've created a jsfiddle. I am working with a simple layout of text and images. My goal is to make the second text and image appear on a new row just below the f ...

Ways to avoid scrolling on a fixed element

Here is the HTML setup I have... body .top .content The issue I am facing is that when scrolling reaches the end of the ul in the .top element, the background starts to scroll. This can be quite disorienting and makes the site slow on tablets. Even ...

Tips for customizing MUI PaperProps using styled components

I am trying to customize the width of the menu using styled components in MUI. Initially, I attempted the following: const StyledMenu = styled(Menu)` && { width: 100%; } `; However, this did not have any effect. After further research, I ...

Inaccurate sizing of popup dialogs on SharePoint 2010

Currently, I am in the process of revamping a SharePoint 2007 web application to SharePoint 2010. I was surprised to find that the popup dialog boxes for new items, edit, etc. have inline styles for fixed width and height. Below is an example where div.ms ...

Remove inline CSS from HTML elements

Having a large HTML file structured like this: <div style="min-height: 32px; padding: 5px; width: 800px; margin: 50px auto; overflow: auto; font-size: 12px;" class="selectable clearfix selected_layer" id="wrap"> <div class="selectable" id="l1" st ...

Classes that are designed to be written on a single

A fellow team member recently made an addition to our project. <ol class="numbered-list list-inside" start="1"> .numbered-list { list-style-type: decimal; } .list-inside { list-style-position: inside; } Is there a problem with this code, ...

Adjust the div container to wrap underneath the image if the webpage width decreases

Hello there, I am currently in the process of creating my own portfolio. I have a brief introduction that I would like to display next to an image of myself, with the image positioned on the right side. I have a div called "container" which contains anoth ...

Stylize the final element within a webpage using CSS styling techniques

In the code snippet below, my goal is to apply a specific style to the content of the final occurrence of "B". <div class="A"> <div> I am <span class="B">foo</span>. </div> <div> I like <span class="B"> ...

Guide to aligning a fraction in the center of a percentage on a Materal Design progress bar

Greetings! My objective is to create a material progress bar with the fraction displayed at the top of the percentage. https://i.sstatic.net/GbphJ.png Currently, I have managed to show the fraction at the beginning of the percentage. Below is the code sn ...

Placing a div underneath a different element on a webpage

I am struggling with the placement of a div on my webpage. I have tried various methods to position it beneath two other elements without success, despite following advice from online resources. Here is the code I have been working with: ...

Switching the background color of alternating divs in reverse order: a step-by-step guide

I am looking to alternate the background color of divs between odd and even, with the last div being grey and the second to last div being green. I have tried using the odd/even classes in CSS, but it did not work as expected. .main{ width:500px; height ...

Show Navbar Toggler only when in Portrait mode on mobile devices, not Landscape mode

Attempting to create a responsive website utilizing Bootstrap 4, I encountered a problem with the menu expanding in Landscape orientation on mobile devices, causing distortion. How can I ensure the menu stays collapsed in Landscape orientation? Despite ha ...

Hide the button when you're not actively moving the mouse, and show it when you start moving it

How can I make my fixed positioned button only visible when the mouse is moved, and otherwise hidden? ...