gpt4 book ai didi

html - CSS:背景尺寸:覆盖率50%-可以吗?

转载 作者:行者123 更新时间:2023-12-01 07:07:34 28 4
gpt4 key购买 nike

这样的事情可能吗?

.background {
background-size: 50% cover;
}

更新:
希望您现在能更好地理解它。
即使一部分消失,图像也应保持成比例。

.background {
border: 5px solid black;
width: 100%;
min-height: 400px;
background-image: url('http://placehold.it/350x150');
background-repeat: no-repeat;
background-position: top right;
background-size: 50% 100%;
}

.text {
padding: 10px;
width: 48%;
}

.center {
display: block;
text-align: center;
}
<div class='background'>
<div class='text'>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<div class='center'>
<a href='#'>Lorem ipsum</a>
</div>
</div>


干杯

最佳答案

不,你不能

这是background-size属性的formal syntax

<bg-size> = [<length-percentage> | auto | {1,2} | cover | contain
这意味着每当您拥有cover时,您就不会拥有length-percentage(这些|表示OR)

相反,您可以使用background-size: 50% 100%background-size: auto 100%
更新根据更新的问题,您可以使用flexbox实现所需的功能

div {
display: flex
}
div div:last-of-type {
background: url("http://lorempixel.com/400/200/") no-repeat center / cover;
}
div div {
flex: 1
}
<div>
<div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim
qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</div>
<div>
</div>
</div>

关于html - CSS:背景尺寸:覆盖率50%-可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41731679/

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