Is it possible to have a non-rectangular div?

前端 未结 10 1919
滥情空心
滥情空心 2021-01-11 14:26

I need to shape ONE div tag in the following shape:

Is it possible to make it cross browser? I don\'t necessarily need rounded

相关标签:
10条回答
  • 2021-01-11 14:53

    Perhaps you could use Border-radius along with 2 or 3 div's to get the look you want. The only issue then is it's not supported in all browsers.

    0 讨论(0)
  • 2021-01-11 14:53

    A one div solution using pseudo elements:

    /* relevant styles for shape */
    .tab {
      border-top-left-radius: 0px;
      margin-left: 100px;
    }
    
    .tab:before {
      content:"";
      display: block;
      position: relative;
      height: 50px;
      width: 50px;
      right: 52px; /* width + border width */
      top: -2px;
      background-color: white;
      border: inherit;
      border-right-width: 0px;
      border-top-left-radius: 5px;
      border-bottom-left-radius: 5px;
    }
    
    /* styles to look like example */
    div{
      box-sizing: border-box;
      background-color: white;
      border: 2px solid red;
      height: 100px;
      width: 200px;
      border-radius: 5px;
    }
    
    div:hover {
      border-color: green;
    }
    <div class="tab"></div>

    0 讨论(0)
  • 2021-01-11 14:57

    Yeah, you can do that using HTML and CSS like this: http://jsfiddle.net/broofa/364Eq/

    It's essentially using three divs to aggregate the mouse events, like so:

    <div id="outer">
      <div class="inner"></div>
      <div class="inner"></div>
    </div>
    

    And I use a :hover rule on the outer element to affect the border colors on the inner divs:

    #outer .inner {border-color: red}
    #outer:hover .inner {border-color: blue}
    

    The only quirk with this markup is that the content area - the area you drew in your image - is that it's two divs, not one. So text won't wrap and flow the way you might expect. Also, this may not work so well on older (IE6-7) browsers. But FF, Chrome, Safari, Opera should probably be okay.

    0 讨论(0)
  • 2021-01-11 14:57

    See this jsFiddle example:

    <div id="main">    
        <div id="div1" class="border">
            &nbsp;
        </div>
        <div id="div2" class="border">
            &nbsp;
        </div>
    </div>
    
    0 讨论(0)
提交回复
热议问题