简体   繁体   English

我该如何解决这个CSS骇客问题?

[英]How should I tackle this css-hack?

I am using Bootstrap3.0 for my site. 我正在为我的网站使用Bootstrap3.0。

My requirement is as:- 我的要求是:-

  1. You open the site 您打开网站
  2. You select Audiotorium 您选择Audiotorium
  3. Based on Auditorium selected, seal layout is drawn using jQuery 根据所选的礼堂,使用jQuery绘制图章布局

Now suppose, you Selected Auditorium-A, it has 25 seats 现在假设您选择了A礼堂,它有25个席位

  • 15 seats in first row 第一排15个座位
  • 7 seats in second row 第二排7个座位
  • 3 seats in third row 第三排3个座位

In CSS, I have given each column in row width of 100px, looking the above layout configuration using jQuery I set a width of 100*15(1500px) to the container. 在CSS中,我给每一列的行宽为100px,使用jQuery查看上述布局配置,然后将容器的宽度设置为100 * 15(1500px)。

HTML HTML

<div class="col-lg-12>
 <ul id="seatsContainer">
 </ul>
</div>

jQuery jQuery的

  $('#seatsContainer').append('<li style='position:absoulte;left:'+colIndex * 100px> SeatNumber</li>');

Since, I am using position:absolute for the child li , I need to set the height & width of the container explicity So I do that. 因为我为子li使用了position:absolute,所以我需要显式设置容器的高度和宽度,所以我要这样做。

$('#seatContainer').css('width',(maxCols*100)+"px");

But it renders as desired on md,lg devices,but when I view the same on xs or sm devices, the overflow width is hidden. 但是它可以在md,lg设备上按需渲染,但是当我在xs或sm设备上查看时,溢出宽度被隐藏了。

My Question is how should a horizontal scrollbar to be rendered in case of smaller resoultion. 我的问题是,在较小的边框尺寸下应如何呈现水平滚动条。

Settings in css CSS中的设置

html,body
{
 overflow:auto;
}

Like the redbus site,if I select the bus,look for seats & if I minimize the screen a horizontal scrollbar comes. 像redbus网站一样,如果我选择公共汽车,请寻找座位;如果我将屏幕最小化,则会出现水平滚动条。

https://www.redbus.in/Booking/SelectBus.aspx?fromCityId=130&toCityId=122&doj=12-Jan-2016&busType=Any&opId=0 https://www.redbus.in/Booking/SelectBus.aspx?fromCityId=130&toCityId=122&doj=12-Jan-2016&busType=Any&opId=0

FYI:- I am using "container-fluid" on the root element 仅供参考:-我在根元素上使用“容器流体”

Here is my JSON:- 这是我的JSON:-

 {
"SeatDetails": [{
    "seatId": 1021,
    "seatNumber": "A1",
    "rowIndex": 1,
    "colIndex": 1
}, {
    "seatId": 1022,
    "seatNumber": "A2",
    "rowIndex": 1,
    "colIndex": 2
}, {
    "seatId": 1023,
    "seatNumber": "A3",
    "rowIndex": 1,
    "colIndex": 3
}, {
    "seatId": 1024,
    "seatNumber": "A4",
    "rowIndex": 1,
    "colIndex": 4
}, {
    "seatId": 1025,
    "seatNumber": "A5",
    "seatPrice": 105,
    "rowIndex": 1,
    "colIndex": 5
}, {
    "seatId": 1026,
    "seatNumber": "B1",
    "rowIndex": 2,
    "colIndex": 1
}, {
    "seatId": 1027,
    "seatNumber": "B2",
    "rowIndex": 2,
    "colIndex": 2
}, {
    "seatId": 1028,
    "seatNumber": "B3",
    "rowIndex": 2,
    "colIndex": 3
}, {
    "seatId": 1029,
    "seatNumber": "B4",
    "rowIndex": 2,
    "colIndex": 4
}, {
    "seatId": 1030,
    "seatNumber": "B5",
    "rowIndex": 2,
    "colIndex": 5
}, {
    "seatId": 1031,
    "seatNumber": "C1",
    "rowIndex": 3,
    "colIndex": 1
}, {
    "seatId": 1051,
    "seatNumber": "C2",
    "rowIndex": 3,
    "colIndex": 2
}, {
    "seatId": 1032,
    "seatNumber": "C3",
    "rowIndex": 3,
    "colIndex": 5
}, {
    "seatId": 1033,
    "seatNumber": "C4",
    "rowIndex": 3,
    "colIndex": 6
}, {
    "seatId": 1034,
    "seatNumber": "C5",
    "rowIndex": 3,
    "colIndex": 8
}]
}

