Vertical aligning of pictures with links inside a div - html

I've been struggling with this simple and basic problem for the last day and can't seem to find a solution for it nowhere.
I'm having a container div on my website, in which there are four social network buttons, and what I'm trying to achieve is vertically align them in to the middle
of the container, so there's equal amount of free space on top of them and underneath them.
Please note, that I've linke normalize.css and reset.css to my html.
Muh code:
HTML
<div class="social-line-container">
<div class="social-line-buttons-group">
<a href="#0"><img src="socialicons/facebook.png" alt="FB"><a/>
<a href="#0"><img src="socialicons/twitter.png" alt="TW"><a/>
<a href="#0"><img src="socialicons/google.png" alt="GO"><a/>
<a href="#0"><img src="socialicons/youtube.png" alt="YT"><a/>
</div>
</div>
CSS
.social-line-container {
width: 66%;
height: inherit;
margin: 0 auto;
}
.social-line-buttons-group a{
display: inline-block;
vertical-align: middle;
height: 100%;
float: right;
padding: 2px;
margin: 0 3px;
}
Any help will be much appreciated.

All you need to add is clear
.social-line-container {
width: 66%;
height: inherit;
margin: 0 auto;
}
.social-line-buttons-group a {
display: inline-block;
/*vertical-align: middle;*/
height: 100%;
float: right;
clear: both; /* add */
padding: 2px;
margin: 0 3px;
}
<div class="social-line-container">
<div class="social-line-buttons-group">
<a href="#0">
<img src="socialicons/facebook.png" alt="FB"><a/>
<a href="#0">
<img src="socialicons/twitter.png" alt="TW"><a/>
<a href="#0">
<img src="socialicons/google.png" alt="GO"><a/>
<a href="#0">
<img src="socialicons/youtube.png" alt="YT"><a/>
</div>
</div>

.social-line-container{
border:2px solid black;
}
.social-line-buttons-group{
display:flex;
align-items: center;
justify-content: center;
height:100%;
}
.social-line-buttons-group a{
padding: 2px;
margin: 0 3px;
}
img{
width:50px;
height:50px;
}
<div class="social-line-container">
<div class="social-line-buttons-group">
<img src="http://lh3.googleusercontent.com/-ElsaNCI_yKg/VcXI_VFictI/AAAAAAAAINA/MeFjL1Ymaac/s640/StylzzZ%252520%252528289%252529.png" alt="FB">
<img src="https://upload.wikimedia.org/wikipedia/it/archive/0/09/20160903181541!Twitter_bird_logo.png" alt="TW">
<img src="http://www.userlogos.org/files/logos/annyella/google3.png" alt="GO">
<img src="http://logok.org/wp-content/uploads/2014/08/YouTube-logo-play-icon-219x286.png" alt="YT">
</div>
</div>

Related

How do I center this Google logo regardless of browser size?

