gpt4 book ai didi

html - 如何使用CSS修复图像定位

转载 作者:太空宇宙 更新时间:2023-11-04 06:07:46 24 4
gpt4 key购买 nike

我正在开发一个网络应用程序,我正在尝试将图像放在左右图像上,如下图所示,但它会移动屏幕尺寸。如何使图像左右固定。

我正在开发一个网络应用程序,我正在尝试将图像放在左右图像上,如下图所示,但它会移动屏幕尺寸。如何使图像左右固定。

enter image description here

   
* {
box-sizing: border-box;
}


ul,
nav {
list-style: none;
}

.pricing * {
margin: 0 auto;
}

section {
align-items: center;
}

.bg-gray{
background: #F2F2F2;
}

.container-fluid{
background: #fff
}


.flex-container-ctrl {
align-items: center;
width: 100%;
z-index: 9;
}

.flex-container {
display: flex;
padding: 1.9em;
max-width: 80%;
position: relative;
z-index: 1;
}

.flex-item {
flex: 1;
width: 0;
}

.flex-item:not(:last-child) {
margin-right: 1.5em;
width: 90%;
}

.package {
border: 1px solid #eee;
list-style-type: none;
margin: 0;
padding: 0;
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2);
transition: 0.25s;
border-radius: 12px;
}

/* .package:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2);
transform: scale(1.025);
} */

.package .header {
color: #fff;
font-size: 1.5em;
height: 124px;
}

.package .highlight {
background-color: #29b6f6;
border-radius: 12px 12px 0 0;
}

.package .heading:nth-of-type(1):before {
content: "Best Plan";
display: block;
padding: 5px 0;
background: #ffb100;
box-shadow: 0 1px 0 #c18705;
color: #fff;
border-radius: 25px;
width: 10%;
margin: -45px 70px;
position: absolute;
/* top: 1px; */
font-size: large;
transition: all 0.5s ease;
box-sizing: border-box;
letter-spacing: 0.13em;
}

.package .pricing-title {
float: left;
height: 10px;
font-size: 17px;
font-weight: bold;
}

.pricing-title .sub-pricing-title {
font-size: 10px;
}

.pricing hr {
margin: 1.5rem 0;
}

.pricing-title img{
width: 19px;
height: auto;
}

.package .ctrl-pricing {
float: right;
height: 10px;
}

.ctrl-pricing .sub-pricing-title {
font-size: 10px;
}

.package li {
background-color: #fff;
/* border-bottom: 1px solid #eee; */
padding: 1.2em;
text-align: center;
height: 20px;
}

.package .gray {
/* background-color: #eee; */
font-size: 1.25em;
border-radius: 0 0 12px 12px;
height: inherit;
padding: 1.6em;
}

button {
background: #015496;
border: none;
border-radius: 25px;
color: #fff;
cursor: pointer;
padding: 0.51em 1.5em;
font-size: 16px;
font-weight: bold;
z-index: 99;
}
.font-clr {
color: #29b6f6;
}

.flower-right{
width: 34em;
height: 48em;
right: 0em;
bottom: 2px;
background: url(https://i.imgur.com/ScMV83t.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position:relative;
z-index: 0;
top: -2px
}

#rightflower{
background-position: 10px;
}

.flower-left{
width: 34em;
height: 51em;
left: -9em;
background: url(https://i.imgur.com/ttgZVYr.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
z-index: 0;
top: 15em;
float: left;
}

#leftflower{
background-position: 10px;
}

@media only screen and (max-width: 800px) {
button {
padding: -0.25em;
}
.flex-container {
flex-wrap: wrap;
}
.payment-method{
flex-wrap: wrap;
}

.flex-item {
flex: 0 0 100%;
margin-bottom: 1em;
width: 100%;
padding-bottom: 20px
}
.flower-left,.flower-right{
display: none;
}
.max-width{
max-width: 71%;
}

.package .heading:nth-of-type(1):before {
width: 20%;
margin: -39px 9em;
}
}

@media only screen and (max-width: 700px) {
.flex-container {
flex-wrap: wrap;
}

.flex-item {
flex: 0 0 100%;
margin-bottom: 1em;
width: 100%;
}

.package:hover {
box-shadow: none;
transform: none;
}

button {
padding: -0.25em 1.5em;
}

.package .heading:nth-of-type(1):before {
width: 20%;
margin: -39px 6.5em;
}
.ctrl-button{
padding: 2px 5px 0 5px !important;
}
.max-width{
max-width: 75%;
}
}
    <section class="pricing" id="pricing">
<div class="flex-container-ctrl">
<div class="flex-container">
<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title"> &nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>

<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title">&nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>
<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title">&nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>

</div>
</div>
<div class="flower-right" id="rightflower"></div>
<div class="flower-left" id="leftflower"></div>
</section>

https://jsfiddle.net

希望有人能帮我解决我的问题

最佳答案

您应该以这种方式对图像使用 position:absolutetransform 属性。


.flower-right {
width: 34em;
height: 48em;
right: 0;
bottom: 2px;
background: url(https://i.imgur.com/ScMV83t.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
z-index: 0;
top: 50%;
transform: translateY(-50%)
}

#rightflower {
background-position: 10px;
}

