【问题标题】:Bottom to top <ul> element arrangement自下而上 <ul> 元素排列
【发布时间】:2012-03-02 16:34:01
【问题描述】:

我正在尝试找出如何强制元素从底部开始到顶部。

我已经通过 stackoverflow 进行了搜索,但我似乎无法得到我需要的答案。 这张图应该能解释清楚:

这也应该有帮助:

<?php require("connectdb.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Dynamic Drag'n Drop</title>
<script type="text/javascript" src="javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="javascript/jquery-ui-1.7.1.custom.min.js"></script>
<script type="text/javascript" src="javascript/jquery.ui.ipad.altfix.js"></script>


<style>
body {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    margin-top: 10px;
}

ul {
    margin: 0;
}

#contentWrap {
    width: 800px;
    margin: 0 auto;
    height: 500px;
    overflow: hidden;
    background-color: #FFFFFF;
    border: solid 2px #EEEEEE;
}

#contentTop {
    width: 600px;
    padding: 10px;
    margin-left: 30px;
}

#sortable { list-style-type: none; margin: 0; padding: 0;}

#sortable li { margin: 20px 20px 1px 20px; 
padding: 1px;
 float: left; 
 width: 70px; 
 height: 70px; 
 font-size: 12px;
 text-align: center; 
 background-color:#cfcfcf;
 position: absoute;
 bottom: 0;
 display: inline-block;
 float: right;
 }


#contentRight {
    float: right;
    width: 300px;
    margin-top: 100px;
    padding:10px;
    background-color:#336600;
    color:#FFFFFF;
}

#save
{    
    width: 100px;
    height: 30px;
    margin-right: auto;
    margin-left: auto;
    background-color:#336600;
    color:#FFFFFF;
    text-align: center;
}
.on { background-color:#000000; color:#782322; }

            #header{
                background-color: #EEEEEE;
                font-weight: bold;
                width: 804px;
                margin-left: auto ;
                margin-right: auto ;
                padding: 2;
            }
</style>


<script type="text/javascript">
//$(document).ready(function(){ 



    $(function() {

    $(document).bind('touchmove', function(e) {
        e.preventDefault();
    }, false);  

        $("#sortable").sortable({ opacity: 0.6, cursor: 'move', update: function()     {
            var order = $(this).sortable("serialize") +     '&action=updateRecordsListings'; 
            $.post("updateDB.php", order, function(theResponse){
            });                                                              
        }                                 
        }).addTouch();
        $( "#sortable" ).disableSelection();

        //$("li").click(function(){
            //$(this).addClass("on");
        //});   
    });

//});   
</script>

</head>
<body>
    <?php 
        session_start();
        $teacherID = $_SESSION['teacherID'];
        $classID = $_SESSION['csID'];
        $qryClass = "SELECT * FROM class_schedule WHERE csID = '". $classID ."';";
        $class = mysql_query($qryClass);
        while($row = mysql_fetch_array($class))
        {
            $subjCode = $row['subjCode'];
            $section = $row['section'];
            $semester = $row['semester'];
            $sy = $row['SY'];
            $time = $row['time'];
        }
    ?>
    <div id = "header">
        <?php 
            //echo "What do you want to do, " .$fname . "?<br>";
            echo "Subject: " . $subjCode . " Block: " . $section . " -     Semester:" . $semester . " - SY:" . $sy . " - " . $time;
        ?>
    </div>
    <div id="contentWrap">
            <ul id="sortable">
                <?php
                session_start();
                $query  = "SELECT e.*, CONCAT(s.lname,', ', s.fname) name     FROM enrollment e, student s
WHERE e.studentID = s.studentID AND e.csID = '". $classID ."' ORDER BY sort;";
                $result = mysql_query($query);
                $c = 0;
                while($row = mysql_fetch_array($result, MYSQL_ASSOC))
                {
                    //if($c != 4)
                        echo "<li id='recordsArray_'"     . $row['id'] . ">" . $row['name'] . "</li>";
                }
                ?>
            </ul>       

    </div>
    <div id="save">
        Blackboard
    </div>


</body>
</html>

【问题讨论】:

  • 这是一个有趣的问题。我很确定这是不可能的。为什么不能以相反的顺序插入元素? (不改变html中的顺序)
  • 您应该始终在问题中包含相关代码。这样,如果您链​​接的文件/页面不复存在,您的问题仍然存在,并且将来可能对其他人有用。
  • 我的错,我在插入代码时遇到了问题。但是,是的,我会记住这一点。谢谢,詹姆斯蒙塔涅。
  • @Oliver 啊,因为我需要元素按那个顺序排列。我正在做的实际上是关于一个班级出勤检查网站。底部是第一行,顶部是第二行。我需要模拟一下,当老师在教室前面检查出勤座位时,他/她会如何看待它。

标签: html css positioning html-lists


【解决方案1】:

一个css解决方案fiddle

ul, ul li {
-webkit-transform: scaleY(-1);
   -moz-transform: scaleY(-1);
    -ms-transform: scaleY(-1);
     -o-transform: scaleY(-1);
        transform: scaleY(-1);

}
ul {
    width: 350px;
}
 li {
    display: inline-block;
    width: 70px;
    zoom: 1;         
    *display: inline;
}

这是通过翻转整个 UL 然后在其 Y 轴上翻转每个 LI 来实现的。

【讨论】:

  • 在我将转换代码添加到 ul 后,我的 li 元素丢失了。当我只将它应用于 LI 时,文本元素会反转:D
  • 哇...有趣,好主意。没有css transformations 的 IE 或旧版浏览器将如何呈现这个?
  • @alpaca Lips nao 嘿兄弟,我似乎已经通过将它应用到持有我的 ul 而不是 ul 的 div 上来实现它!我不知道,但我希望我的问题和这个答案被存档,以便将来其他用户可以使用它。
  • @user1056998:我相信LIfloat: right 而丢失,但我看到您找到了解决方法。如果它适合您,请随意将其标记为答案。谢谢
  • @Maroshii:IE 版本 >9 将忽略 transform 属性并将其呈现为典型的 UL
【解决方案2】:

对于旧版浏览器 (IE7+)

它仍然可以完成,假设一组有限的对象,因为 css 对于更多的行会变得更加复杂(尽管并非不可能)。对于问题中的原始六个对象,see this fiddle。对于 3 行中的 12 个对象see another

注意:我意识到可以使用 :nth-child() 选择器的某些版本,而不是下面的繁琐代码,但是旧浏览器将再次不支持它(这是我在这篇文章中添加答案的重点)。

HTML

<ul>
    <li>a</li>
    <li>b</li>
    <li>c</li>
    <li>d</li>
    <li>e</li>
    <li>f</li>
</ul>

CSS

ul {
    width: 210px;
}

li {
    display: block;
    float: left;
    width: 48px;
    height: 48px;
    margin: 0;
    text-align: center;
    border: 1px solid blue;
}

li:first-child,
li:first-child + li,
li:first-child + li + li,
li:first-child + li + li + li {
    margin: 51px 0 -99px 0;
}

【讨论】:

    【解决方案3】:

    您可以将 $query 更改为以下内容吗?那将是最简单的方法。

    $query  = "SELECT e.*, CONCAT(s.lname,', ', s.fname) name     FROM enrollment e, student s
    WHERE e.studentID = s.studentID AND e.csID = '". $classID ."' ORDER BY sort DESC;";
    

    【讨论】:

    • 很抱歉,但我不这么认为。这只会重新排列框内的值,而不是框的排列。
    猜你喜欢
    • 2013-07-25
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2013-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    相关资源
    最近更新 更多