drd2551 2016-01-31 19:58
浏览 40
已采纳

在html中对齐文本时遇到问题

Ok I am having trouble aligning text and images within a table and browser in general. I have wrote all the code but I am having trouble in three areas:

  1. The image and text are not aligning right, the desired result should look like the following:

enter image description here

  1. More specifically, I cannot make the area and perimeter underneath each other. I even added the but it is not working.

  2. Within the PHP formulas one of them is not working, I localized it to one formula in particular it is this one that is giving me problems:

$hypo = number_format(sqrt(pow(2 , 10.2) * pow(2 , 5.4), 2);

My entire code is as follows:

<!DOCTYPE html>
<!--
    Author:Randy Gilman
-->
<!--Table one-->
<?php
$cir_area = number_format(M_PI * pow(2 , 2.65), 2);
$cir_circum = number_format(2 * M_PI * 2.65, 2);
$rect_area = 4.2 * 5.6;
$rect_per = (2 * 4.2) + (2 * 5.6);
$tri_area = number_format(5.4 * (10.2/2), 2);
$hypo = number_format(sqrt(pow(2 , 10.2) * pow(2 , 5.4), 2);
$tri_per = number_format(5.4 + 10.2 + $hypo, 2);
$sqr_area = number_format(pow(2 , 5.3), 2);
$sqr_per = number_format(5.3 * 4, 2); 
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title> Randy's Table</title>
    </head>
    <body>
    <table border = "5px">
    <tr>
        <th> Circle
             <IMG SRC="http://www.indezine.com/products/powerpoint/learn/shapes/images/drawingtargetppt2010_02.jpg" ALT="circle" ALIGN=Right style="width:52px;height:52px;border:0;">
         <?php echo "Area = $cir_area square meters";
                   echo "
Circumference = $cir_circum meters"; ?> 
        </th>
        <th> Rectangle 
             <IMG SRC="http://image.tutorvista.com/cms/images/38/rectangle-figure1.jpg" ALT="rectangle" ALIGN=Right style="width:52px;height:52px;border:0;">
         <?php echo "Area = $rect_area square meters";
                   echo "
Perimeter = $rect_per meters"; ?> 
        </th>
    </tr>
    <tr>
        <th> Right Triangle 
             <IMG SRC="http://dasha46.narod.ru/Encyclopedic_Knowledge/Mathematics/Shapes/right_triangle.jpg" ALT="circle" ALIGN=Right style="width:52px;height:52px;border:0;">
         <?php echo "Area = $tri_area square meters";
                   echo "
Perimeter = $tri_per meters"; ?> 
        </th>
        <th> Square 
             <IMG SRC="http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Ski_trail_rating_symbol-blue_square.svg/600px-Ski_trail_rating_symbol-blue_square.svg.png" ALT="square" ALIGN=Right style="width:52px;height:52px;border:0;">
         <?php echo "Area = $sqr_area square meters";
                   echo "
Perimeter = $rect_per meters"; ?> 
        </th>
    </tr>

       </table>
       </body>
<!--End of table one-->
</html>

Additionally, here is what my code produces currently if I remove the $hypo formula:

enter image description here

Any help would be appreciated. Thanks.

  • 写回答

3条回答 默认 最新

  • dongyi8383 2016-01-31 20:18
    关注

    Your formulas are wrong. pow(2, 3) is 2 to the power of 3 which is 8. Here and there you need to compute X * X which is X to the power of 2 i.e. pow(X, 2).

    Even if pow($x, 2) seems to be smarter than $x * $x it is not. It's harder to read and understand and it runs slower because it involves a function call and function calls always take time to be processed.

    The formula of the hypotenuse of a square triangle is sqrt(a*a+b*b). In terms of your code this is:

    $hypo = sqrt(10.2 * 10.2 + 5.4 * 5.4);
    

    As a general recommendation, do not mix the computation of values with their display, not even with the preparations for display. Compute all the values as numbers then use number_format() in the HTML part, just for display.

    Regarding the HTML formatting, read the other answers and/or search the web for HTML line break.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。