.flower-left {
width: 34em;
height: 51em;
left: 0;
background: url(https://i.imgur.com/ttgZVYr.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
z-index: 0;
top: 50%;
transform: translateY(-50%)
}

#leftflower {
background-position: 10px;
}


* {
box-sizing: border-box;
}

ul,
nav {
list-style: none;
}

.pricing * {
margin: 0 auto;
}

section {
align-items: center;
}

.bg-gray {
background: #F2F2F2;
}

.container-fluid {
background: #fff
}

.flex-container-ctrl {
align-items: center;
width: 100%;
z-index: 9;
}

.flex-container {
display: flex;
padding: 1.9em;
max-width: 80%;
position: relative;
z-index: 1;
}

.flex-item {
flex: 1;
width: 0;
}

.flex-item:not(:last-child) {
margin-right: 1.5em;
width: 90%;
}

.package {
border: 1px solid #eee;
list-style-type: none;
margin: 0;
padding: 0;
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2);
transition: 0.25s;
border-radius: 12px;
}


/* .package:hover {
box-shadow: 0 8px 12px 0 rgba(0, 0, 0, 0.2);
transform: scale(1.025);
} */

.package .header {
color: #fff;
font-size: 1.5em;
height: 124px;
}

.package .highlight {
background-color: #29b6f6;
border-radius: 12px 12px 0 0;
}

.package .heading:nth-of-type(1):before {
content: "Best Plan";
display: block;
padding: 5px 0;
background: #ffb100;
box-shadow: 0 1px 0 #c18705;
color: #fff;
border-radius: 25px;
width: 10%;
margin: -45px 70px;
position: absolute;
/* top: 1px; */
font-size: large;
transition: all 0.5s ease;
box-sizing: border-box;
letter-spacing: 0.13em;
}

.package .pricing-title {
float: left;
height: 10px;
font-size: 17px;
font-weight: bold;
}

.pricing-title .sub-pricing-title {
font-size: 10px;
}

.pricing hr {
margin: 1.5rem 0;
}

.pricing-title img {
width: 19px;
height: auto;
}

.package .ctrl-pricing {
float: right;
height: 10px;
}

.ctrl-pricing .sub-pricing-title {
font-size: 10px;
}

.package li {
background-color: #fff;
/* border-bottom: 1px solid #eee; */
padding: 1.2em;
text-align: center;
height: 20px;
}

.package .gray {
/* background-color: #eee; */
font-size: 1.25em;
border-radius: 0 0 12px 12px;
height: inherit;
padding: 1.6em;
}

button {
background: #015496;
border: none;
border-radius: 25px;
color: #fff;
cursor: pointer;
padding: 0.51em 1.5em;
font-size: 16px;
font-weight: bold;
z-index: 99;
}

.font-clr {
color: #29b6f6;
}

.flower-right {
width: 34em;
height: 48em;
right: 0;
bottom: 2px;
background: url(https://i.imgur.com/ScMV83t.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
z-index: 0;
top: 50%;
transform: translateY(-50%)
}

#rightflower {
background-position: 10px;
}

.flower-left {
width: 34em;
height: 51em;
left: 0;
background: url(https://i.imgur.com/ttgZVYr.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: absolute;
z-index: 0;
top: 50%;
transform: translateY(-50%)
}

#leftflower {
background-position: 10px;
}

@media only screen and (max-width: 800px) {
button {
padding: -0.25em;
}
.flex-container {
flex-wrap: wrap;
}
.payment-method {
flex-wrap: wrap;
}
.flex-item {
flex: 0 0 100%;
margin-bottom: 1em;
width: 100%;
padding-bottom: 20px
}
.flower-left,
.flower-right {
display: none;
}
.max-width {
max-width: 71%;
}
.package .heading:nth-of-type(1):before {
width: 20%;
margin: -39px 9em;
}
}

@media only screen and (max-width: 700px) {
.flex-container {
flex-wrap: wrap;
}
.flex-item {
flex: 0 0 100%;
margin-bottom: 1em;
width: 100%;
}
.package:hover {
box-shadow: none;
transform: none;
}
button {
padding: -0.25em 1.5em;
}
.package .heading:nth-of-type(1):before {
width: 20%;
margin: -39px 6.5em;
}
.ctrl-button {
padding: 2px 5px 0 5px !important;
}
.max-width {
max-width: 75%;
}
}
<section class="pricing" id="pricing">
<div class="flex-container-ctrl">
<div class="flex-container">
<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title"> &nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>

<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title">&nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>
<div class="flex-item">
<ul class="package">
<li class="header highlight">
<span class="pricing-title">&nbsp;&nbsp;
<p class="sub-pricing-title "> &nbsp;&nbsp;</p></span><span class="ctrl-pricing"> &nbsp;&nbsp;<p
class="sub-pricing-title "> &nbsp;&nbsp;</p></span>
</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="font-clr"> &nbsp;&nbsp;</li>
<li class="gray">
&nbsp;&nbsp;
</li>
</ul>
</div>

</div>
</div>
<div class="flower-right" id="rightflower"></div>
<div class="flower-left" id="leftflower"></div>
</section>

关于html - 如何使用CSS修复图像定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56696795/

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