Drupal 主题 - 没有尺寸限制的背景图像
我使用 zen 作为基本主题为我的网站制作一个新主题。问题是我希望页眉和页脚的背景图像在我指定高度和宽度之前不会显示。此外,#header 和 #footer 内的 CSS 中指定的高度和宽度必须与原始图像(尺寸较大),否则图像无法正确显示(部分图像被剪切)。是否有一个解决方案(使用 CSS 或 PHP)允许我为页眉和页脚编写 CSS,而没有任何尺寸限制,以便背景图像自我调整?页眉和页脚不包含任何块。 CSS 的一部分如下:-
#header
{
background-image:url(images/header.jpg);
background-repeat:no-repeat;
height:
background-position:center;
}
#footer
{
margin-top:0px;
background-image:url(images/footer.jpg);
height:391px;
background-position:center;
}
#footer-inner
{
text-align:center;
padding:4px 10px 10px 10px;
}
I 'm using zen as the basic theme to make a new theme for my site. The problem is i want background images for header and footer that are not getting displayed until i specify a height and width for them.Moreover, the height and width specified in the CSS inside the #header and #footer have to match the exact dimension of the original images (which are dimensionally large) otherwise the images are not being displayed properly (parts of them get cut). Is there a solution (either using CSS or PHP) that would allow me to write the CSS for the header and footer without any dimensional constraints so that the background images self adjust ? The header and footer contain no blocks. A part of the CSS is as follows :-
#header
{
background-image:url(images/header.jpg);
background-repeat:no-repeat;
height:
background-position:center;
}
#footer
{
margin-top:0px;
background-image:url(images/footer.jpg);
height:391px;
background-position:center;
}
#footer-inner
{
text-align:center;
padding:4px 10px 10px 10px;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望图像自动缩放,则需要为每个图像使用
img
标签,并将宽度/高度设置为 100%。这将自动将它们缩放到与其父容器相同的大小。这意味着如果您希望图像根据浏览器窗口的大小进行缩放,则需要将父容器的宽度/高度设置为百分比,而不是固定的像素宽度/高度。很少有网站会做这种事情,您可能需要重新考虑并使用固定尺寸的图像。
If you want the images to automatically scale, you will need to use an
img
tag for each image, and set the width/height to 100%. That will scale them automatically to be the same size as their parent container. That means if you want the images to scale according to the size of the browser window, you'll need to set the parent container's width/height to be a percentage, and not a fixed pixel width/height.Few sites do that sort of thing, you may want to reconsider and use fixed size images.
CSS 中的背景图像被设计为在它们所在的 div 的背景中显示自己。这意味着 div 的大小决定了您看到的图像的范围。在您的情况下,由于您的标题区域没有内容,#header 具有在layout.css 中设置的默认尺寸。
正如您所发现的,如果您的标题 div 没有内容,则必须将标题的大小显式设置为所需的尺寸,无论是在您最初发布的 CSS 中(推荐),还是使用具有正确尺寸的空块(不推荐)除非在极少数情况下)。
Background images in CSS are designed to display themselves in the background of the div they are placed in. This means that the size of the div determines the extent of the image you see. In your case, since your header region has no content, #header has the default dimensions set in layout.css.
As you have discovered, if your header div has no content, you have to explicitly set the size of your header to your desired dimensions, either in CSS as you originally posted (recommended) or with an empty block with the correct dimensions (not recommended except in rare circumstances).
如果您使用预处理函数,您应该能够根据您选择的图像设置页眉和页脚的类。不过,您必须为不同的类创建 CSS 以匹配图像。
例如:
预处理函数
CSS
希望这会有所帮助。
If you use the preprocess functions, you should be able to set a class for the header and footer based on the images you choose. You will have to create the CSS for the different classes to match the images though.
For example:
Preprocess Function
CSS
Hopefully this helps.