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;
}
Related
I have created a landing page for a SharePoint site with graphics. I have noticed that when resizing the browser window to that of something like a tablet or mobile device, the page/graphics aren't responsive and adjusting to the sizing.
I came across a few posts in relation to my issue, but none were very helpful.
Here is my HTML/CSS:
html, body {
margin: 0;
height: 100%;
}
.img_container {
border: none;
width: 70%;
padding: 10px;
height: auto;
display: block;
justify-content: center;
align-items: center;
}
a {
text-decoration: none;
}
a:link, a:visited {
color: #b3ab7d;
}
a:hover {
color: #b3ab7d;
}
.background {
background: #104723;
width: 150px;
height: 150px;
}
.img {
width: 70%;
display: block;
margin: 0 auto;
}
a {
display: block;
text-align: center;
}
.text{
font-size: 70%;
}
*{
box-sizing: border-box;
}
.center {
display: flex;
justify-content: center;
align-items: center;
}
h1{
text-align: center;
color: #104723;
top: -10px;
}
<head>
<h1><strong>G3G Controls</strong></h1>
</head>
<div class="center">
<div class="img_container">
<a href="/ACControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Access Control (AC)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/IAControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Identification & Authentication (IA)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/MPControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Media Protection (MP)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/PEControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Physical Protection (PE)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/SCControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">System & Communications Protection (SC)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/SIControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">System & Information Integrity (SI)</span>
</div>
</a>
</div>
</div>
You have used flexboxes that was enough to make stuff responsive the property you were lacking was setting a flex-wrap:wrap for the .center class which will let the images wrap to the next line as soon as the width of the container element reduces.
AlsoThe .img_container for the images was creating an issue due to its width:70% and it also needs to be set to display:flex which will allow these images to accommodate side by side as you want. I also changed The container element .center width to 100%.
The Proposed Code
html, body {
margin: 0;
height: 100%;
}
.img_container {
display:flex;
border: none;
padding: 10px;
height: auto;
display: block;
justify-content: center;
align-items: center;
}
a {
text-decoration: none;
}
a:link, a:visited {
color: #b3ab7d;
}
a:hover {
color: #b3ab7d;
}
.background {
background: #104723;
width: 150px;
height: 150px;
}
.img {
width: 100%;
display: block;
margin: 0 auto;
}
a {
display: block;
text-align: center;
}
.text{
font-size: 70%;
}
*{
box-sizing: border-box;
}
.center {
width:100%;
display: flex;
justify-content:center;
flex-wrap:wrap;
}
h1{
text-align: center;
color: #104723;
top: -10px;
}
<h1>The Topic</h1>
<div class="center">
<div class="img_container">
<a href="/ACControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Access Control (AC)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/IAControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Identification & Authentication (IA)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/MPControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Media Protection (MP)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/PEControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">Physical Protection (PE)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/SCControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">System & Communications Protection (SC)</span>
</div>
</a>
</div>
<div class="img_container">
<a href="/SIControls.aspx" class="btn">
<div class="background">
<img class="img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Angular_one_color_inverse_logo.svg/1024px-Angular_one_color_inverse_logo.svg.png" alt="logo" />
<span class="text">System & Information Integrity (SI)</span>
</div>
</a>
</div>
</div>
One Important thing - In your code snippet in the HTML you have declared a <h1> heading at the top inside a <head> tag. Pls don't do this <head> tag is always used outside the <body> element that too to declare meta data which doesn't supposed to be visible in the browser. Their are other semantic tags to use inside the <body> element and I think you might have got confused with <header> tag which can be used inside the <body> element.
Do tell me whether I was of any Help :)
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/
There is a white space before the image in the second row. I don’t know why this is happening.
Margin and padding are fine.
All images are of the same size, but there is white space on the second row before the image. 2 more images can fit in there.
Upon inspecting it's just showing white space from the body.
No excess margin or padding is there from any of the images.
Used – "float: left;"
The images on the third row and further are fine.
Can someone figure out the issue, why is this happening?
Click to see image
HTML File:
<!DOCTYPE html>
<html>
<head>
<title>Photo Gallery</title>
<link rel="stylesheet" type="text/css" href="gallery.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,800&display=swap" rel="stylesheet">
</head>
<body>
<p>Photo Gallery</p>
<img src="a (1).jpg">
<img src="a (2).jpg">
<img src="a (3).jpg">
<img src="a (4).jpg">
<img src="a (5).jpg">
<img src="a (6).jpg">
<img src="a (7).jpg">
<img src="a (8).jpg">
<img src="a (9).jpg">
</body>
</html>
CSS File:
img{
width: 30%;
float: left;
margin: 1.66%;
padding: 0;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
This is happening because the images are of different height. The best solution with display block layout will be using a width to the image and setting the display: inline-block
img{
width: 30%;
/* margin: 1.66%; */
padding: 0;
display: inline-block;
vertical-align: middle;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<div class="image-container">
<img src="https://www.w3schools.com/html/img_girl.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
</div
Or else you can go for flex display. This will ensure that the child elemets are of same height, without explicitly mentioning the height.
.image-item {
display: flex;
flex-direction: column;
width: 30%;
margin: 1.66%;
padding: 0;
justify-content: center;
}
img{
width: 100%;
}
.image-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
p {
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width: 30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<div class="image-container">
<div class="image-item">
<img src="https://www.w3schools.com/html/img_girl.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
<div class="image-item">
<img src="https://www.w3schools.com/html/pic_trulli.jpg" />
</div>
</div>
It's the margin property.
img{
width: 30%;
float: left;
margin: 0 1.66%;
padding: 0;
}
p{
font-family: Raleway;
margin-left: 1.66%;
font-size: 30px;
font-weight: 800;
border-bottom: 3px solid #f1f1f1;
width:30%;
padding-bottom: 30px;
}
<p>Photo Gallery</p>
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
<img src="https://www.w3schools.com/html/pic_trulli.jpg">
I would like to align the image links to the center of the page. This is what I have tried so far:
HTML:
<section id="Contact">
<h1 class="other-section">Contact</h1>
<div class="contact-links">
<a id="profile-link" href="https://facebook.com/" target="_blank">
<img src="https://image.flaticon.com/icons/svg/21/21155.svg" />
</a>
<a id="profile-link" href="https://github.com/jadenadams329" target="_blank">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" />
</a>
<a id="profile-link" href="https://instagram.com" target="_blank">
<img src="https://image.flaticon.com/icons/svg/87/87390.svg" />
</a>
</div>
</section>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
CSS:
#Contact {
margin:0 auto;
padding:3em 0 0 0;
min-height:100vh;
background-color: var(--contact-bg);
}
.other-section{
font-size: 30pt;
text-align:center;
color: #EDF5E1;
margin-bottom: 10px;
}
.contact-links{
text-align: center;
}
#profile-link img{
width: 50px;
}
I cannot for the life of me get them to stay in the center of the page evenly spaced under Contact.
Actually you can achieve that using inline-block.
:root{--contact-bg: white}
#Contact {
margin:0 auto;
padding:3em 0 0 0;
min-height:100vh;
background-color: var(--contact-bg);
}
.other-section{
font-size: 30pt;
text-align:center;
color: #EDF5E1;
margin-bottom: 10px;
}
.contact-links{
text-align: center;
}
.profile-link{
display: inline-block;/*just add this*/
}
.profile-link img{
width: 50px;
}
<section id="Contact">
<h1 class="other-section">Contact</h1>
<div class="contact-links">
<a class="profile-link" href="https://facebook.com/" target="_blank">
<img src="https://image.flaticon.com/icons/svg/21/21155.svg" />
</a>
<a class="profile-link" href="https://github.com/jadenadams329" target="_blank">
<img src="https://image.flaticon.com/icons/svg/25/25231.svg" />
</a>
<a class="profile-link" href="https://instagram.com" target="_blank">
<img src="https://image.flaticon.com/icons/svg/87/87390.svg" />
</a>
</div>
</section>
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>