I’m trying to create a responsive dots connecting among the images like below.
I’m able to achieve this with CSS, but the layout is collapsing when I tried to change the image widths or parent div width. How can I make this layout work for all screens and image dimensions?
Here is my code link: https://jsfiddle.net/SampathPerOxide/q2yab607/29/
JavaScript
x
41
41
1
.dotted-line,
2
.dotted-line1 {
3
display: flex;
4
}
5
6
.over {
7
display: flex;
8
align-items: center;
9
justify-content: center;
10
}
11
12
.dotted-line::after {
13
content: ".......";
14
letter-spacing: 3px;
15
font-size: 30px;
16
color: #9cbfdb;
17
display: table-cell;
18
vertical-align: middle;
19
padding-left: 1px;
20
}
21
22
.dotted-line1::before {
23
content: "........";
24
letter-spacing: 3px;
25
font-size: 30px;
26
color: #9cbfdb;
27
display: table-cell;
28
vertical-align: middle;
29
padding-right: 1px;
30
}
31
32
.top:before {
33
transform: rotate(90deg);
34
content: "........";
35
letter-spacing: 3px;
36
font-size: 30px;
37
color: #9cbfdb;
38
position: absolute;
39
top: 5em;
40
margin-left: 0.5em;
41
}
JavaScript
1
29
29
1
<div style="width:90px;margin:0px auto;">
2
<div style=" height: 100%;
3
width: 100%;
4
display: flex;
5
align-items: center;
6
justify-content: center;
7
" class="top">
8
<img src="https://i.pinimg.com/736x/39/4b/f6/394bf6e1c3f2a7351105290ef9fe9dd1.jpg" style="width:100px;">
9
10
</div>
11
<br/><br/><br/>
12
<div class="over">
13
<div style="" class="dotted-line">
14
<img src="https://stat.overdrive.in/wp-content/odgallery/2020/06/57263_2020_Mercedes_Benz_GLS.jpg" style="width:100px;">
15
</div>
16
<div style="">
17
<h4 style="text-align:center;padding:10px;">
18
Choose
19
</h4>
20
</div>
21
<div style="" class="dotted-line1">
22
<img src="https://stat.overdrive.in/wp-content/odgallery/2020/06/57263_2020_Mercedes_Benz_GLS.jpg" style="width:100px;">
23
</div>
24
25
</div>
26
27
28
29
</div>
Advertisement
Answer
I would go for
- display
flex
to easily arrange the items inside a flexbox - Use a repeated background-image with
radial-gradient
to achieve repeated responsive dots
JavaScript
1
44
44
1
* {
2
margin: 0;
3
box-sizing: border-box;
4
}
5
6
h4 {
7
padding: 1em;
8
}
9
10
.flex {
11
display: flex;
12
}
13
14
.flex.col {
15
flex-direction: column;
16
}
17
18
.flex.center {
19
justify-content: center;
20
}
21
22
.grow {
23
flex-grow: 1;
24
}
25
26
.dots-h,
27
.dots-v {
28
flex-grow: 1;
29
background-image: radial-gradient(1px 1px at center, #888 1px, transparent 1px);
30
}
31
32
.dots-h {
33
height: 1em;
34
background-repeat: repeat-x;
35
background-size: 10px 1em;
36
margin: auto 0;
37
}
38
39
.dots-v {
40
width: 1em;
41
background-repeat: repeat-y;
42
background-size: 1em 10px;
43
margin: 0 auto;
44
}
JavaScript
1
16
16
1
<div>
2
<div class="flex center">
3
<img src="https://picsum.photos/id/1/100/100">
4
</div>
5
<div class="flex center">
6
<img src="https://picsum.photos/id/2/100/100">
7
<div class="dots-h"></div>
8
<div class="flex col center">
9
<div class="dots-v"></div>
10
<h4>Choose</h4>
11
<div class="grow"><!-- Just a spacer --></div>
12
</div>
13
<div class="dots-h"></div>
14
<img src="https://picsum.photos/id/9/100/100">
15
</div>
16
</div>