If you're using the bootstrap framework you should use the responsiveness functionality, however, referring to your comments I see you don't want the responsiveness. 如果您使用的是自举框架,则应使用响应功能,但是,参考您的评论,我看到您不希望响应。 In that case, don't use the container or the columns bootstrap provides. 在这种情况下,请勿使用引导程序提供的容器或列。

<div class="seatsWrapper">
    <ul class="seatsContainer r1">
        <li>A1</li>
        <li>A2</li>
        <li>A3</li>
        <li>A4</li>
        <li>A5</li>
        <li>A6</li>
        <li>A7</li>
        <li>A8</li>
        <li>A9</li>
        <li>A10</li>
        <li>A11</li>
        <li>A12</li>
        <li>A13</li>
        <li>A14</li>
        <li>A15</li>
    </ul>       
    <ul class="seatsContainer r2">
        <li>B1</li>
        <li>B2</li>
        <li>B3</li>
        <li>B4</li>
        <li>B5</li>
        <li>B6</li>
        <li>B7</li>
    </ul>
    <ul class="seatsContainer r3">
        <li>C1</li>
        <li>C2</li>
        <li>C3</li>
    </ul>
</div>

And css 和CSS

.seatsWrapper {
    overflow-x: scroll;
    min-width: 1500px;
}
ul.seatsContainer {
    list-style-type: none;
    clear: both;
    overflow-x: none;
}
ul.seatsContainer li {
    float: left;
    width: 100px;
    height: 100px;
}
ul.seatsContainer.r1 {
    color: blue;
}
ul.seatsContainer.r2 {
    color: red;
}
ul.seatsContainer.r3 {
    color: green;
}

I have added the classes .r1 .r2 .r3 to give you an example of better accessing the elements. 我添加了.r1 .r2 .r3类,为您提供了一个更好地访问元素的示例。

UPDATE UPDATE

Based on your JSON add the data like this 根据您的JSON添加这样的数据

var data = JSON.parse('{"SeatDetails": [{ "seatId": 1021, "seatNumber": "A1", "rowIndex": 1, "colIndex": 1 }, { "seatId": 1022, "seatNumber": "A2", "rowIndex": 1, "colIndex": 2 }, { "seatId": 1023, "seatNumber": "A3", "rowIndex": 1, "colIndex": 3 }, { "seatId": 1024, "seatNumber": "A4", "rowIndex": 1, "colIndex": 4 }, { "seatId": 1025, "seatNumber": "A5", "seatPrice": 105, "rowIndex": 1, "colIndex": 5 }, { "seatId": 1026, "seatNumber": "B1", "rowIndex": 2, "colIndex": 1 }, { "seatId": 1027, "seatNumber": "B2", "rowIndex": 2, "colIndex": 2 }, { "seatId": 1028, "seatNumber": "B3", "rowIndex": 2, "colIndex": 3 }, { "seatId": 1029, "seatNumber": "B4", "rowIndex": 2, "colIndex": 4 }, { "seatId": 1030, "seatNumber": "B5", "rowIndex": 2, "colIndex": 5 }, { "seatId": 1031, "seatNumber": "C1", "rowIndex": 3, "colIndex": 1 }, { "seatId": 1051, "seatNumber": "C2", "rowIndex": 3, "colIndex": 2 }, { "seatId": 1032, "seatNumber": "C3", "rowIndex": 3, "colIndex": 5 }, { "seatId": 1033, "seatNumber": "C4", "rowIndex": 3, "colIndex": 6 }, { "seatId": 1034, "seatNumber": "C5", "rowIndex": 3, "colIndex": 8 }] }')

$.each(data.SeatDetails, function(k, v) {
    $('ul.seatsContainer.r'+v.rowIndex).append('<li>'+v.seatNumber+'</li>')
})

In the case of adding data via json array, start with empty ul elements 如果通过json数组添加数据,请从空ul元素开始

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

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