简体   繁体   English

以表格/网格格式显示div

[英]Present divs in a tabular / grid format

I'm currently struggling to present a div structure in a certain way. 我目前正在努力以某种方式呈现div结构。 Unfortunately I can only do this via css as our database system outputs the html. 不幸的是我只能通过css这样做,因为我们的数据库系统输出html。 Basically I am trying to present the code below in the format shown in the picture: 基本上我试图以图片中显示的格式显示下面的代码:

<div class="job_classifications">
    <div class="classification x_location">
       <div class="class_type">Location</div>
       <div id="location" class="class_value"> London</div>
    </div>

     <div class="classification refno">
       <div class="class_type">Ref No</div>
       <div class="class_value">80</div>
    </div>

Class type refers to the darker heading on the left and class_value refers to the content. 类类型指的是左侧较暗的标题,class_value指的是内容。

Do any of you have any recommendations of how to acheive this via css? 你们有没有任何关于如何通过CSS实现这一目标的建议? Any help would be greatly appreciated. 任何帮助将不胜感激。 JQuery and javascript can be used to append classes where necessary if required. 如果需要,可以使用JQuery和javascript在必要时附加类。

在此输入图像描述

http://jsfiddle.net/NVDjU/ http://jsfiddle.net/NVDjU/

Using your uploaded image as an example, this method uses floats and arbitrary widths that you can change, but may do the trick. 以上传的图像为例,此方法使用可以更改的浮点数和任意宽度,但可以实现。

.job_classifications {
    width: 420px;
    font-size: 11px;
    font-family: Arial;
}

.classification {
    float: left;
}

.classification .class_type {
    font-weight: bold;
    width: 80px;
    float: left;
}

.classification .class_value {
    float: left;
    margin: 0 10px 0 0;
    width: 100px;
}   

The above being said, in the likely event that you're stuck with the markup they give you, you could use display:table*, though you'll have to be careful of old browsers if you have to support before IE8. 上面说的是,在你可能使用它们给你的标记的情况下,你可以使用display:table *,但如果你必须在IE8之前支持那么你必须小心旧的浏览器。

Given: 鉴于:

<div class="job_classifications">
    <div class="classification x_location">
       <div class="class_type">Location</div>
       <div id="location" class="class_value"> London</div>
    </div>

     <div class="classification refno">
       <div class="class_type">Ref No</div>
       <div class="class_value">80</div>
    </div>
</div>​​​​​​​​​

You could use css like this: 你可以像这样使用css:

.job_classifications {
    display:table;
    border: 1px solid green;
}

.classification, .class_type, .class_value {
    display:table-cell;
    border: 1px solid blue;
}    

Obviously, the border styles are there just to illustrate the point... 显然,边框样式只是为了说明这一点......

Read up on display: table, see if that gets you where you need to be. 阅读显示:表格,看看是否能满足您的需求。 http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/ http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/

(Example jsFiddle: http://jsfiddle.net/mori57/SguEb/ ) (示例jsFiddle: http//jsfiddle.net/mori57/SguEb/

The best I can think of is something like this: 我能想到的最好的是这样的:

​.class_type{
float:left​;
font-weight:bold;
background-color:#DDD;
width:125px;
}
.class_value{
float:left;
background-color:#FFF;
width:125px;
}
.job_classifications{width:250px;}

http://jsfiddle.net/calder12/G29nU/ http://jsfiddle.net/calder12/G29nU/

There are obviously inherit issues here since it's based on forcing the floats to break a line with set widths, which is a crap way to do it but I can't think of another way. 这里显然存在继承问题,因为它基于强制浮点数以设置宽度打破一条线,这是一种废话方式,但我不能想到另一种方式。

  • First you're only going to get one column if all that data is inside the job_classifications div as it looks like it is. 首先,如果所有数据都在job_classifications div中,那么你只会获得一列,因为它看起来像是。
  • If you ever have data overrun the fixed width this layout cuts it off. 如果您的数据超出固定宽度,则此布局会将其切断。

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

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