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>
Related
I need to center images side by side (warp) & also be able to change images on hover, seems like I can't do both at the same time.
Here is what is have tried:
The first part is the centering part; it works.
The 3rd part is the hover part; that works too but only if justified to the left
and the 2nd part is both and it gets crazy when I hover over.
a img:last-child {
display: none;
}
a:hover img:last-child {
display: block;
}
a:hover img:first-child {
display: none;
}
.fblogo {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: 200px;
}
#images{ text-align: center; }
#images2{ text-align: center; }
<div id="images">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" />
</div>
<div id="images2">
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" />
</a>
<a href="https://www.facebook.com/OlympiaHaacht">
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" />
<img class="fblogo" border="0" alt="Facebook" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" />
</a>
</div>
<div id="images3">
<a href="https://cs13498732.churchspring.org/get-involved/calvary-kids/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" alt="" style="float: left; margin: auto;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" alt="" style="background-color: initial; float: left; margin: auto;">
</a>
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
</a>
</div>
This is a simple solution which uses a Flexbox to centre the content automatically
HTML
<div class="flex justify-center">
<div>
<a href="https://cs13498732.churchspring.org/get-involved/calvary-kids/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141420_2072_Artboard-55.png" alt="" style="float: left; margin: auto;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141416_2072_Artboard-56.png" alt="" style="background-color: initial; float: left; margin: auto;">
</a>
</div>
<div>
<a href="https://cs13498732.churchspring.org/get-involved/breakway/">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141436_2072_Artboard-50.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
<img class="img-responsive" src="https://d1fzhre25nnjsm.cloudfront.net/483141441_2072_Artboard-49.png" alt="" style="float: left; margin: 0px 30px 30px 0px;">
</a>
</div>
</div>
CSS
a img:last-child {
display: none;
}
a:hover img:last-child {
display: block;
}
a:hover img:first-child {
display: none;
}
.fblogo {
height: 200px;
}
.flex {
display:flex;
}
.justify-center {
justify-content: center;
}
View On JSFiddle
https://jsfiddle.net/MrGreyKnight/qmsfj89h/4/
Nice Guide to Flexboxes :)
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
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;
}
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/