【问题标题】:Coding a customized HTML box编写自定义 HTML 框
【发布时间】:2012-10-23 16:28:38
【问题描述】:

我想用 HTML 编写一个框,就像我在图片中添加的那样,右上角的蓝色框被剪掉了。

我想知道我是否可以这样做,或者是否必须将其作为图像。 请告诉我。

【问题讨论】:

标签: html xhtml


【解决方案1】:

你可以用 css 来做: http://jsfiddle.net/Cqnaa/

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Hello</title>
        <style>
        body{
                margin: 20px;
        }

        .box:after {
                content: "";
                position: absolute;
                top: 0px;
                right: 0px;
                border-width: 20px 20px 0 0;
                border-style: solid;
                border-color: #fff transparent;
                display: block;
                width: 0;
        }

        .box {
                color: #fff;
                background-color: #bbd0ed;
                position: relative;
                height: 80px;
                width: 150px;
                padding: 10px;
        }
        </style>
    </head>
    <body>
        <p class="box">
                Hello!
        </p>
    </body>
</html>

gl 高频

【讨论】:

    【解决方案2】:

    这可以通过 CSS 来完成:

    .box-corner {
       /* You would prefer a png for the transparent background where the corner is */
       background-image: url('box-background.jpg');
       padding: 10px 10px 0 0; /* Assuming the corner is 10x10 */
    }
    

    然后像这样实例化它:

    <div class="box-corner">Content</div>
    

    【讨论】:

      【解决方案3】:

      获取具有一定高度和宽度的 DIV 以及一些背景颜色。然后添加一个带有背景的子 div,因为作物在图像中。将子 div 的位置设置为相对位置,并将 top 和 right 设置为 0。如下所示

        #childDiv{
             position : relative;
             background-image : url("cropedMark.png)"
             width : "Some width";
             height : "Some height";
             top : 0;
             right : 0
        }
      

      希望这会有所帮助。

      【讨论】:

      • 你好。非常感谢。这也有效。但我正在寻找一个我不想有图像的地方。请向下滚动以获得可行的解决方案。
      【解决方案4】:

      这是一个准确的答案。 http://jsfiddle.net/swGvr/

      <style>
      #target {
      border-top: 30px solid transparent;
      border-left: 30px solid #4c4c4c; 
      border-right: 30px solid #4c4c4c; 
      border-bottom: 30px solid #4c4c4c;
      width:200px;
      height:100px;
      }
      #target > div {
      background-color:#4c4c4c;
      width:230px;
      height:130px;
      margin-top:-30px;
      margin-left:-30px;
      position:absolute;
      }
      </style>
      <div id="target"><div></div></div>
      

      有两个 CSS 共享宽度和高度。 您也可以使用 jQuery 自动生成另一个。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-11
        • 2016-03-03
        • 2014-12-09
        • 1970-01-01
        • 1970-01-01
        • 2011-03-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多