What is the best way to align the bottom of an anchor element with the bottom of an SVG element when positioning them together

I am working on a test website where I am trying to create an interesting visual layout. My goal is to place an SVG image in the background, with an anchor element and other elements laid out above it. The challenge I am facing is aligning the bottom of the SVG image with the bottom of the paragraph element.

body {
  margin: 0;
}

a {
  font-size: 0.8rem;
  display: block;
  text-align: center;
  color: black;
}

footer {
  text-align: -webkit-center;
  padding: 1.25%;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
  sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt
  ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit
  esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
<p>
  At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
  animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
  est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
  voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
  in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
  sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt
  ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit
  esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
<p>
  At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
  animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
  est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
  voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
</p>
<br><br>

<footer>Shamar's Domestic Cleaning Services</footer>
<a href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ffae7fef2eff3fadff8f2fef6f3b1fcf0f2">[email protected]</a>">Built by Riverstone Technologies UK © 2023</a>

<svg xmlns:xlink="http://www.w3.org/1999/xlink" id="wave" style="transform:rotate(0deg); transition: 0.3s" viewBox="0 0 1440 490" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <defs>
            <linearGradient id="sw-gradient-0" x1="0" x2="0" y1="1" y2="0">
                <stop stop-color="rgba(161, 11, 255, 1)" offset="0%" />
                <stop stop-color="rgba(161, 11, 255, 1)" offset="100%" />
            </linearGradient>
        </defs>
        <path style="transform:translate(0, 0px); opacity:1" fill="url(#sw-gradient-0)"
            d="M0,343L30,318.5C60,294,120,245,180,187.8C240,131,300,65,360,73.5C420,82,480,163,540,171.5C600,180,660,114,720,138.8C780,163,840,278,900,310.3C960,343,1020,294,1080,253.2C1140,212,1200,180,1260,147C1320,114,1380,82,1440,114.3C1500,147,1560,245,1620,302.2C1680,359,1740,376,1800,383.8C1860,392,1920,392,1980,375.7C2040,359,2100,327,2160,294C2220,261,2280,229,2340,187.8C2400,147,2460,98,2520,65.3C2580,33,2640,16,2700,32.7C2760,49,2820,98,2880,163.3C2940,229,3000,310,3060,294C3120,278,3180,163,3240,98C3300,33,3360,16,3420,57.2C3480,98,3540,196,3600,269.5C3660,343,3720,392,3780,400.2C3840,408,3900,376,3960,367.5C4020,359,4080,376,4140,392C4200,408,4260,425,4290,432.8L4320,441L4320,490L4290,490C4260,490,4200,490,4140,490C4080,490,4020,490,3960,490C3900,490,3840,490,3780,490C3720,490,3660,490,3600,490C3540,490,3480,490,3420,490C3360,490,3300,490,3240,490C3180,490,3120,490,3060,490C3000,490,2940,490,2880,490C2820,490,2760,490,2700,490C2640,490,2580,490,2520,490C2460,490,2400,490,2340,490C2280,490,2220,490,2160,490C2100,490,2040,490,1980,490C1920,490,1860,490,1800,490C1740,490,1680,490,1620,490C1560,490,1500,490,1440,490C1380,490,1320,490,1260,490C1200,490,1140,490,1080,490C1020,490,960,490,900,490C840,490,780,490,720,490C660,490,600,490,540,490C480,490,420,490,360,490C300,490,240,490,180,490C120,490,60,490,30,490L0,490Z" />
    </svg>

Check out this sneak peek of what the website currently looks like: https://i.stack.imgur.com/Hx44q.jpg

The challenge now lies in ensuring that the wavy purple SVG is perfectly aligned at the bottom with the anchor tag above it and effectively placed behind it (which can be achieved by adjusting the z-index of the SVG).

Answer №1

To effectively position an SVG within your webpage, you can create a parent element that encompasses the entire page. This entails adding a div with the class name page-container.

The relative positioning of your SVG in relation to this parent container can be achieved using the CSS property position: absolute. According to w3schools:

position: absolute allows the element to be positioned relative to its first ancestor element that has a non-static positioning.

In order to designate the parent element as the first positioned ancestor, you must include position: relative; in its style properties.

Subsequently, to align the bottom of the SVG with the parent div (and consequently with its last static sibling, the anchor tag), apply bottom: 0. This particular attribute specifies the distance from the bottom of the parent at which the SVG should be displayed.

Below is the revised code snippet reflecting these adjustments:

body {
  margin: 0;
}

a {
  font-size: 0.8rem;
  display: block;
  text-align: center;
  color: black;
}

footer {
  text-align: -webkit-center;
  padding: 1.25%;
}

.page-container {
  position: relative;
}

svg {
  position: absolute;
  bottom: 0;
  z-index: -1;
}
<div class="page-container">

  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p>
  <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
    sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
    incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea vol...voluptate
    velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
  <p>
    At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
    animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
    est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
    voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  </p>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p>
  <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas
    sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora
    incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea volu...voluptate
    velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
  <p>
    At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia
    animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda
    est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis
    voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  </p>
  <br><br>

  <footer>Shamar's Domestic Cleaning Services</footer>
  <a href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff9a879e928f939abf98929e9693d19c9092">[email protected]</a>">Built by Riverstone Technologies UK © 2023</a>

  <svg xmlns:xlink="http://www.w3.org/1999/xlink" id="wave" style="transform:rotate(0deg); transition: 0.3s" viewBox="0 0 1440 490" version="1.1" xmlns="http://www.w3.org/2000/svg">
        <defs>
            <linearGradient id="sw-gradient-0" x1="0" x2="0" y1="1" y2="0">
                <stop stop-color="rgba(161, 11, 255, 1)" offset="0%" />
                <stop stop-color="rgba(161, 11, 255, 1)" offset="100%" />
            </linearGradient>
        </defs>
        <path style="transform:translate(0, 0px); opacity:1" fill="url(#sw-gradient-0)"
            d="M0,343L30,318.5C60,294,120,245,180,187.8C240,131,300,65,360,73.5C420,82,480,163,540,171.5C600,180,660,114,720,138.8C780,163,840,278,900,310.3C960,343,1020,294,1080,253.2C1140,212,1200,180,1260,147C1320,114,1380,82,1440,114.3C1500,147,1560,245,1620,302.2C1680,359,1740,376,1800,383.8C1860,392,1920,392,1980,375.7C2040,359,2100,327,2160,294C2220,261,2280,229,2340,187.8C2400,147,2460,98,2520,65.3C2580,33,2640,16,2700,32.7C2760,49,2820,98,2880,163.3C2940,229,3000,310,3060,294C3120,278,3180,163,3240,98C3300,33,3360,16,3420,57.2C3480,98,3540,196,3600,269.5C3660,343,3720,392,3780,400.2C3840,408,3900,376,...
            C3960,367.5C4020,359,4080,376,4140,392C4200,408,4260,425,4290,432.8L4320,441L4320,490L4290,490C4260,490,4200,490,4140,490C4080,490,4020,490,3960,490C3900,490,3840,490,3780,490C3720,490,3660,490,3600,490C3540,490,3480,490,3420,490C3360,490,3300,490,3240,490C3180,490,3120,490,3060,490C3000,490,2940,490,2880,490C2820,490,2760,490,2700,490C2640,490,2580,490,2520,490C2460,490,2400,490,2340,490C2280,490,2220,490,2160,490C2100,490,2040,490,1980,490C1920,490,1860,490,1800,490C1740,490...
            ,1680,490,1620,490C1560,490,1500,490,1440,490C1380,490,1320,490,1260,490C1200,490,1140,490,1080,490C1020,490,960,490,900,490C840,490,780,490,720,490C660,490,600,490,540,490C480,490,420,490,360,490C300,490,240,490,180,490C120,490,60,490,30,490L0,490Z" />
    </svg>

</div>

Answer №2

One alternative approach involves utilizing SVG as a background for the footer element HTML and adjusting text alignment using margin properties.

To begin, convert your SVG code to CSS format. You can employ this tool. The provided code has been revised.

body {
  margin: 0;
}

a {
  font-size: 0.8rem;
  text-align: center;
  color: #fff;
}

footer {
  text-align: center;
  padding: 1.25%;
  color: #fff;
}

.container {
  position: relative;
}

footer {

   background-image: url('data:image/svg+xml,%3Csvg xmlns:xlink="http://www.w3.org/1999/xlink" id="wave" style="transform:rotate(0deg); transition: 0.3s" viewBox="0 0 1440 490" version="1.1" xmlns="http://www.w3.org/2000/svg"%3E%3Cdefs%3E%3ClinearGradient id="sw-gradient-0" x1="0" x2="0" y1="1" y2="0"%3E%3Cstop stop-color="rgba(161, 11, 255, 1)" offset="0%25" /%3E%3Cstop stop-color="rgba(161, 11, 255, 1)" offset="100%25" /%3E%3C/linearGradient%3E%3C/defs%3E%3Cpath style="transform:translate(0, 0px); opacity:1" fill="url(%23sw-gradient-0)" d="M0,343L30,318.5C60,294,120,245,180,187.8C240,131,300,65,360,73.5C420,82,480,163,540,171.5C600,180,660,114,720,138.8C780,163,840,278,900,310.3C960,343,1020,294,1080,253.2C1140,212,1200,180,1260,147C1320,114,1380,82,1440,114.3C1500,147,1560,245,1620,302...

...
 <footer>
    <div class="cope">
      <div class="svg">
    <p>Shamar's Domestic Cleaning Services</p>
    <p><a href="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2978a939f829e97b2959f939b9edc919d9f">[email protected]</a>">Built by Riverstone Technologies UK © 2023</a></p>
      </div>
    </div>
 </footer>

  

</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

Conceal navigation buttons on the first and last pages of the slider

I'm attempting to develop a slider that hides the "previous" button when it is on the first slide and hides the "next" button when it reaches the last slide. The slider will be created using a combination of PHP, forms, and JavaScript. Below is the H ...

There seems to be an issue with the HTML link not redirecting properly, as it is directing to www.oldpage.com/http://www

Has anyone experienced a similar issue before? I can't figure out why this is happening. Here's the HTML code I'm using: <a href="www.google.com">www.google.com</a> Despite it appearing correct, when I click on the li ...

Animating back with a jQuery if statement

Is there a way to implement an if statement that triggers an animation when the right image reaches +400px, and then animates back to -400px upon hovering over the image? $('#left img').mouseenter(function() { $('#right img').animate ...

Guide on automatically populating login data in an html5 form using a python script

I'm currently attempting to create a script that can automatically populate the values of an HTML5 form (specifically Name and Password fields). However, I am struggling with how to actually input these values. After searching various sites, I have y ...

Tips for passing a page as an argument in the function parameter of the page.evaluate() method?

I keep running into this issue when I pass the page as an argument: TypeError: Converting circular structure to JSON --> commencing at object with constructor 'BrowserContext' | property '_browser' -> object with const ...

Exploring the functionality of the Aria role attribute within Angular 2

It's strange that the ARIA role attribute doesn't seem to be functioning as expected for me in Angular 2. I attempted to assign a div role of "listbox" and set the children as role "option", but it still doesn't work. Could someone assist m ...

header color scheme and dimensions

Hello, I've managed to get the menu working correctly on my website at www.g-evo.com/header.php. However, I'm now facing an issue with the size of the header. I'd like to shrink the grey area slightly so it aligns better with the logo, while ...

What is the best way to achieve this smooth scrolling animation on the page?

While browsing the website , I noticed a unique page scrolling effect that caught my eye. Unsure if they were using default bootstrap code or their own custom code, I was intrigued by how it worked. I attempted to find similar effects online but struggled ...

How can you determine whether the CSS of a <div> is defined in a class or an id using JavaScript/jQuery?

Hey there, I'm currently working on dynamically changing the CSS of a website. Let's say we have a div like this: <div id="fooid" class="fooclass" ></div> The div has a class "fooclass" and an ID "fooid", and we're getting its ...

Steps for creating a transparent Bootstrap navbar:1. Start by creating

I have Bootstrap HTML code for a navbar <!--Navbar--> <nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <img class="logo" alt="Brand" src="images/1.png"> <a class="navbar-brand" href="Homepage.jsp">Car ...

Incorporate negative padding in order to smoothly scroll to a specific ID

When I jump to an ID using domain.com/#section, the scroll goes too far down and needs a negative margin added. Is there a way to achieve this directly in the URL without relying on CSS, jQuery, or JavaScript? ...

Menu navigation - ensuring the background color extends to cover the entire page, not just the viewport

I'm facing an issue with the left navigation bar's design. Specifically, I'd like the grey color of the bar to extend vertically across the entire page. Currently, the gray bar ends at the viewport's edge. Is there a way to make the ba ...

What is the method for adding an event listener in AngularJS within an ng-repeat iteration?

I'm completely new to AngularJS and currently working on building a photo gallery. The basic idea is to have an initial page displaying thumbnail photos from Twitter and Instagram using an AngularJS ng-repeat loop. When a user hovers over an image, I ...

Struggling with using flexboxes and creating animated elements

Seeking assistance with animating the search bar on a website project. The animation is functioning, but the search input abruptly moves when the animation starts, as shown in this GIF: I am utilizing jQuery for the animation because I also want to implem ...

Using CSS GRID for creating layouts with customized grid-template-areas that include empty cells and automatic placement

Struggling with implementing the css grid layout module to showcase a 12-column, 3-row grid. The initial row should only contain two elements, positioned on each side of the grid with empty cells in between using ten periods. Subsequent rows should autom ...

Prevent IonContent from scrolling to the bottom or top when using Ionic framework

In my Ionic app, I have a long text page with 2 buttons that trigger the actions scrollToBottom and scrollToTop. Due to the length of the page, I have set the scroll duration to be 30 seconds. I am facing two issues here: How can I stop the scrolling ...

Empty screen appears when "npm run serve" command is executed following the build process

I am currently utilizing Material-ui. Following the project build with npm run build, I encounter a blank page when running npm run serve. I attempted to set homepage: "./" in the package.json as suggested here, however, it still displays a blank ...

Vue encountered an error: TypeError - _c is not recognized as a function

I recently created an icon library in Vue using Vue-cli and vue-svg-loader, and then exported it as a package. However, when I tried to use the icons like this: <template> <div> <MyIcon /> </div> </template> <scri ...

What is the reason behind Google Font's decision to preconnect to fonts.googleapis.com?

I've been looking to incorporate the Quicksand Font into my website, and Google suggested adding the following code: <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="h ...

alignment not behaving as anticipated

My goal is to position two elements on different sides within a container. Although in my coding scenario, these elements are meant to be on opposite ends of a div, for the sake of explanation, let's consider them being on opposite sides of the browse ...