php 为 echo 添加样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10850608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 23:13:35  来源:igfitidea点击:

Add style to echo

phpcss

提问by Ma9ic

I want to add a float right style to this php echo

我想为这个 php echo 添加一个浮动正确的样式

<?php echo $PAGE->button; ?>
<?php } ?>

回答by Darek Rossman

In HTML:

在 HTML 中:

<div class="foo">
    <?php echo $PAGE->button; ?>
    <?php } ?>
</div>

And in CSS:

在 CSS 中:

.foo {
    /* some styles here */
}

Or just simply, but not recommended inline styling:

或者只是简单但不推荐的内联样式:

<?php echo "<div style='float: right;'>". $PAGE->button ."</div>"; ?>

回答by Manuel

<?php echo "<div style=\"float:right;\">" . $PAGE->button . "</div>"; ?>
<?php } ?>

This will float the entire button to the right

这将使整个按钮向右浮动

回答by Rukmi Patel

you can not give style to echo function. but you can wrap it in lable or p or any other html tag and give float: right in style.

你不能给 echo 函数赋予风格。但是您可以将其包装在标签或 p 或任何其他 html 标签中,并赋予 float: 风格。

like this,

像这样,

<p style="float: right;"><?php echo $PAGE->button.?></p>

回答by frietkot

Doing it in a cleaner way:

以更清洁的方式进行:

<div style="float: right;"><?php echo $PAGE->button; ?></div>

回答by Lawrence Cherone

You have a couple of options, the preferred method is to define the values for your button within a CSS file:

您有几个选项,首选方法是在 CSS 文件中定义按钮的值:

  • This keeps overhead down as your not loading more bytes on each page load as you can setup your server to cache stylesheets.
  • 这可以降低开销,因为您不会在每个页面加载时加载更多字节,因为您可以设置服务器来缓存样式表。

Or a stylesheet within your head:

或者你头脑中的样式表:

  • This will not save you bandwidth but will keep styling separated from html and keep style's in on place.
  • 这不会节省您的带宽,但会保持样式与 html 分开并保持样式到位。

Or you can use inline styling.

或者您可以使用内联样式。

<style>
.button{
    float:right;
}
</style>

<!--Using the button class from the stylesheet, Notice how many less characters there is-->
<input type="button" value="Button" class="button" name="B3">
<br /> 

<!--Using the same class from the stylesheet, but wrapping the button within a span-->
<span class="button"><input type="button" value="Button" name="B3"></span>
<br /> 

<!--The inline method-->
<span style="float:right"><input type="button" value="Button" name="B3"></span>

回答by Steve

<?php echo "<div style='float: right;'>". $PAGE->button ."</div>"; ?>