I am trying to re-create the Google homepage layout for practice and I can't seem to center the Google logo.
I've tried:
text-align: center;
position: absolute;
Increasing the left margin of the logo (but I feel like this is not the right way to do it because it's not centered when I change the browser size.)
I realized that it might be the top bar affecting the logo alignment because when I removed the top bar, the logo became centered. However, putting the Google logo in a separate div and setting position:absolute; also didn't work.
This a link to my project http://codepen.io/wilfredbtan/pen/dXLxOz
Here's a snippet of the topbar and logo html:
<div id="container">
<div id="topbar">
<ul>
<li>
<a href="#">
<img src="the_odin_project/google-homepage/images/blueperson.jpg" style="border-radius: 100%" />
</a>
</li>
<li>
<a href="https://plus.google.com/u/0/notifications/all?hl=en">
<img src="the_odin_project/google-homepage/images/notification.png" />
</a>
</li>
<li>
<a href="https://www.google.com/intl/en/aboout/products/">
<img src="the_odin_project/google-homepage/images/apps.png" />
</a>
</li>
<li>Images</li>
<li>Gmail</li>
</ul>
</div>
<img style="" id="logo" alt="google" src="the_odin_project/google-homepage/images/google-logo.png" />
</div>
Here's a snippet of the relevant CSS:
body {
margin: 0 auto;
padding: 0;
}
#container {
margin: 10px 0 0 0;
text-align: center;
}
#topbar {
margin: 25px 40px 0 0;
}
ul {
list-style-type: none;
}
li {
float: right;
display: block;
padding: 0 0 0 18px;
}
#topbar ul li {
font: 12.5px Arial, sans-serif;
}
#topbar ul li:first-child {
margin-top: -10px;
}
#logo {
margin: 50px 0 10px 0;
width: 35em;
position: relative;
}
#logo{
clear: both;
display: block;
margin: 0 auto;
}
See this fiddle
What I've done here is, moved your logo img to a new div and the width of this new div is 50%. And to make it centered I used margin:0 auto in CSS.
The updated HTML is as below
<div id="logo-container">
<img style="" id="logo" alt="google" src="http://res.cloudinary.com/wilfredxd/image/upload/v1471790654/google-logo_paxdp8.png" />
</div>
and the updated CSS is as follows
#logo-container {
width: 50%;
margin: 0 auto;
}
#logo {
/* margin: 50px 0 10px 0; */
width: 100%;
}
It's very simple. Just change #logo CSS like this:
#logo {
margin: 50px auto 20px;
width: 20em;
display: block;
clear: both;
}
To center an image, use margin: auto; and make it into a block element.
My code ended up looking something like this. Might not be the cleanest solution but it worked.
Here is the HTML
<div class="container">
<div id="logo-wrapper"></div>
<img src="Google_2015_logo.svg.png" alt="logo" class="logo">
</div>
<form action="https://www.google.com/search" style="display: flex; align-items: center; flex-direction: column;">
<div class="rounded-box">
<input autocomplete="off" type="text" name="q">
</div>
<div class="search-button">
<input type="submit" value="Google Search">
<input type="submit" value="I'm Feeling Lucky" name="btnI">
</div>
</form>
</div>
The CSS for container, logo-wrapper and .logo:
.container {
display: flex;
flex-direction: center;
justify-content: center;
align-items: center;
margin-bottom: 20px;
margin-top: 400px;
}
.logo-wrapper {
width: 20%;
margin: 0 auto;
}
.logo {
width: 20%;
}
Not 100% happy with using px in the CSS but yet to find a better work around!

CSS: three images, one left, one center, one right

