Adding link to a image breaks everything else - html

So this is a simple line of images, with hover effects, I have it doing everything I need, except when I add a link to open up a new page
so do i need to remake everything and use a different approach or is there a way to somehow fix the issue? Thanks :)
UPDATE!
The code might not be perfect, but I added
.box-1 a {
display:contents:
}
and that solved everything !
.container-1 {
display: inline-flex;
}
.box-1 {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
-webkit-flex: 1 1 auto;
flex: 1 1 auto;
padding: 30px;
text-align: center;
display: inline-block;
position: relative;
}
.box-1:hover img {
filter: blur(3px) brightness(85%);
}
.box-1 img {
width: 100%;
height: 100%;
transition: 0.1s;
}
.box-1 :not(img) {
position: absolute;
top: 30%;
z-index: 1;
color: #fff;
text-align: center;
width: 90%;
opacity: 0;
transition: 0.1s;
letter-spacing: 2px;
}
.box-1 h2 {
top: 50%;
}
.box-1:hover :not(img) {
opacity: 1;
}
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"/></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>

I think you are accidentally making <a> position: absolute. Instead of using :not, why not target the h2 directly .box-1 h2 and also try giving it a width and height

You close img tag in anchor tag
<div class="container-1">
<div class="box-1">
<a href="c1.html" target="_blank">
<img class="candle-image" src="image/candlesp/IMG_0900.jpg"></a>
<h2>Festivity</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0903.jpg" alt="">
<h2>Cinnamon</h2>
</div>
<div class="box-1">
<img src="image/candlesp/IMG_0917.jpg" alt="">
<h2>Forest</h2>
</div>
</div>

Related

How can I fix images in flexbox to wrap 2x2? And correct the hover option?

These are my two flexboxes, one for text and the other for category links. I'm trying to lay the category pictures as 2 by 2. I tried to use row wrap, and center the contents, but it didn't work. I also used various methods using containers, but it always ends up 1 x 4... Also, I'm trying to hover option to fit perfectly into the image, but somehow I have the hover background image not perfectly fit with the image although it's height and width is set to 100%.
How can I solve these issues?
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 800px;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
div.two a > img {
padding: 10px;
margin: 10px;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 200%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: absolute;
top: 30%;
left: 100%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="images/categories/holiday.jpg" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</section>
I've wrapped your boxes with flex container, and change some css regards width of the boxes and their content. Also added width: 100% to your .flex-container.
.flex-container {
display: flex;
justify-content: center;
flex-direction: row;
width: 100%;
}
.flex-container > div {
margin: 10px;
padding: 20px;
font-size: 20px;
text-align: center;
flex-flow: row wrap;
width: 500%;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 1 1 auto;
}
a {
text-decoration: none;
}
h1 {
display: block;
font-size: 1.3em;
margin: 0.67em 0;
font-weight: bold;
}
h2 {
display: block;
font-size: 0.8em;
margin: 0.83em 0;
font-weight: bold;
}
.container {
position: relative;
width: calc(50% - 20px);
margin: 10px;
}
.image {
display: block;
width: 100%;
height: 100%;
min-height: 75px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: darkorchid;
min-height: 75px;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: Black;
font-size: 18px;
position: relative;
text-align: center;
padding: 10px;
}
.images-container{
display: flex;
flex-wrap: wrap;
}
<section>
<div class="flex-container">
<div class="one"> <h1> Welcome to Delicious Book store, <br>
where you can find so many delicious food!</h1>
<p> As a specialized book store, we have many cooking books on
holiday specials, vegetarian, desserts and cultural cuisines!</p>
</div>
<div class="two"> <h2> Shop By Category </h2>
<div class="images-container">
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Holiday</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Dessert</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Vegetarian</div>
</div></a>
</div>
<div class="container">
<a href="category.html">
<img src="https://via.placeholder.com/150" alt="holiday image" class="image">
<div class="overlay">
<div class="text">Cultural Cuisine</div>
</div></a>
</div>
</div>
</div>
</div>
</section>

Flexbox Wrap Not Working On 4 Of My Images

Hello Im not sure why but for some reason flexbox is not working.
I have 4 images on one section. I added flexbox wrap on the container and I also assigned flex 1
on the children images but for some reason flexbox is not working.
If anyone could help and let me know what I am doing wrong I would really appreciate it.
https://codepen.io/rubenjr005/pen/rNexOZp?editors=0100
HTML CODE
<div id="capabilities" class="bg-dark-02 py-2 angle-top-bottom-right">
<div class="capabilities-title">
<h4 class="section-title text-center">CAPABILITIES</h4>
<h3 class="lead text-center">I DO THINGS LIKE</h3>
</div>
<div class="capabilities-container">
<div class="category">
<div class="content">
<img src="img/graphic-design-icon_03.png" alt="Graphic Design" />
<div class="text-animation">
<h3 class="text-center">GRAPHIC DESIGN</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/Web-Design-icon_01.jpg" alt="Web Design" />
<div class="text-animation">
<h3 class="text-center">Web Design</h3>
</div>
</div>
</div>
<div class="category">
<div class="content">
<img src="img/web-development-01.png" alt="web Development" />
<div class="text-animation">
<h3 class="text-center">Web Development</h3>
</div>
</div>
</div>
<div class="category category4">
<div class="content">
<img src="img/email-development.png" alt="Email Development" />
<div class="text-animation">
<h3 class="text-center">Email Development</h3>
</div>
</div>
</div>
</div>
</div>
SCSS
#capabilities {
height: 100%;
margin-bottom: 4.5rem;
.capabilities-container {
display: flex;
flex-wrap: wrap;
// min-width: 20%;
.category {
display: flex;
// flex-direction: column;
flex: 1;
padding: 1rem;
align-items: center;
justify-content: center;
min-width: 10rem;
// width: 10rem;
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
img {
position: absolute;
top: 30%;
height: 12rem;
width: auto;
display: block;
// margin: auto;
margin-bottom: 4rem;
opacity: 0.4;
transition: 0.75s;
// padding-bottom: 4rem;
}
.text-animation {
// position: absolute;
text-align: center;
padding-top: 15rem;
transition-duration: 0.75s;
text-align: center;
left: 0;
right: 0;
// background: red;
// margin: auto;
h3 {
color: white;
text-transform: uppercase;
// margin: auto;
}
}
}
}
.category:hover .content img {
opacity: 1;
margin-bottom: 1rem;
// padding-bottom: 0rem;
// padding-bottom: 0rem;
}
.category:hover .content .text-animation {
// opacity: 1.0;
padding-top: 10rem;
}
}
}
You have to get rid of absolute positioning on your img and you'll have to use media queries.
Starting from there, you'll see the flex-wrap: wrap working.
Here is a fork : https://codepen.io/hisato/pen/vYGLLNY?editors=0100
Also, if I may add, as a general advice avoid to transition margin/padding/top/left etc. You should always look for a way to transition the transform property, it will have the best performance.

CSS Elements in columns are under the upper border while scale transforming

I have 4 columns of images using column-count and I want them to scale on mouse hover.
The first column works fine but the next three will be under the upper border while transforming.
I tried all kinds of margins and padding and I also tried z-index but it didn't work.
Here's live JSFiddle
Code:
.content{
margin-top: 20px;
background-color: black;
}
.photos img {
margin-bottom: 10px;
vertical-align: middle;
height: auto;
width: 100%;
}
.photos {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
-webkit-column-gap: 10px;
-moz-column-gap: 10px;
column-gap: 10px;
}
li img {
-webkit-transition: 0.2s;
}
li img:hover {
-webkit-transition: .5s;
transform: scale(1.3);
}
<div class="content">
<ul class="photos">
<li>
<img src="https://syndlab.com/files/view/5db9b150252346nbDR1gKP3OYNuwBhXsHJerdToc5I0SMLfk7qlv951730.jpeg">
</li>
<li>
<img src="https://lh3.googleusercontent.com/proxy/t2UjB23Xy8xLCPcwavD_5pqDWQH8wx1tOggm85KZq22oyODukZGZyMDIfGHwIKyZj1U4JeAzn3t5bkgPXcV8pJ60udJ1eQ">
</li>
<li>
<img src="https://images.all-free-download.com/images/graphicthumb/bavarian_landscape_515460.jpg">
</li>
<li>
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</li>
</ul>
</div>
You can switch to flexbox and achieve the same behavior with no problem.
Just adjust you CSS like this:
.photos {
display: flex;
}
li {
width: 25%;
}
Here's a working live Codepen: https://codepen.io/alezuc/pen/jObWjLm
Update:
Ok so if you want to achieve what you post in the comment below I suggest you to move to a pure CSS Mansory approach. Here's the code:
Remove the column management and the list (ul/li) and use divs:
<div class="content">
<div class="item">
<img src="https://placehold.it/600x620.jpg">
</div>
<div class="item">
<img src="https://lh3.googleusercontent.com/proxy/t2UjB23Xy8xLCPcwavD_5pqDWQH8wx1tOggm85KZq22oyODukZGZyMDIfGHwIKyZj1U4JeAzn3t5bkgPXcV8pJ60udJ1eQ">
</div>
<div class="item">
<img src="https://images.all-free-download.com/images/graphicthumb/bavarian_landscape_515460.jpg">
</div>
<div class="item">
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</div>
<div class="item">
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</div>
<div class="item">
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</div>
<div class="item">
<img src="https://images.all-free-download.com/images/graphicthumb/bavarian_landscape_515460.jpg">
</div>
<div class="item">
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</div>
<span class="item break"></span>
<span class="item break"></span>
<span class="item break"></span>
</div>
Here's the CSS Code:
.content {
background-color: black;
display: flex;
flex-flow: column wrap;
align-content: space-between;
/* Your container needs a fixed height, and it
* needs to be taller than your tallest column. */
height: 960px;
/* Optional */
padding: 0;
width: 100%;
margin: 40px auto;
counter-reset: items;
}
.item {
width: 24%;
/* Optional */
position: relative;
margin-bottom: 1%;
}
/* Re-order items into 3 rows */
.item:nth-of-type(4n+1) { order: 1; }
.item:nth-of-type(4n+2) { order: 2; }
.item:nth-of-type(4n+3) { order: 3; }
.item:nth-of-type(4n) { order: 4; }
/* Force new columns */
.break {
flex-basis: 100%;
width: 0;
margin: 0;
content: "";
padding: 0;
}
img {
max-width: 100%;
height: auto;
transition: 0.2s;
}
img:hover {
transition: .5s;
transform: scale(1.12);
}
Here's the working live Codepen: https://codepen.io/alezuc/pen/MWayKaq
And here the reference where I get this kind of approach.
I think the problem with the columns is that the browser is "confused" and thinks the non-first images are more down below.
I found 2 possibilities to make this work, first my favorite: display: flex;
.content{
margin-top: 50px;
background-color: black;
}
.photos img {
margin-bottom: 10px;
vertical-align: middle;
height: auto;
width: 100%;
}
.photos {
padding: 0;
list-style: none;
display: flex;
}
.photos li{
flex-basis: 25%;
padding: 0 5px;
margin: 0;
}
li img {
-webkit-transition: 0.2s;
}
li img:hover {
-webkit-transition: .5s;
transform: scale(1.12);
}
<div class="content">
<ul class="photos">
<li>
<img src="https://syndlab.com/files/view/5db9b150252346nbDR1gKP3OYNuwBhXsHJerdToc5I0SMLfk7qlv951730.jpeg">
</li>
<li>
<img src="https://lh3.googleusercontent.com/proxy/t2UjB23Xy8xLCPcwavD_5pqDWQH8wx1tOggm85KZq22oyODukZGZyMDIfGHwIKyZj1U4JeAzn3t5bkgPXcV8pJ60udJ1eQ">
</li>
<li>
<img src="https://images.all-free-download.com/images/graphicthumb/bavarian_landscape_515460.jpg">
</li>
<li>
<img src="https://cdn-ep19.pressidium.com/wp-content/uploads/2019/08/16-9-original-1.jpg">
</li>
</ul>
</div>
the other possibilities using your column settings are dased around adding position: absolute to .photos img or float: left to .photos.
Edit: I see that Alessio created his answer while I was working on mine and he also uses float. Please accept his answer as the working one if you go with the float solution.

