I'm working on HTML and CSS and I'm having a hard time aligning the images horizontally instead of vertically.
I tried displaying them inline-block and inline none of them works. And I also want my images to have the same sizes.
Here's my html code:
#gallery {
width: 500px;
overflow: hidden;
position: relative;
z-index: 1;
margin: 100px auto;
display: inline;
}
#gallery img {
width: 50%;
height: auto;
border: 5px solid #FFFFFF;
margin: 10px;
box-sizing: border-box;
margin: 0 auto;
padding: 0;
}
<div id="gallery">
<img src="images/gallery1.png">
<img src="images/gallery2.png">
<img src="images/gallery3.png">
<img src="images/gallery4.png">
<img src="images/gallery5.png">
<img src="images/gallery6.png">
<script src="lightbox2-master/dist/js/lightbox-plus-jquery.js"></script>
</div>
Try this:
div.gallery {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 180px;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
<div class="gallery">
<a href="images/gallery1.png" data-lightbox="image-1" data-title="Ian and Vee">
<img src="images/gallery1.png" width="600" height="400">
</a>
</div>
Simpler answer. Add a float to your image.
#gallery {
width: 500px;
overflow: hidden;
position: relative;
z-index: 1;
margin: 100px auto;
display: inline;
}
#gallery img {
float: left;
width: 50%;
height: auto;
border: 5px solid #FFFFFF;
margin: 10px;
box-sizing: border-box;
margin: 0 auto;
padding: 0;
}
Related
I am creating a gallery with a number of images but the images are viewed in different size and they don't look attractive. I tried to change the height to 100px but all the images are overlapped. I want different sized images to be viewed as same size and also maintain its responsiveness.How can I make them responsive and of same size?
/*
var importantStuff = window.open('', '_blank');
importantStuff.document.write('Loading preview...');
importantStuff.location.href = 'index.html';
*/
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
padding: 20px;
font-family: Arial;
}
.main {
max-width: 1000px;
margin: auto;
}
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
background-color: white;
}
* {
box-sizing: border-box;
}
.responsive {
float: left;
width: 50%;
padding: 5px;
}
#media screen and (max-width: 600px) {
.responsive {
width: 100%;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
<div class="main">
<h1>Image Compression</h1>
<hr>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="1.png">
<img src="1.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:1</h3>
</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="2.png">
<img src="2.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:2</h3>
</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="3.png">
<img src="3.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:3</h3>
</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="4.png">
<img src="4.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:4</h3>
</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="5.png">
<img src="5.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:5</h3>
</div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="6.png">
<img src="6.png" width="600" height="400">
</a>
<div class="desc">
<h3>Image:6</h3>
</div>
</div>
</div>
</div>
One suggestion would be to limit the img size with the a-tag around it. Check my changes for the a- and img-tag in my example:
* {
box-sizing: border-box;
}
body {
background-color: #f1f1f1;
padding: 20px;
font-family: Arial;
}
.main {
max-width: 1000px;
margin: auto;
}
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery a {
display: block;
width: 100%;
overflow: hidden;
height: 100px;
}
div.gallery img {
min-width: 100%;
}
div.desc {
padding: 15px;
text-align: center;
background-color: white;
}
* {
box-sizing: border-box;
}
.responsive {
float: left;
width: 50%;
padding: 5px;
}
#media screen and (max-width: 600px) {
.responsive {
width: 100%;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
<div class="main">
<h1>Image Compression</h1>
<hr>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="1.png">
<img src="https://placehold.it/200x150">
</a>
<div class="desc"><h3>Image:1</h3></div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="2.png">
<img src="https://placehold.it/200x100">
</a>
<div class="desc"><h3>Image:2</h3></div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="3.png">
<img src="https://placehold.it/150x200">
</a>
<div class="desc"><h3>Image:3</h3></div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="4.png">
<img src="https://placehold.it/200x300">
</a>
<div class="desc"><h3>Image:4</h3></div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="5.png">
<img src="https://placehold.it/150x150">
</a>
<div class="desc"><h3>Image:5</h3></div>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="6.png">
<img src="https://placehold.it/200x200">
</a>
<div class="desc"><h3>Image:6</h3></div>
</div>
</div>
</div>
Problem with this solution is, that images are cut of, if the dimensions don't fit.
I am having problems trying to center a div containing four contact images inside of another div. The following is my HTML code for it:
<div id="contact" class="infoSection">
<div id="centeredConctact">
<!--<img class="contactImg" src="images/email.png" alt="Email"></img>-->
<img class="contactImg" src="images/facebook.png" alt="Facebook"></img>
<img class="contactImg" src="images/instagram.png" alt="Instagram"></img>
<img class="contactImg" src="images/twitter.png" alt="Twitter"></img>
<img class="contactImg" src="images/snapchat.png" alt="Snapchat"></img>
</div>
</div>
And the CSS is
div#contact {
border: 1px solid red;
}
div#centeredConctact {
margin: 0 auto;
width: 50%;
}
img.contactImg {
width:50px;
height:50px;
display: inline-block;
margin: 0 auto;
}
div.infoSection {
margin-top: 15px;
padding: 0;
width: 60%;
min-width: 600px;
}
What could I do to fix this? Thank you.
Let me know if this is not what you are trying to achieve. Your question was a little vague but this is what I took from it.
div#contact {
border: 1px solid red;
width: 100%;
}
div#centeredConctact {
text-align: center;
}
img.contactImg {
width: 50px;
height: 50px;
display: inline-block;
margin:4px 1px 1px;
}
a.contactImg {
text-decoration:none;
}
div.infoSection {
margin-top: 15px;
padding: 0;
}
<div id="contact" class="infoSection">
<div id="centeredConctact">
<!--<img class="contactImg" src="images/email.png" alt="Email">-->
<img class="contactImg" src="http://placehold.it/50x50/333333/dddddd&text=F" alt="Facebook">
<img class="contactImg" src="http://placehold.it/50x50/333333/dddddd&text=I" alt="Instagram">
<img class="contactImg" src="http://placehold.it/50x50/333333/dddddd&text=T" alt="Twitter">
<img class="contactImg" src="http://placehold.it/50x50/333333/dddddd&text=S" alt="Snapchat">
</div>
</div>
The div is already centered.
Center the images (respectively the links) with text-algin: center.
div#contact {
border: 1px solid red;
}
div#centeredConctact {
margin: 0 auto;
width: 50%;
border: 1px solid;
text-align: center;
}
img.contactImg {
width: 50px;
height: 50px;
display: inline-block;
}
div.infoSection {
margin-top: 15px;
padding: 0;
width: 60%;
min-width: 600px;
}
<div id="contact" class="infoSection">
<div id="centeredConctact">
<!--<img class="contactImg" src="images/email.png" alt="Email"></img>-->
<a href="" rel="noopener noreferrer"><img class="contactImg" src="images/facebook.png" alt="Facebook">
</a>
<a href="" rel="noopener noreferrer"><img class="contactImg" src="images/instagram.png" alt="Instagram">
</a>
<a href="" rel="noopener noreferrer"><img class="contactImg" src="images/twitter.png" alt="Twitter">
</a>
<a href="" rel="noopener noreferrer"><img class="contactImg" src="images/snapchat.png" alt="Snapchat">
</a>
</div>
</div>
Try using flaxbox layout like this:
div#contact {
border: 1px solid red;
display: flex;
justify-content: center
}
img.contactImg {
width: 50px;
height: 50px;
margin: 3px 1px 0;
}
div.infoSection {
margin-top: 15px;
padding: 0;
width: 60%;
min-width: 600px;
}
<div id="contact" class="infoSection">
<div id="centeredConctact">
<!--<img class="contactImg" src="images/email.png" alt="Email"></img>-->
<img class="contactImg" src="http://placehold.it/50x50" alt="Facebook"></img>
<img class="contactImg" src="http://placehold.it/50x50" alt="Instagram"></img>
<img class="contactImg" src="http://placehold.it/50x50" alt="Twitter"></img>
<img class="contactImg" src="http://placehold.it/50x50" alt="Snapchat"></img>
</div>
</div>
I'm having a problem where divs won't stay on the top of their parent-div if the image they contain doesn't have the same height as the others ones.
In my navbar I have icons of different sizes, I put them in divs on which I use display: flex to verticlly align the icons inside the divs. The divs all have the same height, but if the image of each div isn't identical, a small margin appear above them, as seen in this snippet :
#navbar-right {
position: absolute;
top: 10px;
right: 300px;
margin: 0;
padding: 0;
font-family: 'Comfortaa', cursive;
font-size: 0px;
line-height: 1;
color: #3F3F3F;
border: 1px solid blue;
}
#navbar-right .navbar-menu {
position: relative;
display: inline-flex;
align-items: center;
height: 35px;
border: 1px solid red;
margin: 0;
padding: 0;
}
<div id="navbar-right">
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="24"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="20"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="30"/>
</div>
</a>
</div>
I don't understand why this happens nor how to fix it. Any ideas ?
You have to add display: flex to the container:
#navbar-right {
display: flex;
position: absolute;
top: 10px;
right: 300px;
margin: 0;
padding: 0;
font-family: 'Comfortaa', cursive;
font-size: 0px;
line-height: 1;
color: #3F3F3F;
border: 1px solid blue;
}
#navbar-right .navbar-menu {
position: relative;
display: inline-flex;
align-items: center;
height: 35px;
border: 1px solid red;
margin: 0;
padding: 0;
}
<div id="navbar-right">
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="24"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="20"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="30"/>
</div>
</a>
</div>
It seems that if you add a vertical-align: middle; to the .navbar-menu class, it does the job.
#navbar-right {
position: absolute;
top: 10px;
right: 300px;
margin: 0;
padding: 0;
font-family: 'Comfortaa', cursive;
font-size: 0px;
line-height: 1;
color: #3F3F3F;
border: 1px solid blue;
}
#navbar-right .navbar-menu {
position: relative;
display: inline-flex;
align-items: center;
vertical-align: middle;
height: 35px;
border: 1px solid red;
margin: 0;
padding: 0;
}
<div id="navbar-right">
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="24"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="20"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="30"/>
</div>
</a>
</div>
Remove display:inline-flex from .navbar-menu and add it to main container:
#navbar-right{
display:inline-flex;
}
#navbar-right {
position: absolute;
display:inline-flex;
top: 10px;
right: 300px;
padding: 10px;
font-family: 'Comfortaa', cursive;
border: 1px solid blue;
}
.navbar-menu {
position: relative;
height: 35px;
border: 1px solid red;
}
<div id="navbar-right">
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="24"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="20"/>
</div>
</a>
<a href="#">
<div id="menu-language" class="navbar-menu">
<img src="/core/img/language.png" width="36" height="30"/>
</div>
</a>
</div>
I am trying to align three divs across my page with one always staying center and the others of equal spacing apart. I have what I think is most of the code I need I just cant seem to get the spacing to work.
#Partnerships div {
height: 600px;
width: 100%;
margin-left: 10px;
margin-top: 10px;
Padding: 10px;
float: left;
background-color: #000000;
color:#FFFFFF;
border-radius: 15px 15px 15px 15px;
}
#Robe
{float:left;
width:100px;}
#Avolites
{float:right;
width:100px;}
#UKProductions
{margin:0 auto;
width:100px;}
<div id="Partnerships div">
<div id="Robe">
<h1>Robe</h1>
<p></p>
<a href="http://www.robe.cz/" target="_blank">
<img src="" alt="RobeLogo" height="100" width="200" >
</a>
</div>
<div id="Avolites">
<h1>Avolites</h1>
<p></p>
<a href="" target="_blank">
<img src="" alt="AvolitesLogo" height="100" width="200">
</a>
</div>
<div id="UKProductions">
<h1>UkProductions</h1>
<p></p>
<a href="" target="_blank">
<img src="" alt="UkProductionsLogo" height="100" width="200">
</a>
</div>
You can use this example as a guide for your solution:
Flexbox takes care of the alignment horizontally.
#Partnerships {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
background-color: lightgrey;
}
#Partnerships div {
background-color: cornflowerblue;
width: 300px;
margin: 10px;
}
<div id="Partnerships">
<div id="Robe">
<h1>Robe</h1>
<a href="http://www.robe.cz/" target="_blank">
<img src="" alt="RobeLogo" height="100" width="200" >
</a>
</div>
<div id="Avolites">
<h1>Avolites</h1>
<a href="" target="_blank">
<img src="" alt="AvolitesLogo" height="100" width="200">
</a>
</div>
<div id="UKProductions">
<h1>UkProductions</h1>
<a href="" target="_blank">
<img src="" alt="UkProductionsLogo" height="100" width="200">
</a>
</div>
</div>
Add this to these code:
#Robe, #Avolites {
display: block;
}
#UKProductions {
display: inline-block;
}
#Partnerships {
text-align: center;
}
I'd like to format my tumbnails so that they form one larger square. Currently they're uncentered (which is my first issue), and have spaces between them. How would I go about centering the overall thumbnails, and then making it so that all the thumbnails would touch and form a square?
.links {
margin: auto;
padding: auto;
width: 100%;
}
img {
margin: 0 0 0 0;
padding: auto;
vertical-align: middle;
width: 100px;
}
h2 {
margin: 15% 0 0 0;
padding: 0 0 0 0;
margin-top: 10px;
margin-bottom: 5px;
font-size: 125%;
text-align: center;
}
<h2>Landscapes</h2>
<div id="links">
<a href="img/landscapes/brs.jpg" title="">
<img src="img/thumbnails/brs.jpg" alt="">
</a>
<a href="img/landscapes/ela.jpg" title="">
<img src="img/thumbnails/ela.jpg" alt="">
</a>
<a href="img/landscapes/farm.jpg" title="">
<img src="img/thumbnails/farm.jpg" alt="">
</a>
<a href="img/landscapes/first.jpg" title="">
<img src="img/thumbnails/first.jpg" alt="">
</a>
<a href="img/landscapes/hf.jpg" title="">
<img src="img/thumbnails/hf.jpg" alt="">
</a>
<a href="img/landscapes/lindy.jpg" title="">
<img src="img/thumbnails/lindy.jpg" alt="">
</a>
<a href="img/landscapes/lp.jpg" title="">
<img src="img/thumbnails/lp.jpg" alt="">
</a>
<a href="img/landscapes/mcafee.jpg" title="">
<img src="img/thumbnails/mcafee.jpg" alt="">
</a>
<a href="img/landscapes/meth.jpg" title="">
<img src="img/thumbnails/meth.jpg" alt="">
</a>
<a href="img/landscapes/nr.jpg" title="">
<img src="img/thumbnails/nr.jpg" alt="">
</a>
<a href="img/landscapes/d.jpg" title="">
<img src="img/thumbnails/d.jpg" alt="">
</a>
<a href="img/landscapes/old.jpg" title="">
<img src="img/thumbnails/old.jpg" alt="">
</a>
</div>
Here's an image of what it currently looks like:
The kind of thing I'm going for:
Just add the following and change .links to #links or set class = 'links' instead of id = 'links'
a{
display: inline-block;
margin: 0px -2.5px;
}
Try to
a, img, div{
display: inline-table;
}
.links {
margin: auto;
padding: auto;
width: 100%;
}
img {
margin: 0 0 0 0;
padding: auto;
vertical-align: middle;
width: 100px;
}
h2 {
margin: 15% 0 0 0;
padding: 0 0 0 0;
margin-top: 10px;
margin-bottom: 5px;
font-size: 125%;
text-align: center;
}
a{
display: inline-table;
width: 100px;
}
Fiddle: https://jsfiddle.net/55cdek2r/