CSS - How to change border height in linear-gradient?

akcasoy

I have the following table:

enter image description here

and this css for the table border:

border-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, #B3B3B3 20%) 0 0 0 1;

i want the border ends where the last list item bullet ends. Can i achieve this with the border-image property? Or is this possible at all? By the way the height of the list items may vary, not every item has the exact same height.

So this should be the result:

enter image description here

wlh

If you would be able to know the height of the either the ul or at least the last li, then a css only solution is definitely possible; otherwise, it gets tricky.

The linear-gradient function takes four values (see https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient#Values), one of which is the color-stop-list. If you set one stop to end and another to begin at the same point (either a percentage or a length, such as pixels), then you get a solid line at that stop with the defined or default angle.

So, you can get the gradient to stop at a fixed pixel point as follows:

linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, #b3b3b3 20%, #b3b3b3 calc(100% - 25px), rgba(0,0,0,0) calc(100% - 25px))

Here, I am changing from the main color to a color with opacity: 0 at a point 25px from the full height of the box (since we are using to bottom). You can try to eyeball this for you project, or use JavaScript via Element.getBoundingClientRect().height (see https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) on the last li to calculate the position of the list-item-type based on how you define that in your css.

To answer the question in your last comment, use the same logic and set a stop point 20px in:

linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 20px, #b3b3b3 20px, #b3b3b3 calc(100% - 25px), rgba(0,0,0,0) calc(100% - 25px))

Having said this you may consider handling the border on each individual li rather than on the ul, which would make it much easier to handle without JavaScript. You would then only need to supply linear-gradient values on the ul>li:first-child and ul>li:last-child using the principles above. Just keep in mind that if you use margin-top or margin-bottom on any li in the list, you will see gaps in your border.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to create semi transparent linear gradient background and border using css?

How to make a button a linear gradient color border in tailwind css?

HTML CSS Border Linear Gradient Corners

CSS Transition with Border Radius and Linear Gradient

CSS - linear-gradient - How to make the gradient part of border constant, not percentual?

CSS linear gradient for div with dynamic height

Gradient colour with Linear Gradient Border in text using css not working

How to apply linear-gradient to input border?

how to change height of ellipse in radial gradient in css for background property

Creating border linear gradient

Linear gradient border issue

CSS Background Image Linear Gradient showing unwanted border in Chrome

How to change ModalBottomSheet border and height?

how to change the linear gradient color in shimmer effect

How to reposition an image with a linear gradient using css?

linear gradient bottom border on hover

Background border radius with linear gradient

How to use gradient in border in CSS3?

How to create a CSS loader with gradient border and transparency?

How to use css property linear-gradient to gradually change color from red to yellow to green?

how to change the css height?

CSS Linear gradient is inaccurate?

CSS linear gradient with separations

CSS - Change background image without affecting linear gradient?

Animating a CSS linear-gradient's change in percentage values in Javascript?

css gradient border with transparency

CSS Button with Gradient Border

Gradient on a div border in CSS

How to set multi-color border using border-image and linear-gradient?