3

私はここでサンプル投票システムを作成しました:サンプル投票システム

しかし、何度も試みた後、開発者がここであまりにも多くのdivを使用したため、希望どおりのスタイルにすることができませんでした。フォントが大きくなりすぎたり、数字と重なったり、バランスが崩れたりします。

私はそれを次のように見せたい:

投票システムのスタイリング

そしてここに私のコードがあります:

    <!DOCTYPE html>
<head>
<title>Sample Polling System</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".vote").click(function() 
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}  
}); 
}
else
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "down_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
return false;
});
});
</script>

<style type="text/css">
body
{
font-family:'Georgia', Times New Roman, Times, serif;
}
#main
{
height:100px; 
width:800px;
}
a
{
color:#DF3D82;
text-decoration:none;

}
a:hover
{
color:#DF3D82;
text-decoration:underline;

}
.up
{
height:40px; font-size:24px; text-align:center; background-color:gray; margin-bottom:2px;
-moz-border-radius: 6px;-webkit-border-radius: 6px;
}
.up a
{
color:#FFFFFF;
text-decoration:none;

}
.up a:hover
{
color:#FFFFFF;
text-decoration:none;

}
.down
{
height:40px; font-size:24px; text-align:center; background-color:gray; margin-top:2px;
-moz-border-radius: 6px;-webkit-border-radius: 6px;
}

.down a
{
color:#FFFFFF;
text-decoration:none;

}
.down a:hover
{
color:#FFFFFF;
text-decoration:none;

}
.box1
{
float:left; height:80px; width:50px;
}
.box2
{
float:left; width:440px; text-align:left;
margin-left:10px;height:60px;margin-top:10px;
font-size:18px;
}
img
{
border:none;
padding-top:7px;
}
</style>
</head>
<body>
<div align="center">
<h3>Sample Polling System</h3><hr>
<?php
include('config.php');
$sql=mysql_query("SELECT * FROM Messages  LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg=$row['msg'];
$mes_id=$row['mes_id'];
$up=$row['up'];
$down=$row['down'];
?>
<div id="main">
<div class="box1">
<div class='up'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="up"><?php echo $up; ?></a><!--Tried placing here, didn't work--></div>
<div class='down'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="down"><?php echo $down; ?></a></div>
</div><!-- tried to put this box below box2 but still didn't work -->
<div class='box2' ><?php echo $msg; ?></div>
</div><!-- tried atleast 10 permutations and combinations, couldn't get it work-->
<hr>
<?php
}
?>
</div>
</body>
</html>

達成したい効果を得るのを手伝ってください。

ありがとうございました

4

3 に答える 3

2

私はあなたのコードを修正しました:

    <!DOCTYPE html>
<head>
<title>Sample Polling System</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".vote").click(function() 
{
var id = $(this).attr("id");
var name = $(this).attr("name");
var dataString = 'id='+ id ;
var parent = $(this);
if(name=='up')
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "up_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}  
}); 
}
else
{
$(this).fadeIn(200).html('<img src="dot.gif" align="absmiddle">');
$.ajax({
type: "POST",
url: "down_vote.php",
data: dataString,
cache: false,
success: function(html)
{
parent.html(html);
}
});
}
return false;
});
});
</script>

<style type="text/css">
body
{
font-family:'Georgia', Times New Roman, Times, serif;
}
#main
{
width:800px;
overflow:hidden;
}
a
{
color:#DF3D82;
text-decoration:none;

}
a:hover
{
color:#DF3D82;
text-decoration:underline;

}
.up
{
height:40px; font-size:24px; text-align:center; background-color:gray; margin-bottom:2px;
-moz-border-radius: 6px;-webkit-border-radius: 6px; float:left; width:40px; 
}
.up a
{
color:#FFFFFF;
text-decoration:none;

}
.up a:hover
{
color:#FFFFFF;
text-decoration:none;

}
.down
{
height:40px; font-size:24px; text-align:center; background-color:gray; margin-top:2px;
-moz-border-radius: 6px;-webkit-border-radius: 6px; float:left; margin-left:40px; width:40px; 
}

