2017-04-04 118 views
-4

展开DIV向右CSS

.icon1 { 
 
    float: left; 
 
    width: 0; 
 
    height: 0; 
 
    border-bottom: 100px solid red; 
 
    border-right: 100px solid transparent; 
 
} 
 
    
 
.text1 { 
 
    float: right; 
 
    width: 0; 
 
    height: 0; 
 
    border-bottom: 100px solid transparent; 
 
    border-right: 100px solid red; 
 
    right: 50px solid red; 
 
}
<div class="content"> 
 
    <div class= "icon1"></div> 
 
    <div class= "text1"></div> 
 
</div>

我要让文本1格向右展开,我觉得截图将帮助:https://gyazo.com/e0ac67dadf5a0c8b20de2508cd525862 你们能帮助我吗?我想要左三角形是没有左下角的矩形。

+1

我不确定你的预期结果是什么。此外,您可以将您的代码转换为Stack Snippet。 – domsson

+0

这是我想达到的一点:https://gyazo.com/01f8aa86563c036653cfd4cb011b7fbb –

+0

有没有原因,你不能使用'img'或'svg'?就目前而言,为了使用CSS创建这种形状,我认为您需要多个元素,“伪”或其他。您可能可以使用'clip-path',具体取决于您使用的形状。 – hungerstar

回答

0

不知道这是否适用于你,就砍死了一起真正快速:

.content { 
 
    overflow: hidden; 
 
    box-sizing: border-box; 
 
    display: inline-block; 
 
    height: 120px; 
 
    padding: 10px; 
 
    background: #fff; 
 
} 
 

 
.icon1 { 
 
    float: left; 
 
} 
 

 
.icon1::before { 
 
    content: " "; 
 
    float: left; 
 
    height: 0; 
 
    width: 0; 
 
    border-top: 100px solid transparent; 
 
    border-left: 100px solid #f00; 
 
} 
 

 
.icon1::after { 
 
    content: " "; 
 
    float: left; 
 
    width: 0; 
 
    height: 0; 
 
    margin-left: -70px; 
 
    border-right: 100px solid #f00; 
 
    border-bottom: 100px solid transparent; 
 
} 
 

 
.text1 { 
 
    float: left; 
 
    height: 100%; 
 
    padding: 0 1em; 
 
    line-height: 80px; 
 
    color: #fff; 
 
    background: #f00; 
 
    font-family: sans-serif; 
 
    font-weight: bold; 
 
}
<div class="content"> 
 
    <div class= "icon1"></div> 
 
    <div class= "text1"><p>I'm some text within a fancy box.</p></div> 
 
</div>

Bazinga。

编辑:根据OP的最新图片参考完全重做。没有在任何其他浏览器尝试它,不知道这是否会保持良好。虽然FF在我看来很好。

+0

我在评论中将OP共享的图片添加到了他们的帖子中,可能是一个有用的参考。 – hungerstar

+0

如果我误导了你们,我很抱歉,我非常感谢你的帮助,但是我希望我们有箱子里的文字,就像在图像中一样。我需要一个底部的三角形和一个角度在左边的矩形。 –

+0

但是......但文本是在盒子里面?你参考什么图像?我看到两个,都没有文字。我真的很困惑。 – domsson