php 如何回显 div 类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12557653/
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-25 03:48:20  来源:igfitidea点击:

How to echo a div class?

phpclasshtmlecho

提问by user1636968

Not sure how to do this... I'm a bit of a php noob. I'm trying to echo the div class '.header1'

不知道如何做到这一点...林有点PHP菜鸟。我试图回应 div 类“.header1”

In my css I've given .header1 a background image and I want that to appear, but I'm not having any luck so my code must be wrong. Here it is:

在我的 css 中,我给了 .header1 一个背景图像,我希望它出现,但我没有任何运气,所以我的代码一定是错误的。这里是:

echo '<div class="header1">';

.header1 {
background: url(_images/header1.png);

What am I doing wrong? I've tried it with and without the closing div but neither have worked.

我究竟做错了什么?我已经尝试过使用和不使用关闭 div 但都没有奏效。

回答by Gung Foo

The div tag needs both an ending tag and content.

div 标签需要结束标签和内容

If there is no content, you need to define it's heightand widthmanually.

如果没有内容,你需要定义它heightwidth手动。

回答by Baba

A. You echois working .. you are probably not seeing anything because its an HTML tag try

A. 您echo正在工作 .. 您可能没有看到任何东西,因为它是一个 HTML 标签

<?php
    echo '<div class="header1">Hello</div>';
?>

B. You should try and make sure you set PHP open tag <?phpand close tag ?>as demostrated above

B. 您应该尝试确保按照上面演示的方式设置 PHP 打开标记<?php和关闭标记?>

回答by noel

Whenever I echo html in php I like to use the heredoc syntax

每当我在 php 中回显 html 我喜欢使用heredoc 语法

$div = <<<DIV
    <div class="header1"></div>
DIV;

Just looks somuch better, to me, especially when your strings get more complex, i.e. quotes and stuff.

只是看起来那么好很多,对我来说,尤其是当你的字符串变得越来越复杂,即报价之类的东西。