gpt4 book ai didi

html - 完整的背景图像响应式内部 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 09:14:01 27 4
gpt4 key购买 nike

我正在寻找一种方法来使完整的背景图像具有响应性,但使用内部 CSS。我尝试了很多其他代码,但似乎没有任何效果(在 Chrome 和 Firefox 中测试过)。我的断点是 320px、480px、768px、1366px 和 1920px。这就是我在代码方面所拥有的。那么我究竟应该如何标记这些媒体查询以给出相应宽度的背景图像呢?最重要的是,在设计图像时,合适的高度应该是多少?

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Naamloos document</title>
<style>

body {

/* Location of the image */
background-image: url(Version1/dr-muller-landing-page_1920x1080px.png);

/* Image is centered vertically and horizontally at all times */
background-position: center center;

/* Image doesn't repeat */
background-repeat: no-repeat;

/* Makes the image fixed in the viewport so that it doesn't move when
the content height is greater than the image height */
background-attachment: fixed;

/* This is what makes the background image rescale based on its container's size */
background-size: cover;

/* Pick a solid background color that will be displayed while the background image is loading */
background-color: rgb(236,146,189);

/* SHORTHAND CSS NOTATION
* background: url(background-photo.jpg) center center cover no-repeat fixed;
*/
}
<style>
/* Three website */

* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

.photo-grid {
margin: 290px auto;
margin-bottom: 0px;
max-width: 1920px;
text-align: center;
}

.photo-grid li {
display: inline-block;
margin: 15px;
width: 500px;
height: 500px;
text-align: center;
}

.photo-grid img {
display: block;
max-height: 100%;
max-width: 100%;
}

.photo-grid figure {
height: 400px;
overflow: hidden;
position: relative;
width: 400px;
}

.photo-grid figcaption {
background: rgba(0,0,0,0.5);
color: white;
display: table;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
z-index: 100;
}

.photo-grid figcaption p {
display: table-cell;
font-size: 1.5em;
position: relative;
top: -40px;
width: 500px;
vertical-align: middle;
}


.photo-grid li:hover figcaption {
opacity: 1;
}

.photo-grid img {
display: block;
height: 500px;
width: 500px;
-webkit-transition: all 300ms;
-moz-transition: all 300ms;
transition: all 300ms;
max-width: 100%;
}

.photo-grid li:hover img {
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
transform: scale(1.4);
}

.photo-grid figcaption p {
display: table-cell;
color: white;
font-size: 2em;
position: relative;
top: -40px;
width: 500px;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
transition: all 300ms ease-out;
vertical-align: middle;
}

.photo-grid li:hover figcaption p {
-moz-transform: translateY(40px);
-webkit-transform: translateY(40px);
transform: translateY(40px);
}


.photo-grid figcaption {
background: rgba(192,192,192,0.3);
color: white;
display: table;
height: 100%;
left: 0;
opacity: 0;
position: absolute;
right: 0;
top: 0;
-webkit-transition: all 300ms;
-moz-transition: all 300ms;
transition: all 300ms;
-webkit-transition-delay: 100ms;
-moz-transition-delay: 100ms;
transition-delay: 100ms;
z-index: 100;
}

@font-face {font-family:Arial, Helvetica, sans-serif;
src:url(fonts/ITCAvantGardeStd-Demi.otf)
}
div{font-family:Arial, Helvetica, sans-serif;
}
}
</style>
</head>

最佳答案

试试这个 CSS 代码:

html {
background: url(images/BG.jpg) no-repeat center center fixed;
background-size: cover;
}

关于html - 完整的背景图像响应式内部 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41890615/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com