English 中文(简体)
Html/Css - 如何获得图像,使集装箱的100%宽度达到极限,然后展示另一个形象?
原标题:Html/Css - How to get an image to stretch 100% width of a container then display another image over it?

I am struggling with getting the layout of the header i have in mind together.

The html

<div id="header">
    <img src="/img/headerBg.jpg" alt="" class="headerBg" />
    <a href="/"><img src="/img/logo.png" alt="Logo" class="logo" /></a>
    <div id="loginBox">
        other code
    </div>
</div>

至今为止各点:

#header {
    height: 130px;
    margin: 5px 5px 0 5px;
    border: #0f0f12 outset 2px;
    border-radius: 15px;
}

#loginBox {
    float: right;
    width: 23.5%;
    height: 128px;
    font-size: 75%;
}

.headerBg {

}

.logo {
    width: 50%;
    height: 120px;
    float: left;
    display: block;
    padding: 5px;
}

我正试图完成的工作是,“头盔”的形象显示为“头盔”的100%宽度,因此,这从根本上来说将是四舍五入的背景。 然后,图像“logo.png”和div“loginBox”显示在“headerBg.jpg”之上。

标识应移至遥远的终点和标志 盒子的权重于 c。

由于图像被抹去,标识和碎块被正确定位,但当图像被引入时,两个浮标的物品被放在流体图像之后。

我尝试了各种补充和重新配置,但没有人证明我是如何想到的。

我在座标上添加了图像,作为头盔的背景资料,但这样一来不会超过100%。

谁能对此提供某种见解?

此外,任何涉及类似情况的辅导,都将是我的收集工作的重要补充!

谢谢!

最佳回答
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Render this</title>
    <style type="text/css">
#header {
    position:relative;
    height: 130px;
    margin: 5px 5px 0 5px;
    border: #0f0f12 outset 2px;
    border-radius: 15px;
}

#loginBox {
    position:relative;
    float: right;
    width: 23.5%;
    height: 128px;
    font-size: 75%;

}

.headerBg {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: -1;
}

.logo {
    position:relative;
    width: 50%;
    height: 120px;
    float: left;
    display: block;
    padding: 5px;
}
    </style>
</head>
<body>
<div id="header">
    <img src="img/headerBg.jpg" alt="" class="headerBg" />
    <a href="/"><img src="img/logo.png" alt="Logo" class="logo" /></a>
    <div id="loginBox">
        other code
    </div>
</div>

</body>
</html>
问题回答
.header {
    position: relative;
}

.headerBg {
    position: absolute;
    left: 0px;
    right: 0px;
    width: 100%;
}

请注意,这将扩大图像,使之适合<代码><div>的宽度;如果你只想横向地加以改装,那么你就应当明确确定高点。

也可以尝试<条码>至上:100%;。 如果你只想把形象提升到大窗上。

Just make the header background image the true background of that div. Float does not ignore other objects the way that position: absolute does.

#header {
    height: 130px;
    margin: 5px 5px 0 5px;
    border: #0f0f12 outset 2px;
    border-radius: 15px;
    background: url(headerBg.jpg);
}

规定不显示任何额外部分的四分级。

div {
overflow: hidden;
}

这些环境对我来说是完美无缺的,它会为所有制片人提供大小光照。

#headerBg {
position: absolute;
top: 0px;
left: 0px;
right: 0px;
width: 100%;
height: 100%;

}

 <!DOCTYPE html>
            <html>
                <head>
                    <title>W3.CSS</title>
                    <meta name="viewport" content="width=device-width, initial-scale=1">
                    <meta content="text/html; charset=iso-8859-2" http-equiv="Content-Type">
                    <!--link rel="stylesheet" href="#"-->
                    <style>
                        .mySlides {
                            display: none;
                        }

                        .header {
                            background-color: #f1f1f1;
                            padding: 30px;
                            text-align: center;
                            height: 195px;
                            display: flex;
                            align-items: center;
                            align-items: center;
                            justify-content: center;
                        }

                        .img2 {
                            float: center;
                            display: inline-block;
                        }
                    </style>
                    <style type="text/css">
                        .c4 {
                            max-width: 500px
                        }

                        .c3 {
                            width: 100%
                        }

                        .c2 {
                            display: inline-block;
                            text-align: center;
                            width: 100%;
                        }

                        .c1 {
                            max-width: 100%;
                            height: auto;
                        }
                    </style>
                </head>
                <body>
                    <h2 class="c2">Automatic Slideshow</h2>
                    <div id="header" class="c2">
                        <img class="img2 c1" src="./img/16px/avi.png" alt="Pineapple">
                        <h1 class="c2">
                            <a href="#">I want to be</a>
                        </h1>
                        <div class="c4">
                            <img id="carousel" src="" class="c3">
                        </div>
                    </div>
                    <script>
                        //set up things
                        var images = [];
                        images[0] = "./img/16px/avi.png";
                        images[1] = "./img/16px/bmp.png";
                        images[2] = "./img/16px/cpp.png";

                        var n = images.length - 1;
                        var carouselimg = document.getElementById("carousel");
                        var header = document.getElementById("carousel");
                        // preload all images
                        carouselimg.style.display = "none";
                        for (var i = 0; i < n; i++) {
                            carouselimg.src = images[i];
                        }
                        carouselimg.style.display = "block";
                        //prepare first round
                        var carouselIndex = 0;
                        // start show
                        rotate();

                        function rotate() {
                            var dr = header.getBoundingClientRect();
                            carouselimg.style.width = dr.width;
                            carouselimg.src = images[carouselIndex];
                            //index is a global variable

                            //so its state will be kept and we can load the first / next image
                            carouselIndex++;
                            // increment image array  index
                            if (carouselIndex > n) {
                                // do we rech the end
                                carouselIndex = 0
                                // start from begin
                            }
                            setTimeout(rotate, 2000);
                            // restart rotation every 2 seconds
                        }
                    </script>
                </body>
            </html>

在座标上使用:

max-height:100%;




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签