Trouble getting SVG line to display within Bootstrap 4 flex divs

I am attempting to establish a connection between the first two circular div elements using an SVG line. While inspecting, I can visualize the line but it remains hidden on the page. I tried adjusting the z-index without success. However, increasing the width seems to solve the issue. It appears that the div is positioned behind another element. But shouldn't setting the z-index make it visible?

const line = $('#connectedLines');
const div1 = $('#node1');
const div2 = $('#node2');

const x1 = div1.offset().left + (div1.width());
const y1 = div1.offset().top + (div1.height() / 2);
const x2 = div2.offset().left + (div2.width() / 10);
const y2 = div2.offset().top + (div2.height() / 2);

line.attr('x1', x1).attr('y1', y1).attr('x2', x2).attr('y2', y2);
.parentContainer {
  background-image: linear-gradient(to bottom, rgb(253, 118, 49,1) 25%, 
  rgb(255, 157, 107,0.5));
  background-color: #FD7631;
  height: auto;
  padding-bottom: 50px;
  top: 0;
  z-index: -1;
}

/* Additional CSS styling goes here */

Please see the CodePen link

Answer №1

It's not just about z-index, but also about the use of overflow.

When dealing with svg, remember to include the CSS properties height, width, overflow in your code.

var line = $('#connectedLines');
var div1 = $('#node1');
var div2 = $('#node2');

var x1 = div1.offset().left + (div1.width());
var y1 = div1.offset().top + (div1.height()/2);
var x2 = div2.offset().left + (div2.width()/10);
var y2 = div2.offset().top + (div2.height()/2);

line.attr('x1',x1).attr('y1',y1).attr('x2',x2).attr('y2',y2);
.parentContainer {
  background-image: linear-gradient(to bottom, rgb(253, 118, 49,1) 25%, rgb(255, 157, 107,0.5));
  background-color: #FD7631;
  height: auto;
  padding-bottom: 50px;
  top: 0;
  z-index: -1;
}
.backgroundLines{
  background-image: url("/assets/imgs/lines_background_5.png");
  background-size: cover;
  width: 100%;
  height: 50%;
  /* margin-top: -400px;*/
}

#lines{
  background-image: url("/assets/imgs/lines_background_5.png");
  /* display: inline; */
  width: 100%;
  height: 25%;
  margin-top: -300px;
}

#svg{
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  width: 80px;
  overflow: visible;
}

#connectedLines{
  display: block;
  stroke-width:10px;
  stroke: black !important;
}

.img{
  background-image: url("/assets/imgs/img_8.jpg");
  height: 500px;
  width: 75%;
  background-size: cover;
  margin-top: 50px;
}

.comoHR {
  display: block;
  background-color: black;
  width: 50%;
  border: 0;
  height: 8px;
}

.leftContainer{
  width: 25%;
  height: auto;
}
.leftDivContainer{
  background-color: white;
  width: 80%;
  height: 250px;
  border-radius: 50%;
}
.leftImage{
  height: 50%;
  width: 50%;
}
.middlePad{
  margin-top: 60px;
}
.leftText{
  width: 30%;
  height: auto;
  padding-top: 20px;
}
.comoText {
  padding-top: 20px;
}

