相关疑难解决方法(0)

如何在css中的图像上定位文本

如何将文本居中在css中的图像上?

<div class="image">
    <img src="sample.png"/>
    <div class="text">
       <h2>Some text</h2>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想做类似下面的事情,但我遇到了困难,这是我现在的css

<style>
.image {
   position: relative;
}

h2 {
   position: absolute;
   top: 200px;
   left: 0;
   width: 100%;
   margin: 0 auto;
   width: 300px;
   height: 50px;
}
</style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

当我使用background-image时,我没有得到html2pdf的任何输出:

<style>
#image_container{
    width: 1000px;
    height: 700px;
    background-image:url('switch.png');
}
</style>
<a href="prints.php">Print</a>
<?php ob_start(); ?>
<div id="image_container"></div>
<?php 
$_SESSION['sess'] = ob_get_contents(); 
ob_flush();
?>
Run Code Online (Sandbox Code Playgroud)

这是prints.php:

<?php require_once('html2pdf/html2pdf.class.php'); ?>
<?php
$html2pdf = new HTML2PDF('L', 'A4', 'en');
$html2pdf->writeHTML($_SESSION['sess']);
$html2pdf->Output('random.pdf');
?>
Run Code Online (Sandbox Code Playgroud)

html css

122
推荐指数
4
解决办法
55万
查看次数

标签 统计

css ×1

html ×1