如何缩放一些图像以填充区域

时间:2019-05-07 12:32:00

标签: css image mobile flexbox

我正在尝试使用未知数量的图像(最多10个)填充一定固定大小的网页区域,以最大程度地增大图像的大小而不会溢出该区域。为了方便移动,我希望它可以在横向和纵向模式下工作而无需滚动。

我一直在尝试使用flexbox来包装图像,但是然后它们没有缩小并最终导致该区域溢出。如果我使用非包装式柔光箱,则图像将在横向模式下缩放,而不能在纵向模式下缩放。我觉得应该有一个不错的,简单的解决方案。有什么想法吗?

更新:

这是到目前为止我所获得的代码的本质。我一直在尝试很多不同的方法,但这是最干净的方法。

#Add Directory
- name: Add Directory
win_file: 
      path: "{{directory_path}}\AppName-{{env}}"
      state: directory

#Add IUSR to directory path
- name: ADD IUSR
win_acl:
      path: "{{directory_path}}\AppName-{{env}}"
      user: IUSR
      rights: Read
      type: allow
      state: present
      propagation: 'NoPropagateInherit'

#Add website
- name: "{{env}} Add App Name"
win_iis_website:
      name: "AppName-{{env}}"
      state: started
      port: 80
      ip: "{{serverip}}"
      hostname: "appname-{{env}}.com"
      application_pool: "{{application_pool4}}"
      physical_path: "{{directory_path}}\AppName-{{env}}"
register: website
html {
	height: 100%;
}

body {
	padding-top: 0;
	padding-bottom: 0;
	height: 100%;
}

.container {
	height: 100%;
	width: 100%;
	display: flex;
	flex-direction: column;
	flex-wrap: nowrap;
	text-align: center;
}

.above {
	margin-bottom: 20px;
	font-size: larger;
	background-color: lightgrey;
}

.middle {
	flex-grow: 1;
	max-height: 100%;
}

.below {
	margin-top: 20px;
	background-color: lightgrey;
}

img {
	border: 5px solid transparent;
	height: 100%;
}

.images {
	flex-direction: row;
	justify-content: center;
	display: flex;
	flex-wrap: wrap;
	height: 100%;
}

.image {
	margin: 5px;
}

重点是尝试使图像完全保留在称为“中间”的div内,但要尽可能放大。这是一些线框。

风景,有10张图片:

Landscape, 10 images

肖像,10张图像:

Portrait, 10 images

肖像,4张图像

Portrait, 4 images

1 个答案:

答案 0 :(得分:0)

我认为您需要在此处考虑flex属性,它是flex-growflex-shrinkflex-basis属性的简写版本。看看这是否是您想要的。

html,body{
    padding: 0;
    margin: 0;
    width: 100vw;
    box-sizing: border-box;
}
.container{
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
}
.row{
    display: flex;
    width: 100%;
    flex-direction: row;
}
.col{
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.item{
    display: flex;
    max-width: 100%;
    height: 150px;
    background-color: #222;
    margin: 1%;
    flex: 1 1 15%;
}
@media only screen and (max-width: 600px) {
    .item {
        height: 100px;
        flex: 1 1 45%;
        max-width: 100%;
    }
  }
<div class="container">
        <div class="row ">
            <div class="col">
                <h1>some text about images</h1>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
                <div class="item"></div>
            </div>
        </div>
        <div class="row">
            <div class="col">
                <p>Some other elements</p>
            </div>
        </div>
    </div>

相关问题