在图像内创建文本

时间:2018-12-17 04:30:58

标签: html css less

我想在图像中添加文字。我尝试遵循w3school中的规则,但未显示令人满意的结果

这是显示的最终结果: Reality Image

下面的代码是所创建的LESS代码:

body {
  background: url("../img/background-blur-5px.jpg") no-repeat top right fixed;
  .container{
    position: relative;
    .img-bg {
      margin: auto auto;
      display: block;
      width: 70%;
      position: relative;
      @media screen and (max-width: 768px){
        display: none;
      }
    }
    .login-box{
      position: absolute;
      text-align: center;
      @media screen and (max-width: 768px){
        background: white;
        width: 90%;
        height: 30em;
        margin: 2em 0;
        padding: 1em;
      }
    }
  }
}

这是创建的HTML代码:

<div class="container">
  <img src="{{url('image/sbopays')}}/login-box.png" class="img-bg">
  <div class="login-box">
    Hello World
  </div>
</div>

这是期望的期望: Ekspektasi

我忘记了什么,以便以后再添加?

3 个答案:

答案 0 :(得分:1)

CSS定位将是您期望的正确解决方案。 根据排名规则,父容器应具有 position:relative ,子标记应具有 position:absolute

现在,您已相对于image标签而不是div标签应用了。 请检查此链接以了解CSS定位方法。 Link

.container{position:relative;}

如有任何疑问,请告诉我。

答案 1 :(得分:0)

如果里面的内容是绝对的,那么容器的位置应该是相对的:

const response = new VoiceResponse();
response.play({
    digits: 'wwww194'
});

答案 2 :(得分:0)

我得到了最终答案。 我的代码是正确的,但是再向前一步,我只需要使用import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; class Point { public float x; public float y; public Point(float x, float y) { this.x = x; this.y = y; } public Point() { } } class DrawingPanel extends JPanel { Random random = new Random(); int clickCount = 0; float pixelSize; float rWidth = 10.0F; float rHeight = 7.5F; float red, green, blue; Point a = new Point(); Point b = new Point(); Point center = new Point(); DrawingPanel() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent click) { clickCount++; if (clickCount == 1) { a.x = fx(click.getX()); a.y = fy(click.getY()); repaint(); } else if (clickCount == 2) { b.x = fx(click.getX()); b.y = fy(click.getY()); repaint(); } } }); } void initgr() { Dimension d = getSize(); int maxX = d.width - 1; int maxY = d.height - 1; pixelSize = Math.max(rWidth / maxX, rHeight / maxY); center.x = maxX / 2; center.y = maxY / 2; } int iX(float x){ return Math.round(center.x + x / pixelSize); } int iY(float y){ return Math.round(center.y - y / pixelSize); } float fx(int x){ return (x - center.x) * pixelSize; } float fy(int y){ return (center.y - y) * pixelSize; } public void paintComponent(Graphics g) { super.paintComponent(g); initgr(); setBackground(Color.white); if (clickCount == 1) { g.setColor(Color.red); g.drawLine(iX(a.x), iY(a.y), iX(a.x), iY(a.y)); } else if (clickCount > 1) { drawTree(g, a, b); } } public void drawTree(Graphics g, Point first, Point second) { double xSquared = Math.pow(second.x - first.x, 2); double ySquared = Math.pow(second.y - first.y, 2); if (Math.sqrt(xSquared + ySquared) < 0.01) { return; } Point u = new Point(second.x - first.x, second.y - first.y); Point d = new Point(first.x - u.y, first.y + u.x); Point c = new Point(d.x + u.x, d.y + u.y); Point e = new Point(d.x + 0.5F * (u.x - u.y), d.y + 0.5F * (u.y + u.x)); Polygon square = new Polygon(); square.addPoint(iX(first.x), iY(first.y)); square.addPoint(iX(second.x), iY(second.y)); square.addPoint(iX(c.x), iY(c.y)); square.addPoint(iX(d.x), iY(d.y)); red = random.nextFloat(); green = random.nextFloat(); blue = random.nextFloat(); g.setColor(new Color(red, green, blue)); g.fillPolygon(square); Polygon triangle = new Polygon(); triangle.addPoint(iX(c.x), iY(c.y)); triangle.addPoint(iX(d.x), iY(d.y)); triangle.addPoint(iX(e.x), iY(e.y)); red = random.nextFloat(); green = random.nextFloat(); blue = random.nextFloat(); g.setColor(new Color(red, green, blue)); g.fillPolygon(triangle); drawTree(g, d, e); // Draw tree left drawTree(g, e, c); // Draw tree right } } public class PythagorasTree extends JFrame { PythagorasTree() { super("Pythagoras Tree"); setSize(800, 800); add("Center", new DrawingPanel()); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { new PythagorasTree(); } } left righttop风格的更多位置:

bottom

最终结果: enter image description here