How to pinch the middle of a line in css


Tags: html,css,css3,css-shapes

Problem :

I'm trying to make a line that almost looks like it has serifs at the ends. Essentially, I want to make it wider at the very ends and thin in the middle, just using css. This has actually proven to be quite a challenge.

Any help would be appreciated.

Thus far I've been able to get the bottom to look how I want using the :after pseudo selector, but no luck with the top, which I can only seem to get concave, rather than convex.

Here's the code of what I've done so far

    .line {
        background:none;
        height: 8px;
        position:relative;
        overflow:hidden;
        z-index:1;
        top: 50px;
        left: 50px;
        width: 140px;
        box-shadow: 11px 12px 16px -3px rgba(0,0,0,0.6);
        -webkit-transform: rotate(38deg);
        transform: rotate(38deg);
    }
    .line:after {
        content: '';
        position: absolute;
        left: 0%;
        width: 100%;
        padding-bottom: 10%;
        top: 50%;
        border-radius: 35%;
        box-shadow: 0px 0px 0px 150px rgba(0,0,0,0.6);
        z-index: -1;
    }
    .line:before {
        content: '';
        position: absolute;
        left: 0%;
        width: 100%;
        padding-bottom: 8%;
        top: -30%;
        border-radius: 35%;
        box-shadow: 0px 0px 0px 150px rgba(255,255,255, 1);
        z-index: 24 !important;
    }

and the HTML

<section class="stage">
    <figure class="line"></figure>
</section>

Here's the fiddle of what I have thus far (also, I'm gonna need to rotate it for certain areas)

http://jsfiddle.net/speo9bfv/1/

Thanks for the help!



Solution :

If you have a plain background color, you can do this with pseudo elements :

DEMO

HTML :

<section class="stage">
    <figure class="line"></figure>
</section>

CSS :

.line {
    height: 8px;
    position:relative;
    overflow:hidden;
    z-index:1;
    top: 50px;
    left: 50px;
    width: 140px;
    -webkit-transform: rotate(38deg);
    transform: rotate(38deg);
    background:rgba(0,0,0,0.6);
}
.line:after, .line:before {
    content:'';
    position: absolute;
    left:0;
    width:100%;
    height:100%;
    border-radius: 35%;
    background:#fff;
}
.line:after{
    top:5px;
}
.line:before{
    bottom:5px;
}

    CSS Howto..

    CSS How to change background color of text?

    How do I put a clear button inside my HTML text input box like the iPhone does?

    How to use easeOutBounce animiation on display block?

    How to adjust width of right-aligned navbar

    How to squircle an app icon image with just CSS

    How to put background after anchor tag throw css?

    How do you structure css files for a web project?

    .addClass - How to call CSS from linked css?

    How to make a CSS menu to remain visible after a child has been clicked on

    How to make responsive video background in DIV container with dynamic height?

    CSS - HTML how to make the anchor image go to a specific spot

    How to load multiple CSS files within a JS script

    How to grab a CSS syntax with JavaScript?

    Show Link on image at hovering in jquery

    Drupal 7.x: how to apply styles to RSS feed in node?

    How to detect and deliver separate CSS files for mobile devices?

    How can I keep the original :focus element with CSS?

    how to properly use css in jsf?

    How to DRY up on SASS transitions with multiple elements?

    how to create css concave/convex shapes

    float css only menu - how to modify on section2

    Show specific comment in LESS file when compiled to CSS while keeping all other comments hidden

    How to style a dynamic html created by PHP

    How do I add line-height to a