2016-09-30 9 views
0

こんにちは私は、CSS、HTML、PHPを使用してWebページを持っています。このコードをご覧ください:HTMLマージントップが動作しないのはなぜですか?

<?php 
    session_start(); 

    include_once "mysql_connect.php"; 
    $log = null; 
    if(isset($_SESSION["ID"])){ 
    $log = $_SESSION["ID"]; 
    }else{ 
    $log=null; 
    } 
     $_SESSION["prevpage"] = "home"; 
     $terms = $_POST["search"]; 
     if($terms == null){ 
      header("location:home"); 
     } 
    ?> 
    <html> 
    <head> 
    <title><?php echo $terms;?></title> 

    <link rel="icon" type="image/png" href="favicon-32x32.png" sizes="32x32" /> 


    <link rel="stylesheet" href="css/reset.css"> 
    <link rel="stylesheet" href="css/text.css"> 
    <link rel="stylesheet" href="css/960_24_col.css"> 
    <link rel="stylesheet" href="css/style.css"> 
    <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW"> 
    <meta name="description" CONTENT="Find everything and anything on Omicrome"> 
    <META NAME="ROBOTS" CONTENT="INDEX, FOLLOW"> 
    </head> 
      <body> 
      <div class = "container_24"> 
      <header> 
      <div id = "rectban"> 
      <h1>Omicrome</h1> 
      <nav> 
      <ul> 
      <li><a href="home">Home</a></li> 
      <li><a href="articles">Articles</a></li> 
      <li><a href="about">About</a></li> 
      <?php if($log != null){?> 
      <li id = "myprofilebanner"><a href="MyProfile">My Profile</a></li> 
      <?php }else{ ?> 
      <li id = "myprofilebanner"><a href="createAccount">Create Account</a>  </li> 
      <?php } ?> 


      <li id = "loginbanner"><a href= <?php if($log != null){?>"logout.php"<?php }else{?>"login"<?php }?>><?php if($log != null){?>Log Out<?php }else{?>Log In <?php }?></a></li> 

      </ul> 
      </nav> 
     </div> 
      <div id = "Postban"> 
      <form action="searchresults.php" method="post" enctype="multipart/form-data"> 
      <input class="searchbar" type="text" name="search" size="30" maxlength = "500" placeholder="Search"/> 
      <input type="submit" class = "searchbtn" value="[&nbsp;&nbsp;Go&nbsp;&nbsp;]" /> 
      <a class="Post" href="post" > 
      [&nbsp;&nbsp;Post&nbsp;&nbsp;] 
      </a> 
      </form>  
     </div>    
    </header> 





     <div class = "main clearfix"> 
     <div id = "rectsearchresults"> 

     <?php 


       $fetchlast = mysql_query("SELECT * FROM posts WHERE id=(SELECT MAX(id) FROM posts)"); 
       $lastrow = mysql_fetch_row($fetchlast); 
       $lastid = $lastrow[6]; 

       for ($i=1; $i <= $lastid; $i++) { 

        $currentname = mysql_query("SELECT * FROM posts WHERE id=$i"); 

        while ($row = mysql_fetch_array($currentname)) { 
         $title = $row[0]; 
         $desc = $row[1]; 
         $ID = $row[6]; 

         $title2 = rtrim($title); 
         $donetitle = str_replace(" ", "-", $title2); 
         $url = "articles/".$ID."/".$donetitle.""; 

         echo "<div id=\"result\"><img src=\"img/tempsmall.png\" alt = \"icon\" > 
           <a id=\"resultheader\" href=\"$url\">$title</a><br> 
           </div>"; 

        } 

       } 
     ?> 

    </div> 
    </div> 







    </div> 
    </div> 

    </body> 

    </html> 

上記のコードはすべて同じページにありますが、いくつかの検索結果を表示する必要があります。 'resultheader'のIDを持つ<a>タグを上下に移動したいと考えています。何らかの理由で余白は残っていますが、余白はありません。私はdisplay:inline-blockを使って試してみました。誰かがなぜそれがうまくいかないか教えてもらえますか? HERESに私のCSSコード:ここで

#rectsearchresults{ 
    position: relative; 
    margin-top: -10px; 
    margin-left: -0px; 
    background: #ffffff; 
    padding-left: 20px; 
    padding-right: 20px; 
    padding-bottom: 20px; 
    padding-top: 20px; 
    width:916px; 

} 
#result{ 
    margin-bottom: 20px; 
} 
#resultheader{ 
    margin-left:10px; 
    color:black; 
    font-size: 15px; 
    margin-top: -20px; 
} 

は私が各結果のヘッダは、画像の上

enter image description here

+1

複数の要素のスタイルを設定する場合はIDを使用しないでください。代わりにクラスを使用してください。 – Phiter

+0

問題を表示するためにコードを孤立させてください....問題のレンダリングされたhtmlとCSSを含めてください。 – DaniP

+2

**最終レンダリングされたHTMLを表示できます** –

答えて

3

<a>(アンカータグ)をインラインになりたいもらうことでをしているものですデフォルトdisplay:inline

'インライン' タイプの要素がありません

1)display: tableを使用してください:

多くのソリューションは、これに存在する負のマージントップを受け入れます。これは、インラインブロックのコンテンツ適合プロパティを持ちますが、負のマージンもサポートします。

#resultheader { 
    margin-left: 60px; //adjust to your likes 
    color: black; 
    font-size: 15px; 
    margin-top: -30px; //adjust to your likes 
    display: table; 
} 

2)お好みを選んでposition: relative & top性質

#resultheader{ 
    margin-left:10px; 
    color:black; 
    font-size: 15px; 
    position: relative; 
    top: -6px; 
} 

を使用vertical-alignプロパティ

#resultheader { 
    margin-left: 10px; 
    color: black; 
    font-size: 15px; 
    vertical-align: 10px; //adjust 
} 

3)を使用します。

関連する問題