The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other diagonal line

  • This topic is empty.
Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
  • #85856

    @Mottie, THANKS!


    I have the same problem and haven’t really come up with any good solution. The best I could do without javascript was this and it really doesn’t look good and it’s not very flexible. It kind of looks good on a retina display in some sizes.

    I think I’ll go for an image instead…


    Stumbled upon this when I googled the same issue:)

    A technique i’m just playing with is using SVG as background image.:

    background-image: url(‘img/bg.svg’);
    -o-background-size: 100% 100%;
    -webkit-background-size: 100% 100%;


    Here’s my attempt:

    It only works for chrome for now, because I was too lazy to add all the prefixes in the js and css.

    the script:

    scrW = $(window).width();
    scrH = $(window).height();
    angle = (Math.atan(scrH / scrW)) * (180/3.14);
    var line = $(‘#line’);
    var length = Math.sqrt(( scrW * scrW) + (scrH * scrH ));
    line.css(‘left’, ( -1 ) * ((length – scrW) / 2) );
    line.css(‘width’, length);
    line.css(‘top’, scrH / 2);
    line.css(“-webkit-transform”, “scale(1) rotate(” + (-1) * angle + “deg) translateX(0px) translateY(0px) skewX(0deg) skewY(0deg)”);

    Rob Wierzbowski

    If you’re ok with a css3 requirement, you can create an oversized image with a diagonal line from one corner to the other, and then apply as a fixed background on an element with [background size]( 100% 100%. One quibble is the line thickness will change depending on the pixel size of the viewport, but during a single session that won’t be noticeable.


    You can use a diagonal (`to bottom right`) gradient that is very thin..



    background:linear-gradient(to bottom right,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0) 50%,
    rgba(0,0,0,1) 50.1%,
    rgba(0,0,0,0) 50.2%,
    rgba(0,0,0,0) 100%


    Expanding on gaby’s post, you can use calc to get the precise pixel width that you want that line to be:

    In SCSS:

    $line-color: red;
    $line-width: 1px;
    background-image: linear-gradient(to bottom left, transparent 50%, $line-color 50%, $line-color calc(50% + $line-width), transparent calc(50% + $line-width));

    See a working codepen example here.

Viewing 7 posts - 16 through 22 (of 22 total)
  • The forum ‘Other’ is closed to new topics and replies.