简体   繁体   English

具有圆形边框的多列CSS布局

[英]Multi-column CSS layout with rounded borders

Problem: 问题:

I am trying to create a multi-column CSS layout with borders that look something in line with this picture: 我正在尝试创建一个多列CSS布局,其边框看起来与此图片一致:

在此输入图像描述

Code: 码:

<div style="border-radius:4px; border: 1px solid #ddd;">

        <div style="display:block;float:left;width:50%;">
            <div><b>F&ouml;rfattare:</b> '.$authors.'<br></div>
            <b>Handledare:</b> '.$row['Supervisor'].'<br>
            <b>Examinator:</b> '.$row['Examiner'].'<br>
            <b>Design av studie:</b> '.$design.'
        </div>

        <div style="display:block;float:left;width:50%;">
            <b>Examinationsdatum:</b> '.$row['ExaminationDate'].'<br>
            <b>Niv&aring;:</b> '.$level.' ('.$credits.')<br>
            <b>Kommentar:</b> '.$row['Comments'].'<br>
            <b>&Ouml;vrigt:</b> '.$row['Participants'].' deltagare, '.$row['Reference'].' referenser
        </div>

</div>

The above-mentioned code will produce the following: 上述代码将产生以下内容:

在此输入图像描述

Question: 题:

What needs to be modified so I can get the horizontal and vertical lines to the box? 什么需要修改,以便我可以获得框的水平和垂直线?

You can modify the CSS to look like this: 您可以将CSS修改为如下所示:

.row {
    border: 1px solid #ddd;
    margin-bottom: -1px;
}

.left {
    display: inline-block;
    width: 50%;
    border-right: 1px solid #ddd;
}

.right {
    display: inline-block;
    width: 49%;
    border-left: 1px solid #ddd;
    margin-left: -1px;
}

.top {
    border-top-right-radius: 4px;
    border-top-left-radius: 4px;
}

.bottom {
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 4px;
}

.outerBox {
    margin: 10px;
}​

Then have your markup look like this: 然后让你的标记看起来像这样:

<div class="outerBox">
    <div class="row top">
        <span class="left"><b>F&ouml;rfattare:</b> '.$authors.'</span><span class="right"><b>Examinationsdatum:</b> '.$row['ExaminationDate'].'</span>
    </div>
    <div class="row">
        <span class="left"><b>Handledare:</b> '.$row['Supervisor'].'</span><span class="right"><b>Niv&aring;:</b> '.$level.' ('.$credits.')</span>
    </div>
    <div class="row">
        <span class="left"><b>Examinator:</b> '.$row['Examiner'].'</span><span class="right"><b>Kommentar:</b> '.$row['Comments'].'</span>
    </div>
    <div class="row bottom">
        <span class="left"><b>Design av studie:</b> '.$design.'</span><span class="right"><b>&Ouml;vrigt:</b> '.$row['Participants'].' deltagare, '.$row['Reference'].' referenser</span>
    </div>
</div>

CAVEAT: The formatting will break if you put a space between the span s on an individual line, so don't break them; CAVEAT:如果你在单独一行的span s之间放置一个空格,格式化就会中断,所以不要破坏它们; otherwise, take this solution and work out something that doesn't break =) ​ 否则,采取这个解决方案,并找出一些不会破坏的东西=)

You can see a working example at http://jsfiddle.net/saluce/XhnBE/ 您可以在http://jsfiddle.net/saluce/XhnBE/上看到一个工作示例

EDIT: It seems that mPDF doesn't like inline-block , so change this part of your CSS: 编辑:似乎mPDF不喜欢inline-block ,所以改变你的这部分CSS:

.left {
    display: block;
    float: left;
    width: 50%;
    border-right: 1px solid #ddd;
}

http://jsfiddle.net/saluce/XhnBE/1/ http://jsfiddle.net/saluce/XhnBE/1/

