简体   繁体   English

如何用CSS或SVG连接离子网格中的三个方块?

[英]How to connect three squares in ion-grid with CSS or SVG?

I have an ion-grid of 1 row by 3 columns: 我有一个1行乘3列ion-grid

What I'd like to do is connect the green squares with a dashed line, like this (the line is hand drawed on the image): 我想做的是将绿色方块用虚线连接,就像这样(在图像上手绘线条):

在此输入图像描述 在此输入图像描述

I have thought to put a background image of a dashed line behind the grid, but this is what I get: 我曾想过在网格后面放一个虚线背景图片,但这就是我得到的: 在此输入图像描述

When the grid is vertically positioned, the line should be vertical, and the same with horizontal position (like in the first images). 当网格垂直定位时,线应该是垂直的,并且与水平位置相同(就像在第一个图像中一样)。

Also, I have thought of a SVG dashed line drawed somehow between the squares (but I'm very new to SVG so I'm not very sure). 另外,我想到了在广场之间以某种方式绘制的SVG虚线(但我对SVG很新,所以我不太确定)。

Could this be achived by using HTML, CSS or SVG? 这可以通过使用HTML,CSS或SVG来实现吗? Can you think of anything different? 你能想到什么不同吗?

Edit: added code 编辑:添加代码

Current HTML: 目前的HTML:

<div class="my-grid">
    <ion-grid fixed>
        <ion-row text-center>
            <ion-col col-12 col-sm>
                <div></div>
            </ion-col>
            <ion-col col-12 col-sm>
                <div></div>
            </ion-col>
            <ion-col col-12 col-sm>
                <div></div>
            </ion-col>
        </ion-row>
    </ion-grid>
</div>

Current CSS: 目前的CSS:

ion-col div {
    height: 100px;
    width: 100px;
    background-color: green;
}
ion-col {
    border-width: thin;
    border-color: blue;
    border-style: solid;

    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

Edit: added Stackblitz example here . 编辑: 在这里添加了Stackblitz示例。

By defining the grid areas for grind items, you can achieve overlapping items and thus add a dashed line. 通过定义研磨项目的网格区域,您可以实现重叠项目,从而添加虚线。 See my snippet below. 请参阅下面的我的代码段。

 ion-row { display: grid; } ion-col div { height: 100px; width: 100px; background-color: green; } ion-col { border-width: thin; border-color: blue; border-style: solid; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 1; } @media (min-width: 577px) { ion-row { grid-template-columns: 33% 33% 33%; grid-template-rows: 150px; } ion-col { grid-row: 1; } ion-col:nth-child(1) { grid-column: 1; } ion-col:nth-child(2) { grid-column: 2; } ion-col:nth-child(3) { grid-column: 3; } .dash-container { grid-column: 1 / 4; grid-row: 1; height: 3px; align-self: center; display: flex; justify-content: center; } .dash.horizontal { width: 66%; border-top: 3px dashed #000; height: 10px; } } @media (max-width: 576px) { ion-row { grid-template-rows: 33% 33% 33%; grid-template-columns: 150px; height: 450px; } ion-col { grid-column: 1; } ion-col:nth-child(1) { grid-row: 1; } ion-col:nth-child(2) { grid-row: 2; } ion-col:nth-child(3) { grid-row: 3; } .dash-container { grid-row: 1 / 4; grid-column: 1; height: 100%; width: 3px; align-self: center; display: flex; justify-content: center; margin-left: 50%; margin-top: 33%; } .dash.horizontal { height: 66%; border-left: 3px dashed #000; width: 0; } } 
 <div class="my-grid"> <ion-grid fixed> <ion-row text-center> <ion-col col-12 col-sm> <div></div> </ion-col> <ion-col col-12 col-sm> <div></div> </ion-col> <ion-col col-12 col-sm> <div></div> </ion-col> <div class="dash-container"> <div class="dash horizontal"></div> </div> </ion-row> </ion-grid> </div> 

I have added a new element .dash-container which spans the whole grid and is self-centered. 我添加了一个新元素.dash-container ,它跨越整个网格并以自我为中心。 Within that element is another element which is only 66% in width/height (which is the distance between the center points of the outer boxes if each is 33% wide) and has a dashed border. 在该元素内是另一个元素,其宽度/高度仅为66%(如果每个宽度为33%,则为外框的中心点之间的距离)并且具有虚线边框。

I combined both former snippets into one using media queries. 我使用媒体查询将两个前片段合并为一个。 Below 577px, the grid is vertical. 低于577px,网格是垂直的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM