有辦法讓這些圖像變小嗎?裝進一個盒子里?我按照一個教程,圖像更大。這是縮小到25%的看法。我在尋找一種方法來調整圖像的大小,以適應類似畫廊的視圖,在教程中,這個人最終得到了一個完美的畫廊類型的輸出,不像我xd。這是一個django項目,提前感謝:)
html代碼:
{% extends 'portofolio/base.html' %}
{% load static %}
{% block content %}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.8.2/css/lightbox.min.css">
<link rel="stylesheet" href="{% static "portofolio/css/photogallery.css" %}">
<body>
<h1 style="margin-top: 70px;">Image Gallery</h1>
<div id="jLightroom" class="jlr">
<a href="{% static "portofolio/images/1.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/1.jpg" %}">
</a>
<a href="{% static "portofolio/images/2.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/2.jpg" %}">
</a>
<a href="{% static "portofolio/images/3.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/3.jpg" %}">
</a>
<a href="{% static "portofolio/images/4.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/4.jpg" %}">
</a>
<a href="{% static "portofolio/images/5.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/5.jpg" %}">
</a>
<a href="{% static "portofolio/images/6.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/6.jpg" %}">
</a>
<a href="{% static "portofolio/images/7.jpg" %}" data-lightbox="lb1" class="jlr_item">
<img src="{% static "portofolio/images/7.jpg" %}">
</a>
</div>
</div>
</body>
<script src="{% static 'portofolio/js/jquery.min.js' %}"></script>
<script src="{% static 'portofolio/js/imagesloaded.pkgd.min.js' %}"></script>
<script src="{% static 'portofolio/js/lightbox.min.js' %}"></script>
<script src="{% static 'portofolio/js/jquery.lightroom.js' %}"></script>
<script type="text/javascript">
$("#jLightroom").lightroom({
image_container_selector: ".jlr_item",
img_selector: "img.jlr_img",
img_class_loaded: "jlr_loaded",
img_space: 5,
img_mode: 'min',
init_callback: function (elem) {
$(elem).removeClass("gray_out")
}
}).init();
</script>
{% endblock %}
css代碼:
.jlr {
font-size: 0;
}
.jlr div {
font-size: 1rem;
display: inline-block;
box-sizing: border-box;
padding: 10px;
}
.jlr div img {
height: 100px;
opacity: 0;
}
.jlr img.jlr_loaded {
-webkit-transition: opacity 1s ease-in;
-moz-transition: opacity 1s ease-in;
-o-transition: opacity 1s ease-in;
-ms-transition: opacity 1s ease-in;
transition: opacity 1s ease-in;
opacity: 1;
}
幸運的是,我正在做類似的事情,我使用了grid,它實際上幫助我將圖像放在一個特定的框中的一行中,就像下面的照片一樣,你可以打開代碼下面的鏈接并查看輸出。 圖像的網格框
HTML:
<div class='l-grid'>
<div class='c-project'>
<img src='./images/fulls/01.jpg'>
<div>
<h4>Tower</h4>
</div>
</div>
<div class='c-project'>
<img src='./images/fulls/02.jpg'>
<div>
<h4>Water fall</h4>
</div>
</div>
<div class='c-project'>
<img src='./images/fulls/03.jpg'>
<div>
<h4>River</h4>
</div>
</div>
<div class='c-project'>
<img src='./images/fulls/04.jpg'>
<div>
<h4>Sea</h4>
</div>
</div>
<div class='c-project'>
<img src='./images/fulls/06.jpg'>
<div>
<h4>Beautiful face</h4>
</div>
</div>
</div>
CSS:
.l-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
grid-gap: 0.5rem; /*Here you can control the spacing between the images*/
}
.c-project img {
width: 100%;
}
您可以使用寬度和高度屬性來調整圖像的大小。
<img src="{% static "portofolio/images/7.jpg" %}" width="Your preferred width" height="Your preferred height">
要定位圖像,您可以使用邊距屬性:
<html>
<head>
<title>Test website </title>
</head>
<style>
#test {margin-left: 70px;
margin-top: 80px}
</style>
<body>
<img id="test" src="test image.png"/>
</body>
</html>