I'm trying to position three images, one to the left, one to the right, and one in the center, with equal space both sides, but this code is not working:
#header {
background: lightgrey;
background-color: rgba(256, 256, 256, 0.47);
margin: 15px auto 0px auto;
display: block;
height: 80px;
width: 965px;
}
#capçalera1 {
float: left;
margin-left: 15px;
margin-top: 16px;
margin-bottom: 16px;
}
#capçalera2 {
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 10px;
}
#capçalera3 {
float: right;
margin-right: 15px;
margin-top: 18px;
margin-bottom: 18px;
}
<div id="header">
<div id="capçalera1">
<a href="http://www.uib.cat/">
<img src="/images/logoblue2.png" width=138px height=44px/>
</a>
</div>
<div id="capçalera3">
<a href="http://www.iac3.eu/">
<img src="/images/iac3ieec.jpeg" width=58px height=40px/>
</a>
</div>
<div id="capçalera2">
<img src="/images/test.png" width=531px height=51px/>
</div>
</div>
The left and right images are ok, but the centered one is "glued" to the left one. I want to be able to put it top margin, and to be equally spaced from left and right image.
Thanks for your help!
<div id="header">
<div id="capçalera1">
<img src="/images/logoblue2.png" width=138px height=44px/>
</div>
<div id="capçalera3">
<img src="/images/iac3ieec.jpeg" width=58px height=40px/>
</div>
<div id="capçalera2">
<img src="/images/test.png" width=531px height=51px/>
</div>
</div>
Thats to complicated...
Try this.
<div id="header">
<ul>
<li><img src="/images/logoblue2.png" width=138px height=44px/></li>
<li><img src="/images/iac3ieec.jpeg" width=58px height=40px/></li>
<li><img src="/images/test.png" width=531px height=51px/></li>
</ul>
</div>
CSS
#header ul {
margin: 0;
padding: 0;
}
#header ul li {
display: inline-block //or you can float them,
}
#header ul li:nth-child(even){
margin: 0 10px;
}
you can use one div and three spans like
<div class="container">
<span>
<img ... >
</span>
<span>
<img ... >
</span>
<span>
<img ... >
</span>
css :
.container{ width:50%; margin:0 auto; text-align:center}
.container span{ width:30%; margin:0 1%; }
`
This looks like a job for flexbox! Remove all styling on the capcaleras, and put:
#header {
display: flex;
justify-content: space-around;
background: lightgrey;
background-color: rgba(256, 256, 256, 0.47);
margin: 15px auto 0px auto;
display: block;
height: 80px;
width: 965px;
}
Keep in mind, though, that support for this is not great.

Align Images Vertically over Horizontally

I am trying to realign my images side by side, rather than vertically. I have looked at CSS - center two images in css side by side, to no avail. My code from that link is as follows:
HTML:
<!-- Naviational Bar -->
<div width="100%" height="25%">
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
</div>
CSS:
/*Header and Navigational Bar*/
h1.heading {
padding: 10px;
text-align: center;
font-family: 'Signika', sans-serif;
}
.btn {
/*display: inline-block;*/
margin-left: 10%;
margin-right: 10%;
}
/*Define Button Attributes*/
.navigational-item {
width: 7%;
height: auto;
border-radius: 10px;
position: relative;
-webkit-filter: contrast(50%);
z-index: 100;
}
span.navigational-item {
font-family: sans-serif;
color: red;
}
.nav {
display: block;
margin-left: auto;
margin-right: auto;
}
This is what it looks like:
Is there any way I can lay the image out side by side with a 10px margin between them?
Thanks in advance!
Try below code for "btn" class:
.btn {
margin-left: 10px;
margin-right: 10px;
float:left;
}
You need to put your buttons into a container div like this: (arbitrarily set here for a width of 30% -- edit accordingly)
<div width="100%" height="25%">
<div id="container" style="width:30%;margin:auto">
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
<div class="btn"><img class="navigational-item nav" alt="Home" src="images/buttons/home.jpg"></div>
</div>
</div>
And then set the display property of your buttons to inline-block:
.btn {
/*display: inline-block;*/
margin-left: 10%;
margin-right: 10%;
display:inline-block;
}
See pen here: http://codepen.io/Bangkokian/pen/eppbYL
Have a look at this basic idea :
#container {
text-align: center;
}
.btn {
display: inline-block;
}
.nav {
margin: 0 10px;
}
/* Below is trivial for reszing */
.navigational-item {
width: 50px;
}
http://codepen.io/anon/pen/wKKRMe?editors=110
Do you know the parameters of the images? If so we'll do this
<div class="image_container">
<div class="center">
<div class="btn">
<img src="">
</div>
</div>
</div>
CSS:
.image_container { position: relative }
.center {
position:absolute;
left:50%;
width: 970px;
margin: 0 0 0 -485px;
/*margin left is width / 2*/
}
.btn {
display:inline-block;
margin: 0 10px 0 10px;
}
DEMO HERE
http://jsbin.com/fexasivori/1
EDITED
updated the link and the CSS I mistakenly wrote the wrong math for the margin-left parameter. 970 divided by 2 is not 435 it is 485

position relative in logo is not working

I have created a design which is below
http://jsfiddle.net/g9TT7/1/
i want to put logo means below top and left side of the page
<a href="index.html" style="margin-top:10px;position:relative!important;width:200px;display:block;" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
here i want to put business name in the center of the page and logo will be on the left side of the page. I have set position absolute in my logo but not working.
Please help me to do this.
I hope you want something like this:
Demo
Add css float:left in your logo style and remove position absolute from business div.
You can also adjust position from top and left by playing with margin.
HTML:
<div class="b" style="text-align:center;">
<a href="index.html" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
<div class="business_name" >
Business
</div>
<div class="clear"></div>
</div>
CSS:
.clear
{
clear:both;
}
.img1{
margin-top:20px;
width:200px;
display:block;
float:left;
}
.business_name {
width: 78%;
font-size: 43px;
font-weight: bold;
float: left;
text-align: center;
line-height: 28px;
margin-top: 5px;
}
.b {
font-size: 25px;
font-weight: bold;
width: 78.5%;
text-align: left;
height: 50px;
margin: 0px;
color: rgb(67, 161, 240);
}
.img1 {
float: left;
margin: 2px 0px 0px;
width: 20%;
text-align: left;
border: 0px solid red;
}
Something like this? http://jsfiddle.net/ADDTn/
<div class="header">
<a href="#" class="logo">
<img src="img.jpg" />
</a>
<h1>Bussiness</h1>
<div class="clear"></div>
</div>
css
.header {
width: 100%;
height: 100px;
}
.logo {
display: block;
float: left;
}
h1 {
text-align: center;
}
.clear {
clear: both;
}
Assign the z-index value
<a href="index.html" style="margin-top:10px;position:relative!important;width:200px;display:block; z-index: 1;" class="img1">
<img src="image/img_2.png" alt="logo" />
</a>
see this demo

Image link cause another image link to be unclickable

I have two image links that need to be centered with a little shifting.
My problem is that one link cause the other to be unclickable.
DEMO - The right one can't be clicked
HTML:
<div class="my_class" id="my_id1">
<a href="URL">
<img src="//placehold.it/200x150" />
</a>
</div>
<div class="my_class" id="my_id2">
<a href="URL2">
<img src="//placehold.it/200x150" />
</a>
</div>
css:
#my_id1
{
left: 120px;
}
#my_id2
{
right: 120px;
top: -157px;
}
.my_class
{
text-align:center;
position:relative;
display: block;
margin-left: auto;
margin-right: auto;
}
.my_class
{
text-align:center;
position:relative;
display: block;
margin: 0px, auto;
}
img{
border:1px solid red;
}
Here is the modified code:
<div class="my_class" id="my_id1"> <a href="URL">
<img src="//placehold.it/200x150" />
</a>
</div>
<div class="my_class" id="my_id2"> <a href="URL2">
<img src="//placehold.it/200x150" />
</a>
</div>
And the CSS:
#my_id1 {
float: left;
left: 150px;
}
#my_id2 {
float:right;
right: 150px;
}
.my_class {
text-align:center;
position:relative;
display: block;
margin-left: auto;
margin-right: auto;
}
.my_class {
text-align:center;
position:relative;
display: block;
margin: 0px, auto;
}
img {
border:1px solid red;
}
You need to float those containers : http://jsfiddle.net/GbzSQ/5/
Your first div overlaps over the other, so you need to float them and then use margins to position them properly.
.my_class{
float:left;
width:200px;
}
The divs of the links are just on top of each other.
So the mouse does not "see the bottom link".
Try using display inline in the divs with defined width.
I would use some floats or display:inline-block 's.
I made an update of your Fiddle with the Floats.
http://jsfiddle.net/cfknoop/GbzSQ/7/
#my_id1 {
float:left;
}
#my_id2 {
float:right;
}
The wrapper needs to be cleared with an clearfix or something.
Try not to use negative positioning, it's bad practice and will cause issues such as this. Try defining the size of the containing divide, position that, then float the divs within this.
I'll put together a quick fiddle to show you.
http://jsfiddle.net/GbzSQ/23/
And here's the HTML:
<div class="container" id="container">
<div class="my_class1" id="my_id1">
<a href="URL">
<img src="//placehold.it/200x150" alt="1" />
</a>
</div>
<div class="my_class2" id="my_id2">
<a href="URL2">
<img src="//placehold.it/200x150" alt="2" />
</a>
</div>
</div>
And the CSS:
.my_class2 {
text-align:center;
float: right;
position:relative;
display: block;
margin: 0 auto;
}
.my_class1 {
text-align:center;
float: left;
position:relative;
display: block;
margin: 0 auto;
margin-right: 20px;
}
img{
border:1px solid red;
}
.container {
width: 440px;
height: 200px;
display: block;
margin: 0 auto;
}