You could use two lists side by side: 您可以并排使用两个列表:

<div style="border-radius:4px; border: 1px solid #ddd;">

    <ul style="display:block;float:left;width:50%;">
        <li><b>F&ouml;rfattare:</b> '.$authors.'</li>
        <li><b>Handledare:</b> '.$row['Supervisor'].'</li>
        <li><b>Examinator:</b> '.$row['Examiner'].'</li>
        <li><b>Design av studie:</b> '.$design.'</li>
    </ul>

    <ul style="display:block;float:left;width:50%;">
        <li><b>Examinationsdatum:</b> '.$row['ExaminationDate'].'</li>
        <li><b>Niv&aring;:</b> '.$level.' ('.$credits.')</li>
        <li><b>Kommentar:</b> '.$row['Comments'].'</li>
        <li><b>&Ouml;vrigt:</b> '.$row['Participants'].' deltagare, '.$row['Reference'].' referenser</li>
    </ul>

</div>

You'll need to add some styles to get rid of the default styles for lists and add you borders to the top, bottom and sides of your li s . 您需要添加一些样式来摆脱列表的默认样式,并将边框添加到li的顶部,底部和侧面。

A down side of this is that you'll have to give your li s fixed heights so the borders line up. 这样做的缺点是,你必须给你的li小号固定高度,所以边界排队。

You have to change your marke-up. 你必须改变你的市场。 You need a table or more boxes to do this. 您需要一个或多个表来执行此操作。 I think tables would be easier to manage... and somehow this is a case tables are for. 我认为表格更容易管理......不知何故,这是一个案例表。 Or you take a bg-image... but I won't recommend this 或者你采取bg图像...但我不会推荐这个

Check this: http://jsfiddle.net/eNEzs/ 检查一下: http//jsfiddle.net/eNEzs/

It's enough to correct your css a little bit and wrapp items in div's. 这足以纠正你的css和div中的物品。

<div style="border-radius:4px; border: 1px solid #ddd; margin: 20px;">

        <div class="block">
            <div><b>F&ouml;rfattare:</b> '.$authors.'</div>
            <div><b>Handledare:</b> '.$row['Supervisor'].'</div>
            <div><b>Examinator:</b> '.$row['Examiner'].'</div>
            <div><b>Design av studie:</b> '.$design.'</div>
        </div>

        <div class="block">
            <div><b>Examinationsdatum:</b> '.$row['ExaminationDate'].'</div>
            <div><b>Niv&aring;:</b> '.$level.' ('.$credits.')</div>
            <div><b>Kommentar:</b> '.$row['Comments'].'</div>
            <div><b>&Ouml;vrigt:</b> '.$row['Participants'].</div>
        </div>
    <div style="clear:both"></div>        
</div>​

CSS CSS

.block {
     display:block;
     float:left;
     width:50%; 
     -moz-box-sizing: border-box;
     -webkit-box-sizing: border-box;
     box-sizing: border-box;
 }
.block:first-child {
     border-right: 1px solid #ddd;
 }
.block div {
     border-bottom: 1px solid #ddd;
 }
.block div:last-child {
     border-bottom: 0px;
}

But I would recommend you to simply change elements to a table or list (ul or ol) . 但我建议你只需将元素更改为表格或列表(ul或ol) Above solution is simply for this particular exmaple. 以上解决方案仅适用于此特定情况。

Wrap each cell in a div instead of using br , and add border-left and border-bottom on the appropriate element. 将每个单元格换行为div而不是使用br ,并在相应的元素上添加border-leftborder-bottom If you still want to use 50% width, then use box-sizing: border-box; 如果你仍想使用50%宽度,那么使用box-sizing: border-box; to keep it from wrapping. 防止包装。

See this jsfiddle for one way to do it , though you should use classes to properly select which elements to apply the different styles to. 看看这个jsfiddle的一种方法 ,尽管你应该使用类来正确选择应用不同样式的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM