Forums

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

Home Forums CSS Flexible triangles using borders?

  • This topic is empty.
Viewing 15 posts - 1 through 15 (of 21 total)
  • Author
    Posts
  • #40956

    Greetings everyone (:

    I came up with a design issue where there’s a banner-like background on a [navigation](http://prntscr.com/kf038 “navigation”) (the red one). Now I usually tend to create a CSS/CSS3 version of almost every graphics in a design and I was hoping this was the same – until I realized that this was a navigation, and I just couldn’t use borders to create the triangles on the bottom. I tried giving percent for the borders’ width, but it doesn’t work. I **can** use background-images, but then that would mean multiple images (even in a sprite) and if _in case_ I have to add more links, I have to draw more images.

    Do you think it’s possible to recreate that completely with CSS?

    Thanks.

    #115365

    So? There is no solution to this?

    #115397
    Paulie_D
    Member

    Nope…not without images.

    #115399
    jwebcat
    Member

    hey why dont you just use :after on the li element
    like:
    li:after {
    position: absolute:
    border-top: .2em solid grey;
    border-left: .2em solid transparent;
    border-right: .2em solid transparent;
    content: “”;
    }

    #115400
    jwebcat
    Member

    then you can align it with the absolute positioning and make it appear/dissappear with
    .visuallyhidden {
    border: 0;
    clip: rect(0 0 0 0); height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    }

    #115401
    Paulie_D
    Member

    It doesn’t work because the width of the li is not fixed and so you can’t set a top/bottom border width for the pseudo element either.

    A pseudo element would be the way to go but it will need a background image of some kind….one that scales appropriate to the size of the element.

    Perhaps playing with background-size?

    #115405
    jwebcat
    Member

    what is the width of the li declared in?

    #115406
    jwebcat
    Member

    percentage?

    #115407
    Paulie_D
    Member

    If you don’t know the width of the li your only option is to use a width of 100% for the border and that doesn’t work.

    #115408
    jwebcat
    Member

    you could also create a separate li and make it animate into place.
    like

    • item

      • triangle

    #115409
    Paulie_D
    Member

    The width of the li isn’t declared at all….it has the width of each ‘a’ + padding.

    As the ‘a’ doesn’t have a set width…you don’t know the width of the li.

    #115410
    jwebcat
    Member

    it didnt like my code

    #115411
    Paulie_D
    Member

    >you could also create a separate li and make it animate into place. like item triangle

    …but you still don’t know how wide to make the triangle….and it’s unsemantic markup used for styling which properly belongs in the css.

    #115412
    Paulie_D
    Member

    > it didnt like my code

    Use Codepen….it’s easier for the rest of us to look at.

    #115413
    jwebcat
    Member

    do you have a pen already started?
    If you start one I will try to help.

Viewing 15 posts - 1 through 15 (of 21 total)
  • The forum ‘CSS’ is closed to new topics and replies.