.down a
{
color:#FFFFFF;
text-decoration:none;

}
.down a:hover
{
color:#FFFFFF;
text-decoration:none;

}
.box1
{
float:left; clear:both;
}
.box2
{
float:left; width:440px;  text-align:left;
font-size:18px; 
}
img
{
border:none;
padding-top:7px;
}
</style>
</head>
<body>
<div align="center">
<h3>Sample Polling System</h3><hr>
<?php
include('config.php');
$sql=mysql_query("SELECT * FROM Messages  LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg=$row['msg'];
$mes_id=$row['mes_id'];
$up=$row['up'];
$down=$row['down'];
?>
<div id="main">
<div class='box2' ><?php echo $msg; ?></div>
<div class="box1">
<div class='up'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="up"><?php echo $up; ?></a></div><span style="margin-top:10px; float:left; margin-left:10px;">People Agree to This</span>
<div class='down'><a href="" class="vote" id="<?php echo $mes_id; ?>" name="down"><?php echo $down; ?></a></div><span style=" margin-top:10px; float:left; margin-left:10px;">People Disagree to This</span>
</div><!-- tried to put this box below box2 but still didn't work -->

</div><!-- tried atleast 10 permutations and combinations, couldn't get it work-->
<hr>
<?php
}
?>
</div>
</body>
</html>

http://jsfiddle.net/qCwZd/をチェックしてください

#box2タイトルは上に配置されていたので、aとaを#box1付けて、新しい行に表示できるようにしました。float:left;#box1float:left;clear:both;

span私はすべての灰色のボックスの横に追加しました。最初の人はこれに同意し、他の人はこれに同意しませんfloat:left;。灰色のボックスの横に置くように与えられましたmargin-leftheight一部のプロパティを削除しました。

于 2013-01-26T08:38:15.207 に答える
1

まず、マークアップも変更する必要があります。同じ名前(「main」)の複数の要素IDを使用していますが、これは間違っています。1つのHTMLページに同じIDの要素幅が1つを超えないようにする必要があります。

マークアップの代わりに、次のことを行うことをお勧めします。

<div align="center">
<h3>Sample Polling System</h3><hr>
<div id="main">

 <div class="row">
  <div class="wrapper">
   <div class="item">
    <div class="box1">
     <div class='up'><a href="" class="vote" id="13" name="up">2</a></div>
     <div class='down'><a href="" class="vote" id="13" name="down">0</a></div>
    </div><!--end box1-->
    <div class='box2' >Sachin Tendulkar is GOD</div>
   </div><!--end item-->

  <div class="item">
    <div class="box1">
     <div class='up'><a href="" class="vote" id="13" name="up">2</a></div>
     <div class='down'><a href="" class="vote" id="13" name="down">0</a></div>
    </div><!--end box1-->
    <div class='box2' >Sachin Tendulkar is GOD</div>
   </div><!--end item-->
 </div><!--end wrapper-->
</div><!--end row-->

</div><!--end main-->

そして、あなたのcssは単純に次のようになります。

#main{width:100%;}
.row{width:100%; border-bottom:1px solid black;}
.wrapper{width:800px; margin:0 auto;}
.item{width:400px; float:left;}

ここで実際の例を見ることができます:http://jsfiddle.net/gHmDv/

于 2013-01-26T08:46:35.413 に答える
0

私はここで投票システムを作りました。Stackoverflowの投票から色を取得しました。クリップパスで「アイコン」を作り、三角形にしました。ラジオボタンを使用して、ラベルをnameプロパティに接続しました。三角形をクリックすると、ラジオボタンがアクティブになり、三角形がオレンジ色に変わります。コードは次のとおりです(javascriptコードは省略できます)。

var number = 0;
var count = document.getElementById("voteCounter");

function plusOne() {
  number = 1;
  count.innerHTML = number;
}

function minusOne() {
  number = - 1;
  count.innerHTML = number;
}
* {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
}

#vote {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 50px;
  font-size: 25px;
  color: #6C737B;
}

#upvote {
  background: #BCC0C3;
  height: 50px;
  width: 40px;
  clip-path: polygon(50% 60%, 0% 100%, 100% 100%);
  margin-bottom: 10px;
  cursor: pointer;
}

#downvote {
  background: #BCC0C3;
  height: 50px;
  width: 40px;
  clip-path: polygon(50% 40%, 100% 0%, 0% 0%);
  margin-top: 10px;
  cursor: pointer;
}

input[type="radio"] {
  display: none;
}

input[id="upvoteRadio"]:checked ~ #upvote {
  background: #E5863D;
}

input[id="downvoteRadio"]:checked ~ #downvote {
  background: #E5863D;
}
<div id="vote">
  <input type="radio" id="upvoteRadio" name="vote" value="upvote">
  <label for="upvoteRadio" id="upvote" onclick="plusOne()"></label>
  <p id="voteCounter">0</p>
  <input type="radio" id="downvoteRadio" name="vote">
  <label for="downvoteRadio" id="downvote" onclick="minusOne()"></label>
</div>

于 2021-06-19T18:18:59.177 に答える