css - 有没有更简单的方法来使用 css 创建这个形状? (包括 jsfiddle)

标签 css shapes

我正在尝试围绕广告设计这种形状,但仍允许其中的正常文本流动。你可以看到这是一个引用,我一直在为曲线制作不同的 id 和类。所以现在它实际上是 3 个元素,边界重叠,但我觉得它做的工作比需要的多。

http://jsfiddle.net/dUKQe/

最佳答案

这还不是 100% 完美(浏览器之间似乎有一些细微的像素差异需要敲定——我已经花了太长时间了),但总的来说,这非常接近你所寻求的明智地使用伪元素。

See the example fiddle .

HTML

<div id="text3" class="text">
    <h4>Bruce Lee</h4>
        <p><q>Be like water making its way through cracks. Do not be assertive, but adjust to the object, and you shall find a way around or through it. If nothing within you stays rigid, outward things will disclose themselves. Empty your mind, be formless. Shapeless, like water. If you put water into a cup, it becomes the cup. You put water into a bottle and it becomes the bottle. You put it in a teapot, it becomes the teapot. Now, water can flow or it can crash. Be water, my friend.</q>
        </p>
</div> 

CSS

#text3 {
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 0;
}

.text h4 {
    width: 228px;
    color: #ffffff;
    background-color: #012E40;
    margin: 5px 5px 0 5px;
    padding: 10px 10px 0 10px;
    border: 3px solid #000000;
    border-bottom-width: 0;
    -moz-border-radius: 5px 5px 0px 0px;
    border-radius: 5px 5px 0px 0px;
    position: relative;
}

.text h4:before {
    content: '';
    position: absolute;
    width: 3px;
    height: 3px;
    right: -3px;
    bottom: 0;
    background-color: #012E40;
}

.text h4:after { /*upper light blue bkg */
    content: '';
    display: block;
    background-color: #1B4E59;
    border: 2px solid #000000;
    width: 210px;
    height: 3em;
    padding: 5px;
    margin-top: -9px;
    margin-left: 2px;
    margin-bottom: -2px;
    border-bottom-width: 0;
    -moz-border-radius: 5px 5px 0px 0px;
    border-radius: 5px 5px 0px 0px;
    position: relative;
    top: 10px;
    z-index: 1;
}

.text p {
    color: #ffffff;
    margin: -3em 5px 5px 5px;
    padding: 0 5px 5px;
    width: 448px;
    position: relative;
}

.text p:before { /* inset border corner */
    content: '';
    display: block;
    width: 200px;
    height: 3em;
    float: right;
    margin: -3px 0px 3px 15px;
    border: 3px solid #000000;
    border-top-width: 0;
    border-right-width: 0;
    -moz-border-radius: 0px 0px 0px 5px;
    border-radius: 0px 0px 0px 5px;    
}

.text p:after { /* lower dark blue bkg */
    content: '';
    display: block;
    position: absolute;
    top: 3em;
    right: 0;
    bottom: 0;
    left: 0;
    margin-top: -3px;
    background-color: #012E40;
    border: 3px solid #000000;
    -moz-border-radius: 0px 5px 5px 5px;
    border-radius: 0px 5px 5px 5px;
    z-index: -1;
}

.text p q {
    display: block;
    margin: 0 10px 10px;
    padding: 5px;
    position: relative;
    z-index: 2;
}

.text p q:before { /* 2nd inset border corner */
    content: '';
    display: block;
    height: .5em;
    width: 202px;
    position: absolute;
    top: 3em;
    right: 3px;
    border: 2px solid #000000;
    border-top-width: 0;
    border-right-width: 0;
    -moz-border-radius: 0px 0px 0px 5px;
    border-radius: 0px 0px 0px 5px;
    z-index: 3;    
}

.text p q:after { /* lower light blue bkg */
    content: '';
    display: block;
    position: absolute;
    top: 3.5em;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: #1B4E59;
    border: 2px solid #000000;
    border-top-width: 0;
    -moz-border-radius: 0px 5px 5px 5px;
    border-radius: 0px 5px 5px 5px;
    z-index: -1;
}

关于css - 有没有更简单的方法来使用 css 创建这个形状? (包括 jsfiddle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711183/

相关文章:

javascript - 使用javascript导航滚动

html - 为什么我的子选择器 #id > .test 没有效果?

android - 只有一个透明边框的形状

Javascript 切换现有形状的形状

简单平方的算法

php - 使用 PHP 文件扩展名编写动态 CSS 样式表是否效率较低?

html - 将 1/4 添加到 Twitter Bootstrap 列

css - 渲染的 PDF 在生产环境中看起来不同 - Rails、PDFKit、wkhtmltopdf

wpf - 轻量级可模板 WPF 形状

java - 使用行、列和字符的输入创建形状以填充形状时出现问题