<body>
<div id="container">
    <div id="background"></div>
  <div id="dialog">
        <p>Hello there!</p>
    </div>
    <div id="button" onclick="showDialog()">
        <img src="images/images/sceond3.jpg" width="126" height="210" alt=""/>
    </div>
</div>
</body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>

var counter = 0;
function showDialog() {
    if (counter == 0) {
        $("#dialog p").html("Testing Second Line!");
    }
    if (counter == 1) {
        $("#dialog p").html("Testing Third Line!");
    }
    //increase counter by 1
    counter++;
}

</script>
</html>


body {
    line-height:0;
}

#container {
    float: left;
    height: 630px;
    width: 1155px;
}

#background {
    background-image: url(images/images/second1.jpg);
    float: left;
    height: 420px;
    width: 1155px;
}

#dialog {
    background-image: url(images/images/second2.jpg);
    z-index: 100;
    float: left;
    height: 210px;
    width: 1029px;
    left: 70px;
    top: 618px;
    font-size:25px;
}


您好,我在HTML代码中对齐和移动文本时遇到问题。基本上,我的对话框div中有一些文本,但是,无论我对CSS中的该div做什么,该文本似乎都不想移动或执行任何操作。

我将不胜感激。谢谢。

最佳答案

对话框div是文本的容器。如果要在“ p”标签中的容器内对齐文本本身,则需要将CSS应用于“ #dialog p”。这将使您在对话框div中居中。然后,您可以根据需要更改对话框div的宽度和位置。

#dialog p {
    text-align: center;
}

10-05 20:49
查看更多