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

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.

Related

Vertical aligning of pictures with links inside a div

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>

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!

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

Stacking Multiple Divs From Bottom to Top

I am trying to align multiple divs (buttonNav) to the bottom of a container div (lowerNav). I have read every question on here regarding this and tried the CSS and it does not seem to work. I tried this one: Stacking Divs from Bottom to Top amoung others, hoping someone can help.
Here is my html, I have 5 of the lowerNav containers each with multiple buttonNavs that I want to align to the bottom of the lowerNav here is the code from one, they are all set up the same way:
<div class="lowerNav">
<img src="image/contact-us.gif" width="126" height="27" alt=""/>
<p>Ready to get more information or contact us directly?</p>
<div class="buttonNav">
<p>Order Literature</p>
</div>
<div class="buttonNav">
<p>Downloads</p>
</div>
<div class="buttonNav">
<p>Email Sign-Up</p>
</div>
<div class="buttonNav">
<p>Meet Your Rep</p>
</div>
<div class="buttonNav">
<p>Ask a Question</p>
</div>
</div>
Here is my CSS:
.lowerNav {
width: 160px;
height: 325px;
background-color: #e3dfd7;
border: 3px solid #383431;
float: left;
margin: 15px 8px 0px 8px;
text-align: left;
display: table-cell;
vertical-align: bottom;
}
.lowerNav p {
padding: 5px 12px 12px 12px;
}
.lowerNav img {
padding-top: 12px;
}
.buttonNav {
background:url(image/button-lowerNav.jpg);
width: 160px;
height: 45px;
display: inline-block;
}
.buttonNav p {
text-align:center;
padding-top: 14px;
}
.buttonNav a {
color: #fff;
font-size: 13px;
text-decoration:none;
font-weight:700;
}
.buttonNav a:hover {
color: #fff;
font-size: 13px;
text-decoration:underline;
font-weight:700;
}
Since the container (.lowerNav) has a fixed height and you know the size of its content this is quite easy to do with absolute positioning.
HTML:
<div class="outer">
Hello up here!
<ul class="inner">
<li>Hello</li>
<li>down</li>
<li>there!</li>
</ul>
</div>
CSS:
.outer {
position: relative;
height: 200px;
}
.inner {
position: absolute;
bottom: 0;
}
Check this CodePen for a live example of this code: http://codepen.io/EvilOatmeal/pen/fCzIv

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