CSS grid issues in IE 11

I have created a masonry style grid in HTML/CSS. To do this I have used the
display:grid properties with 'grid-row' and 'grid-column.'
See attached pen.
This works great in Chrome, Firefox and Edge, not tried on Safari yet, but unfortunately, there are issues when it renders in the IE 11 browser.
Instead of getting a nice grid layout as shown in the attached pen it just displays 4 1x1 columns on top of one another.
Are there any IE specific properties that I can assign to my CSS classes in order to get this to display correctly across all browsers?
#container {
display:inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
text-align:center;
color:#fff;
display:block;
position:relative;
overflow:hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
color:#fff;
position:relative;
overflow:hidden;
}
.c {
grid-column: 2;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.d {
grid-column: 3;
grid-row: 2;
color:#fff;
position:relative;
overflow:hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display:block;
position:relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX A<h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr"><h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr"><h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>
Try to change the CSS from
grid-template-columns: 33% 33% 33%;
To
grid-template-columns: 1fr 1fr 1fr;
Some elements are not properly rendered on IE11 due to their implementation of the standards.
Try adding a -ms- prefix to elements such as display: grid, grid-column and grid-row.
You will probably face the same kind of problems when testing on older versions of Safari (in which case try the -webkit prefix).
I've added some css to make it work in IE. Pay attention to the -ms- prefix added in css. You can also refer to this article which explains how to support css grid in IE.
#container {
display: inline-block;
overflow: hidden; /* clip the excess when child gets bigger than parent */
}
#container img {
display: block;
transition: transform .4s; /* smoother zoom */
}
#container:hover img {
transform: scale(1.3);
transform-origin: 50% 50%;
}
.wrapper {
display: -ms-grid;
display: grid;
grid-gap: 0px;
grid-template-columns: 33% 33% 33%;
-ms-grid-columns: 33% 33% 33%;
grid-template-rows: 400px 400px;
-ms-grid-rows: 400px 400px;
color: #000;
}
.a {
grid-column: 1;
grid-row: 1/3;
-ms-grid-column: 1;
-ms-grid-row-span: 2;
text-align: center;
color: #fff;
display: block;
position: relative;
overflow: hidden;
}
.b {
grid-column: 2 / span 2;
grid-row: 1;
-ms-grid-row:1;
-ms-grid-column-span: 2;
-ms-grid-column:2;
color: #fff;
position: relative;
overflow: hidden;
}
.c {
grid-column: 2;
grid-row: 2;
-ms-grid-column:2;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.d {
grid-column: 3;
grid-row: 2;
-ms-grid-column:3;
-ms-grid-row:2;
color: #fff;
position: relative;
overflow: hidden;
}
.box {
border-radius: 0px;
padding: 10px;
font-size: 150%;
display: block;
position: relative;
}
.ctr {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
.imex-btn {
background-color: #4080fa;
border: none;
color: white;
padding: 10px 30px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin-top: 70px;
cursor: pointer;
font-family: "Century Gothic";
}
.imex-btn:hover {
background-color: #000;
color: #4080fa;
}
<div class="wrapper">
<div class="box a">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x900
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX A</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box b">
<div id="container">
<img id="image" src="https://via.placeholder.com/1200x900/C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white">BOX B</h2>
</div>
VIEW NOW
</div>
</div>
<div class="box c">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX C</h2>
</div>
READ MORE
</div>
</div>
<div class="box d">
<div id="container">
<img id="image" src="https://via.placeholder.com/500x500
C/O https://placeholder.com/">
<div class="ctr">
<h2 class="white" style="text-align:center">BOX D</h2>
</div>
READ MORE
</div>
</div>
</div>

How can I center and left align images?

I am working on an image gallery and want have the image's container be completely centered on the page, but the images are left aligned.
This is my desired output:
However, when I try to do a text-align: center on the container(id: gallery) I am getting the images displayed like this:
I tried following suit with a previous stack overflow question: CSS: Center block, but align contents to the left
and wrap the images in another div then align it with display: inline-block; and text-align: left; but the images just seem to align left on the entire page:
What can I do to accomplish my desired output?
HTML
<div id="gallery">
<div id="images">
<div class="container">
<a href="images/gallery/image1.jpg" data-lightbox="mygallery">
<img src="images/gallery/image1.jpg">
<div class="overlay">
<img src="images/magnify.png">
</div>
</a>
</div>
<div class="container">
<a href="images/gallery/image2.jpg" data-lightbox="mygallery">
<img src="images/gallery/image2.jpg">
<div class="overlay">
<img src="images/magnify.png">
</div>
</a>
</div>
</div>
</div>
CSS
#gallery{
text-align: center;
}
#images{
display: inline-block;
text-align: left;
}
img{
width: 300px;
cursor: pointer;
}
.overlay {
position: absolute;
right: 0;
left: 0;
cursor: pointer;
visibility: hidden;
color: transparent;
top: 0;
bottom: 0;
width: 100%;
height: 100%;
transition: all ease-in .3s;
}
.overlay > img{
height: 50%;
width: 50%;
top: 50%;
visibility: hidden;
left: 50%;
transform: translate(-50%,-50%);
position: absolute;
}
.overlay:hover > img{
visibility: visible;
}
.container {
position: relative;
display: inline-block;
margin: 5px;
}
.container:hover .overlay {
visibility: visible;
opacity: .6;
background: black;
color: white;
}
How about styling the image wrapper .images like
.images {
width:80%;
margin:0 auto;
text-align:left;
}
this works
body{
display: flex;
flex-flow: row nowrap;
justify-content: center;
align-content: center;
align-items: center;
}
section{
height:400px;
width:400px;
background:grey;
}
img {
margin:48px;
}
<section>
<img src="https://telecomputingarchitects.com/media/logo.png" height="24"/>
<img src="https://telecomputingarchitects.com/media/logo.png" height="24"/>
<img src="https://telecomputingarchitects.com/media/logo.png" height="24"/>
<img src="https://telecomputingarchitects.com/media/logo.png" height="24"/>
<img src="https://telecomputingarchitects.com/media/logo.png" height="24"/>
</section>
Give your #gallery div a max-width, text-align: center, and margin:auto, then put your header in another div inside the #gallery, but outside the #images. Then put text-align: left on your #images div.
See example below:
#gallery {
text-align: center;
max-width: 420px;
margin: auto;
}
img {
width: 100px;
cursor: pointer;
}
.container {
display: inline-block;
}
#images {
text-align: left
}
<div id="gallery">
<div id="header">
<h1>Header</h1>
</div>
<div id="images">
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=d42">
<img src="http://thecatapi.com/api/images/get?id=d42">
</a>
</div>
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=21o">
<img src="http://thecatapi.com/api/images/get?id=21o">
</a>
</div>
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=49e">
<img src="http://thecatapi.com/api/images/get?id=49e">
</a>
</div>
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=13v">
<img src="http://thecatapi.com/api/images/get?id=13v">
</a>
</div>
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=6e6">
<img src="http://thecatapi.com/api/images/get?id=6e6">
</a>
</div>
<div class="container">
<a href="http://thecatapi.com/api/images/get?id=4bf">
<img src="http://thecatapi.com/api/images/get?id=4bf">
</a>
</div>
</div>
</div>
HTML
<h2>HEADER</h2>
<div class="container">
<img src=""/>
<img src=""/>
<img src=""/>
<img src=""/>
<img src=""/>
<img src=""/>
</div>
CSS
h2 {
text-align: center;
}
.container {
float: left;
}
img {
border: medium solid black;
width: 200px;
height: 350px;
margin: 5% 2%;
}