html - 当图像试图在图像上显示文字时,另一个 div 被切成两半

标签 html css bootstrap-4

我需要一些帮助来解决我遇到的问题。我试图将文本放在图像上用于我的网页。但是,每当我将图像的位置放在相对位置时。我的图像上方的 div 被切成两半。我想注意被切成两半的 div 设置为 position:fixed。我这样做是为了让 div 可以留在页面上,即使我向下滚动。现在如何在不将 div 切成两半的情况下在图像上获取文本。

这是我的 HTML 代码:

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="main.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

        <!-- jQuery library -->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

        <!-- Popper JS -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
        <link href='https://fonts.googleapis.com/css?family=Actor' rel='stylesheet'>
        <!-- Latest compiled JavaScript -->
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title></title>
    </head>
    <body>
        <div class="container-fluid" style="font-family: Actor">
            <div class="row"  style="position: fixed; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); background-color: #FFFFFF; padding: 4px;">
                <div class="col-xs-3">
                     <img src="images/1-OrderUp!!.jpg" alt="OrderUp logo">
                </div>
                <div class="col-xs-2">
                    <p class="text-style-1">OrderUp!!</p>
                </div>
                <div class="col-xs-1" style="height: 100px; background: #511F18; width: 2px; margin-left: 784px;"></div>
                <div class="col-xs-2">`enter code here`
                    <button class="btn btn-danger btn-lg" style="width: 100px">Log in
                        <?php

                        ?>
                    </button>
                </div>
                <div class="col-xs-1" style="height: 100px; background: #511F18; width: 2px;"></div>
                <div class="col-xs-2">
                    <button class="btn btn-danger btn-lg">Sign Up
                        <?php

                        ?>
                    </button>
                </div>
                 <div class="col-xs-1" style="height: 100px; background: #511F18; width: 2px;"></div>
            </div><br>
            <div class="row">
                <div class="col-xs-12" style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19); ">
                    <div class="image">
                        <img src="images/home-1.jpg">
                        <h2>Welcome to OrderUp!!</h2>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>

这是我的 CSS 的样子:

.btn.btn-danger.btn-lg{
    border-radius: 0;
    height: 100px;
}
.text-style-1{
    font-family:Actor;
    font-weight: bold;
    font-size:55px; 
    padding-top:2px; 
    padding-left:20px;  
    color: #511F18";
}

我的页面通常是这样的: enter image description here 如果我像这样更改我的 CSS 文件:

.btn.btn-danger.btn-lg{
    border-radius: 0;
    height: 100px;
}
.text-style-1{
    font-family:Actor;
    font-weight: bold;
    font-size:55px; 
    padding-top:2px; 
    padding-left:20px;  
    color: #511F18";
}
.image { 
   position: relative; 
   width: 100%; /* for IE 6 */
}

h2 { 
   position: absolute; 
   top: 200px; 
   left: 0; 
   width: 100%; 
}

看起来像这样:enter image description here

最佳答案

尝试添加到您的文本 css

h4 {
  position:absloute; /* instead of fixed */
  z-index:999;
  opacity:1;
}
您可以通过在顶部和左侧添加边距来移动它,谢谢。

关于html - 当图像试图在图像上显示文字时,另一个 div 被切成两半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51599011/

相关文章:

Html5 - 在 "content"和相关类之间换行

html - Bootstrap 4 - 粘性页脚 - 动态页脚高度

jquery - 在javascript中计算以克服垂直对齐:middle

javascript - 你如何阻止下拉菜单上升?

html - 汉堡菜单下方几行的链接文本未显示为链接,但在更下方显示良好

javascript - 在连接四板上放置 token 动画

css - Sass/Compass Font Awesome 问题(显示奇怪的字形而不是图标?)

css - 如何在 HTML 中的卡片中添加图片?

html - Bootstrap : Toggler not displaying its content

java - 如何将 WebView 的内容居中?