0

I've seen many related questions and examples on this but have had no joy.

I have created a segment:

#bar-segment {
  border-radius: 15px;
  height: 2px;
  width: 20px;
  background-image: linear-gradient(to right, $brand-color-blue , $brand-color-green);
}

I'm using this to build a meter (single-bar bar chart kinda thing). So I basically want to stack these segments (repeat-y) in order to reflect a meter reading. So I found this: background-image: element() and tried so many things but never managed to get even an image to show up on the screen never mind do anything with it. Very frustrating. Ultimately I guess I don't have a clue how to use it. Can anyone show me correct usage of this and perhaps help me to repeat them vertically?

The closest I found is this but couldn't even get this to repeat-y somehow. a jsfiddle

Here's a link to an image to give you an idea of what I'm trying to achieve: Sound Equaliser Bar Chart

Ree
  • 863
  • 2
  • 18
  • 38

2 Answers2

0

I make some for you, hope it helps

<!DOCTYPE html>
<html>
<head>
    <title>Bars </title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<style type="text/css">
*{
    border: 0;
    margin: 0;
}
    body{
        background-color: #000 ;
        background-image: url(https://images.unsplash.com/photo-1533174072545-7a4b6ad7a6c3);
        background-repeat: no-repeat;
        background-position: center;



    }
.box-main {
    margin: 15px auto;
    background: linear-gradient(to bottom, #000 0%, #17191d 100%);
    border: solid 2px #3e434c;
    height: 600px;
    width: 390px;
    border-radius: 40px;
    padding: 15px;
}
/*change #id to .class, we use it a lot of times*/
.dotted_line {
    width: 100%;
    height: 10px;
    float: left;
    margin: 10px auto;
    background-image: url('https://i.stack.imgur.com/ygAUp.png');
    background-repeat: repeat-x;
    background-size: 10px 10px;
    /* background-color: black; */
    border-radius: 5px;
    margin: 18 auto;
    /* box-shadow: inset -2px -2px 2px 0px rgb(66, 70, 74), inset 1px 1px 1px -1px rgb(0, 0, 0); */
    padding: 7px 4px;
    background-position: center;
    animation:bar 3s -1s linear infinite alternate running; 
}

    
  }
@-webkit-keyframes bar {
    0%   {width: 0%; }
    25%  {width: 20%; }
    50%  {width: 60%; }
    75%  {width: 70%;}
    100% {width: 100%;}
}
@keyframes bar {
    0%   {width: 0%; }
    25%  {width: 20%; }
    50%  {width: 60%; }
    75%  {width: 70%;}
    100% {width: 100%;}
}
.bar-0{ left:7px; -webkit-animation-duration: 1s; animation-duration: 2s;}
.bar-1{ left:16px; -webkit-animation-duration: 321ms; animation-duration: 321ms;}
.bar-2{ left:25px; -webkit-animation-duration: 353ms; animation-duration: 353ms;}
.bar-3{ left:34px; -webkit-animation-duration: 341ms; animation-duration: 341ms;}
.bar-4{ left:42px; -webkit-animation-duration: 327ms; animation-duration: 327ms;}
h1 {
    color: #ccc;
    font-size: 15px;
    text-align: center;
    margin-bottom: 112px;
}
</style>

</head>
<body>
<div class="box-main">
    <h1>The best music Peak Level</h1>
<div id="doted1" class="dotted_line bar-3"></div>
<div id="doted2" class="dotted_line bar-4"></div>
<div id="doted3" class="dotted_line bar-1"></div>
<div id="doted4" class="dotted_line bar-3"></div>
<div id="doted5" class="dotted_line bar-0"></div>
<div id="doted6" class="dotted_line bar-4"></div>
<div id="doted7" class="dotted_line bar-2"></div>
<div id="doted8" class="dotted_line bar-0"></div>
<div id="doted9" class="dotted_line bar-1"></div>

</div>
</body>
</html>
stevejobs
  • 391
  • 2
  • 4
  • this is pretty cool! not quite what I need though - I apparently need to repeat my own div and not an image. and not along the x-axis but rather the y-axis... but its cool! – Ree Jun 11 '21 at 10:20
  • you've actually given me something helpful to work with here. thank you! – Ree Jun 11 '21 at 10:29
0

I took inspiration from another question and got this which works perfectly :)

<div id="bar-segment" *ngFor="let i of Arr(num).fill(1)"></div>
Ree
  • 863
  • 2
  • 18
  • 38