.midContainer{
  width: 25%;
  height: auto;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<div class="container-fluid">
  <div class="parentContainer">
    <div class="backgroundLines">
      <div class="d-flex justify-content-center imgParent">
        <div class="img">
        </div>
      </div>
      <br><br><br><br>
      <!-- textt in the top -->
      <div class="d-flex justify-content-between">
...

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

Codepen link for the same example: https://codepen.io/anon/pen/QXwpmR

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

Developing an Easy-to-Use PDF Popup Interface

I need a simple PDF modal where I can input the text: 'The sky is blue' and have it link to a PDF that opens up when clicked. I found a similar sample online, but it includes an image plus an image modal that pops up. I want to replace the imag ...

Troubleshooting the issue of CSS animations activating twice and causing a flickering effect specifically in the Firefox browser

I am facing an issue with CSS animations in Firefox. When I try to slide in some radio buttons upon clicking a button, the animation seems to be firing twice in Firefox while it works fine in Chrome. I have attempted several solutions but haven't been ...

Checkbox value not being accurately retrieved by Struts2 page

I have a form that captures phone information for two different phones, with each phone having its own set of details. If the user enters the same phone number for both phones, the second checkbox is automatically checked using the JavaScript code below: ...

The IIS appears to be experiencing difficulties in serving static content such as CSS, JavaScript, and images, resulting

I've completed this process a countless number of times... Start by creating a project (in this case, an empty web application using only HTML files). Edit the hosts file to allow for a custom URL (local.xxx-xxx.com) Create an IIS website and app po ...

Animate the chosen text via specialized effects

I am trying to implement a show/hide feature for specific text using jQuery. The challenge I am facing is having multiple instances of the same text tag with identical ids. I want to trigger the animation on a particular child element when hovering over it ...

I am struggling to retrieve information from HTML elements using the GET method in Node.js and MongoDB

Code Troubleshooting var userID = req.userid; var pwd = req.pwd; console.log("userid = " + userID + "pass = " + pwd); The console is displaying undefined values instead of the input data. I have a problem with fetching data from an HT ...

How can I create space between a checkbox and its label in Google Web Toolkit (GWT)?

How can I create space between a Checkbox and its content in GWT? Checkbox c = new Checkbox("checkme"); c.setStyleName("checkbox_style"); When I try using padding or margin, the entire checkbox and its content move together. Is there a way to achieve a g ...

Using CSS to create sleek all-black Flaticons

After trying various solutions, I am still unable to fix this issue. I downloaded some icons and in the demo, they all appear as they should, with a more colorful aesthetic. Here is what the icons should look like: However, this is how the icons actually ...

Reactstrap: Keep drop down menu open after an item is selected

In a DropdownItem, there is a search Input that should stay open when clicked to allow the user to type in their search query: import React, { Component } from "react"; import { connect } from "react-redux"; import { Dropdown, Dropd ...

Unable to place the div at the bottom of its parent div

I've encountered an issue with the code below and I'm not sure what I'm doing wrong. It seems to work in Dreamweaver, although not in live view, but it sticks to the top and left in Safari and Firefox. I attempted replacing the masthead div ...

Challenge with CSS selectors

Here is the HTML code I am working with: <label for="tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]" class="error" id="tx_alterneteducationcatalog_subscriberadd[newSubscriber] [gender]-error">This field is required.</label> ...

Exploring the grid system within bootstrap

As I venture into the world of web design, I have chosen to explore Angular. However, I find myself grappling with certain concepts in bootstrap, unsure of what is the correct approach. Being a novice in this field, I appreciate your patience as I seek gui ...

Set the search input to occupy the full width of the container by utilizing Bootstrap's

I'm having trouble adjusting the width of my search input to 100% on screen resize (using @media (max-width: 1200px)). The issue: https://i.sstatic.net/EMr6W.jpg Here's how it should look (I can achieve this with a specific pixel width, but not ...

Directories within directories - HTML base directories & subdirectories

Within my HTML, I have included the following code: <head> <base href="http://mydomain.com/dev/"> </head> Despite this base element setting, all of my links seem to be pointing to mydomain.com/ instead of the expected subfolder /dev/. ...

Requesting HTML content from a PHP file using JQuery Ajax callback

For an ajax request, I am entering a name in an input box to search for data from a database. Everything is functioning properly. <script> $(document).ready(function(){ $('input#name-submit').on('click', function() { ...

Tips for Keeping Footer Aligned with Content:

When checking out this website, you may notice that the footer appears to be affixed to the left side. The CSS code responsible for this is as follows: #footer { width: 800px; clear:both; float:right; position:relative; left:-50%;} I would appreciate it ...

Maintain uniform product dimensions for images and configurable swatches in Magento

I am new to using Magento and I am currently working on setting a consistent product image grid size of 500px x 500px for the product detail page. Some of my product images are in square or rectangular shapes, so I need to resize them to fit into the grid ...

Problem with dropdown menu on Internet Explorer 9

Encountering a problem with a dynamic dropdown list in Internet Explorer 9. A table populates one of its columns with individual combo boxes, each created using HTML 5.0 code like this: <select id="cboABC0" class="RetrieveList cboABC" data-index="0" d ...

having trouble loading images properly with javascript

I am currently developing an image search program using JavaScript. The program allows users to input a name, and with the help of an XML database, it retrieves images related to that name and displays them on the canvas. However, I have encountered a pro ...

Using javascript, what is the best way to clear a text field with a specific condition?

When I clear the text field #t1, I expect text field #d1 to also clear. However, the last two lines of code do not achieve this result. function utl() { var tField = document.getElementById('t1'); var dField = document.getElementById(&a ...