html - 具有相同 div 容器的 html 页面
问题描述
我的 html 页面有问题,让我们看看注释代码。事实上,当在代码中使用这个 DIV <div class="player1Container playerContainer">
和 <div class="playerContainer playerContainer">
下面的 DIV 时,第一个 DIV 不起作用。很难解释,让我们看看下面的评论。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>DIV DOES NOT WORK IN THIS CASE</title>
<link href="../style/jquery-ui.css" type="text/css" rel="Stylesheet" />
<link href="../style/main.css" type="text/css" rel="Stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"
type="text/javascript"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-
ui.min.js"></script>
<script src="../js/main.js" type="text/javascript"></script>
</head>
<body>
<form name="matchEditorForm" action="javascript:;" onsubmit="saveEditor();
return false;">
<input type="hidden" name="id" value="<?php echo $match->id; ?>" />
<div class="elemId showId">ID: <?php echo $match->id; ?></div>
<h2 class="showTitle">
<input name="title" value="<?php echo $match->title; ?>"
size="45" />
</h2>
<div class="scoreboardContainer playerContainer">
<img src="/images/overlay_score_180.png" id="myImage" width="200"
height="80" alt="scoreboard" style="float:left;margin:0 10px 0 120px;"
border="3"/>
</div>
<!-- This does not work when with this CSS class -->
<div class="player1Container playerContainer">
<h2>Player 1</h2>
<?php echo
getViewable('views/match_management/player_select.php', array('name' =>
'p1_id', 'selected' => $match->p1_id, 'players' =>
MatchManager::getAllPlayers())); ?>
<div class="score">
Score:
<br />
<input name="p1_match_score" value="<?php echo $match-
>p1_match_score; ?>" size="3" />
<input name="p1_set_score" value="<?php echo $match->p1_set_score; ?>"
size="3" /> <input name="p1_game_score" value="<?php echo $match-
>p1_game_score; ?>" size="3" /> <input name="p1_points_score" value="<?php
echo $match->p1_points_score; ?>" size="3" />
</div>
</div>
<div class="player2Container playerContainer">
<h2>Player 2</h2>
<?php echo
getViewable('views/match_management/player_select.php', array('name' =>
'p2_id', 'selected' => $match->p2_id, 'players' =>
MatchManager::getAllPlayers())); ?>
<div class="score">
Score:
<br />
<input name="p2_match_score" value="<?php echo $match-
>p2_match_score; ?>" size="3" /> <input name="p2_set_score" value="<?php
echo $match->p2_set_score; ?>" size="3" /> <input name="p2_game_score"
value="<?php echo $match->p2_game_score; ?>" size="3" /> <input
name="p2_points_score" value="<?php echo $match->p2_points_score; ?>"
size="3" />
</div>
</div>
<button type="submit" style="border: 3px solid red;"
class="matchSaver">Save</button>
</form>
<button type="button" class="matchDeleter">Delete Match Record</button>
<!-- This works fine -->
<div class="player1Container playerContainer">
<div class="scoreauto">
<button type="button" name="p1s1plus" onclick="p1s1plus();"
style="width:46px;border: 2px solid #7E0219;">+</button>
<button type="button" name="p1s2plus" onclick="p1s2plus();"
</div>
</div>
<!-- -->
<div class="player2Container playerContainer">
<div class="scoreauto">
<button type="button" name="p2s1plus" onclick="p2s1plus();"
style="width:46px;border: 2px solid #7E0219;">+</button>
<button type="button" name="p2s2plus" onclick="p2s2plus();"
</div>
</div>
</body>
<script type="text/javascript">
setInterval(function() {
var myImageElement = document.getElementById('myImage');
myImageElement.src = '/images/overlay_score_180.png?rand=' + Math.random();
}, 2000);
</script>
<!-- increment data -->
<script type="text/javascript">
function p1s1plus () {
$.ajax({
url:"/script/p1s1.php", //the page containing php script
type: "POST",
asynch : true,
data: 'p1s1plus'
});
}
</script>
<script type="text/javascript">
function p1s2plus () {
$.ajax({
url:"/script/p1s2.php",
type: "POST",
asynch : true,
data: 'p1s2plus'
});
}
</script>
the part of CSS code where is probably the problem:
#match_management .matchesEditorContainer .matchesEditor .playerContainer^M
{^M
position: absolute;
width: 250px;^M
}^M
#match_management .matchesEditorContainer .matchesEditor
.scoreboardContainer^M
{^M
position: absolute;^M
width: 200px;^M
}^M
#match_management .matchesEditorContainer .matchesEditor .clayer1Container^M
{^M
top: 160px;^M
left: 10px;^M
}^M
#match_management .matchesEditorContainer .matchesEditor .player2Container^M
{^M
top: 160px;^M
left: 300px;^M
}^M
#match_management .matchesEditorContainer .matchesEditor .playerContainer
h2^M
#match_management .matchesEditorContainer .matchesEditor .playerContainer
h2^M
{^M
border-bottom: 1px solid #ccc;^M
}^M
#match_management .matchesEditorContainer .matchesEditor .playerContainer
.score^M
{^M
margin-top: 15px;^M
font-weight: bold;^M
}^M
#match_management .matchesEditorContainer .matchesEditor .playerContainer
.scoreauto^M
{^M
position: absolute;^M
margin-top: 170px;^M
font-weight: bold;^M
}^M
我认为这是一个 CONTAINER / CSS 问题,但我不知道如何解决它。
你能帮助我吗 ?
解决方案
您已经用clayer1Container
CSS 而不是player1Container
. 您似乎也在这里缺少一些括号:
#match_management .matchesEditorContainer .matchesEditor .playerContainer
h2
#match_management .matchesEditorContainer .matchesEditor .playerContainer
h2
{
border-bottom: 1px solid #ccc;
}
你永远不会关闭这里的第二个按钮player1Container
和player2Container
:
<div class="scoreauto">
<button type="button" name="p1s1plus" onclick="p1s1plus();" style="width:46px;border: 2px solid #7E0219;">+</button>
<button type="button" name="p1s2plus" onclick="p1s2plus();"
</div>
并且脚本应该在 body 或 head 标签中。我假设 CSS 来自main.css
外部样式表,所以我不会说它应该在头部并包含在样式标签中。
推荐阅读
- python - 在什么情况下(如果有的话)手动引发 FileExistsError 是否合适?
- javascript - 我的替换函数适用于数组,但不适用于同样是数组的 HTML 集合。为什么?
- r - 如何让我的操作按钮等到单击以更新文本输出?闪亮的 R
- javascript - 反应原生 BottomTabNavigator 奇怪的动画
- c - 函数不扫描第二个值
- xml - 谷歌搜索控制台对我的第二个 sitemap.xml 说“不支持的文件格式”
- javascript - 提交事件后,如何从控制器函数中的类获取返回值?
- airflow-scheduler - Airflow dag 的日志作为电子邮件的附件/正文
- c++ - 您可以使用带有指定初始值设定项的显式构造函数吗?
- javascript - 浏览器显示 TypeError: Cannot read property 'user' of undefined