I have a row with 5 images with the description below, but if the descriptions aren't with the same width the images go up and down, not anymore on the same row.
This is my situation:
Html:
<div class="background">
<div class="layer">
<div class="div-diviso-contenitore">
<div class="div-diviso">
<img src="http://77.238.26.244:81/confimi/wp-content/uploads/2017/02/SILVIA-FAIT-2017_980.jpg">
<div class="overlay">
</div>
</div>
<div class="description">
<p style="color:#ffffff; padding-top:10px; font-size:18px; text-align:left;"><b>Silvia Fait</b></p><br>
<p style="color:#20bed0; padding-top:10px; font-size:20px; margin-top:-27px; text-align:left;">Responsabile ufficio internalizzazione</p><br>
<p style="color:#ffffff; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Mail: estero#confimiemilia.it</p><br>
<p style="color:#20bed0; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Linkdein</p><br>
</div>
</div>
<div class="div-diviso-contenitore">
<div class="div-diviso">
<img src="http://77.238.26.244:81/confimi/wp-content/uploads/2017/02/CLAUDIO-ZAMPARELLI-2017_980.jpg">
<div class="overlay">
</div>
</div>
<div class="description">
<p style="color:#ffffff; padding-top:10px; font-size:18px; text-align:left;"><b>Claudio Zamparelli</b></p><br>
<p style="color:#20bed0; padding-top:10px; font-size:20px; margin-top:-27px; text-align:left;">Responsabile ufficio ufficio economico finanziario fiscale</p><br>
<p style="color:#ffffff; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Mail: fiscaletributario#confimiemilia.it</p><br>
</div>
</div>
<div class="div-diviso-contenitore">
<div class="div-diviso">
<img src="http://77.238.26.244:81/confimi/wp-content/uploads/2017/02/ROBERTA-MAGNANI-2017_980.jpg">
<div class="overlay">
</div>
</div>
<div class="description">
<p style="color:#ffffff; padding-top:10px; font-size:18px; text-align:left;"><b>Roberta Magnani</b></p><br>
<p style="color:#20bed0; padding-top:10px; font-size:20px; margin-top:-27px; text-align:left;">Responsabile ufficio commerciale & sviluppo</p><br>
<p style="color:#ffffff; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Mail: relazioniassociative#confimiemilia.it</p><br>
<p style="color:#20bed0; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Linkdein</p><br>
</div>
</div>
<div class="div-diviso-contenitore">
<div class="div-diviso">
<img src="http://77.238.26.244:81/confimi/wp-content/uploads/2017/02/BARBARA-VANNI-2017_980.jpg">
<div class="overlay">
</div>
</div>
<div class="description">
<p style="color:#ffffff; padding-top:10px; font-size:18px; text-align:left;"><b>Barbara Vanni</b></p><br>
<p style="color:#20bed0; padding-top:10px; font-size:20px; margin-top:-27px; text-align:left;">Responsabile ufficio formazione</p><br>
<p style="color:#ffffff; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Mail: formazione#confimiemilia.it</p><br>
<p style="color:#20bed0; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Linkdein</p><br>
</div>
</div>
<div class="div-diviso-contenitore">
<div class="div-diviso">
<img src="http://77.238.26.244:81/confimi/wp-content/uploads/2017/02/SANDRO-CAMPANI-2017_980.jpg">
<div class="overlay">
</div>
</div>
<div class="description">
<p style="color:#ffffff; padding-top:10px; font-size:18px; text-align:left;"><b>Sandro Campani</b></p><br>
<p style="color:#20bed0; padding-top:10px; font-size:20px; margin-top:-27px; text-align:left;">Responsabile ufficio relazioni sindacali</p><br>
<p style="color:#ffffff; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Mail: sindacale#confimiemilia.it</p><br>
<p style="color:#20bed0; padding-top:10px; font-size:18px; margin-top:-27px; text-align:left;">Linkdein</p><br>
</div>
</div>
</dvi>
</div>
Css:
.background {
background-image: url('http://77.238.26.244:81/confimi/wp-content/uploads/2016/08/a.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
height: 100%;
}
.layer {
background-color: rgba(18, 29, 47, 0.96);
background-repeat: repeat;
width: 100%;
height: 100%;
text-align: center;
padding: 200px 20px 200px 20px;
}
.div-diviso {
width: 100%;
position: relative;
}
.div-diviso-contenitore {
width: 17%;
margin: 10px;
display: inline-block;
position: relative;
}
.div-diviso img {
width: 100%;
position: relative;
}
.div-diviso .overlay {
width: 100%;
height: 100%;
position: absolute;
box-sizing: border-box;
top: 0;
left: 0;
background-color: rgba(0,0,0,0.6);
opacity: 0;
transform: scale(0.1);
-webkit-transform: scale(0.1);
-moz-transform: scale(0.1);
-ms-transform: scale(0.1);
-o-transform: scale(0.1);
transition: all 0.5s ease-in-out;
-webkit-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
visibility: hidden;
}
.div-diviso:hover .overlay {
opacity: 1;
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
-o-transform: scale(1);
visibility: visible;
border: 3px solid #ffffff;
transform: border 2.75s;
}
#media (min-width: 768px) and (max-width: 980px) {
.layer {
text-align: center;
}
.div-diviso-contenitore {
width: 47%;
margin: 10px;
}
}
#media (max-width: 767px) {
.layer {
text-align: center;
}
.div-diviso-contenitore {
width: 98%;
margin: 5px;
}
}
This is what I would like:
The problem is occurring because of vertical alignment. Set the value of vertical-align: top; and you will have the expected output.
Plunkr
.div-diviso-contenitore {
width: 17%;
margin: 10px;
display: inline-block;
position: relative;
vertical-align: top;
}
See this fiddle
Add this CSS
.div-diviso-contenitore {
vertical-align: top;
}
First you need to give a specific height to the class div-diviso-contenitore.
Here i have rewritten the class div-diviso-contenitore
.div-diviso-contenitore {
display: inline-block;
height: 400px; // give your specific height value
margin: 10px;
overflow: hidden;
position: relative;
width: 17%;
word-wrap: break-word;
}
What difference from your class is
height: 400px;
word-wrap: break-word;
overflow: hidden;
Check this fiddle : https://jsfiddle.net/ganesh16889/wfe58x97/
Related
hey I am new to programming and I'm trying the css vertical text slide animator feature, when the feature runs smoothly the text turns out to be disproportionate (not in the middle of the screen) even though I've added margins (right & left) to auto
#keyframes animate{
0%,100%{
top:0;
}
20%{
top:0px;
}
25%{
top:-50px;
}
45%{
top:-50px;
}
50%{
top:-100px;
}
70%{
top:-100px;
}
75%{
top:-150px;
}
95%{
top:-150px;
}
}
<div class="container " style="margin-left: auto; margin-right:auto">
<h1 class="display-4 w3-center w3-animate-right" >Hi I'm Raffiel</h1>
<div class="outer " style="display: block; position:relative;">
<h1 style="font-size: 45px ;">I am,
<div class="inner" style="position:absolute; border:0px solid #ddd; height:50px; line-height:50px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block; text-align: left; font-weight: 400;">
<span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; text-align: left;">
Graphic Designer<br>
Digital Marketer<br>
Video Editor<br>
Web Designer<br>
</span>
</div>
</h1>
</div>
</div>
strong text
Basically it should have been position:relative in order to take "space" and be included in the text-align:center. But you still need to fine tune this example.
#keyframes animate {
0%,
100% {
top: 0;
}
20% {
top: 0px;
}
25% {
top: -50px;
}
45% {
top: -50px;
}
50% {
top: -100px;
}
70% {
top: -100px;
}
75% {
top: -150px;
}
95% {
top: -150px;
}
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<div class="container" style="text-align:center">
<h1 class="display-4 w3-center w3-animate-right">Hi I'm Raffiel</h1>
<div class="outer">
<h1 style="font-size: 45px ;height:50px; line-height:50px ">I am,
<div class="inner" style="position:relative; border:0px solid #ddd; height:45px; line-height 45px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block; text-align: left; font-weight: 400; ">
<span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; ">
Graphic Designer<br>
Digital Marketer<br>
Video Editor<br>
Web Designer<br>
</span>
</div>
</h1>
</div>
</div>
try this
#keyframes animate{
0%,100%{
top:0;
}
20%{
top:0px;
}
25%{
top:-50px;
}
45%{
top:-50px;
}
50%{
top:-100px;
}
70%{
top:-100px;
}
75%{
top:-150px;
}
95%{
top:-150px;
}
}
<div class="container " style=" width:100%; margin: auto;">
<h1 class="display-4 w3-center w3-animate-right" style="text-align:center;" >Hi I'm Raffiel</h1>
<div class="outer " style="display: block; text-align:center;">
<h1 style="font-size: 45px;">I am,
<div class="inner" style=" border:0px solid #ddd; height:50px; line-height:50px; font-size:45px; text-transform:uppercase; overflow:hidden; display:inline-block; text-align:left; font-weight: 400;">
<span style="animation:animate 10s ease infinite; position:relative;color:#e58e26; ">
Graphic Designer<br>
Digital Marketer<br>
Video Editor<br>
Web Designer<br>
</span>
</div>
</h1>
</div>
</div>
So I am trying to create a website with recipes, so I put images of the recipes, with the name of the recipe underneath, but the problem is that they are not landing in the center beneath the image. They are the same distance apart, but I can't get each text to go under the image in the center. How would I do this? I would suggest viewing the result of the code in full view because I have not coded the website to work properly when the window is minimized. Also, you won't see the images because they are files on my computer.
<style>
body{
background: rgb(239,239,239);
padding:0;
margin:0;
}
a:nth-child(2) {
margin-left: 300px;
}
nav{
height: 120px;
length:relative;
background: rgb(250,131,131);
}
.header{
overflow:hidden;
background-color: white;
padding: 20px 10px;
}
.header-right a {
float:right;
color:black;
text-align:center;
padding:12px;
text-decoration:none;
font-family: 'Paprika', cursive;
font-size:18px;
line-height: 25px;
border-radius:4px;
font-size:14px;
}
.header a.logo{
font-size: 25px;
font-weight: bold;
float:left;
font-family:"Poppins", cursive;
text-decoration:none;
color:black;
letter-spacing: 10px;
}
.header-right a:hover{
background-color: rgb(248,248,248);
color:black;
}
.header a.active {
background-color: rgb(225,225,225);
color:black;
}
.header-right input[type=text] {
float:right;
padding:6px;
margin-top:9px;
margin-right:16px;
font-size:17px;
}
.latest{
font-family: "Pavanam", snas-serif;
text-align: center;
letter-spacing:8px;
}
.simple{
font-family: "Pavanam", snas-serif;
text-align: center;
letter-spacing:8px;
font-size: 12px;
margin-top:300px;
}
hr{
width:10%;
}
.doball:hover, .cookie:hover, .cake:hover, .snacks:hover{
transform:scale(1.2);
box-shadow: 5px 5px 15px rgba(0,0,0,0.6);
}
a:nth-child(2) {
margin-left: 300px;
}
.choccook{
height:150px;
margin-left:50px;
margin-top:100px;
margin-bottom:50px;
width:230px;
height:230px;
}
.oreocak, .coffcake, .granbar,.banbread, .cinnroll{
height:150px;
margin-left:1.5px;
margin-bottom:50px;
width:230px;
height:230px;
object-fit:cover;
}
.choccook:hover, .oreocak:hover, .coffcake:hover, .granbar:hover, .banbread:hover, .cinnroll:hover{
opacity:50%;
}
.recip{
margin-left:50px;
margin-top:-50px;
font-size: 14px;
font-weight: bold;
font-family:"Pavanam", cursive;
text-decoration:none;
color:black;
letter-spacing: 5px;
}
.recipnameone,.recipnametwo, .recipnamethree, .recipnamefour, .recipnamefive{
margin-left:100px;
}
.doball, .cookie, .cake, .snacks{
margin-left:30px;
margin-bottom:100px;
width:80px;
height:80px;
object-fit:cover;
transition: 0.5s ease;
border-radius:50%;
}
.categories{
margin-left:550px;
}
.circone{
font-size: 13px;
font-weight: bold;
font-family:"Pavanam", cursive;
text-decoration:none;
color:black;
letter-spacing:3px;
}
.categnames{
margin-left:40px;
margin-top:-120px;
}
.circtwo, .circthree, .circthree, .circfour{
margin-left:55px;
.recipnamefive{
font-size:13px;
}
.recippics{
margin-top:-80px;
}
</style>
<!DOCTYPE html>
<html>
<head>
<title>Bake It Simple</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Paprika&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Pavanam&display=swap" rel="stylesheet">
</head>
<body>
<div class="header">
BAKE IT SIMPLE
<div class="header-right">
About
Recipes
<input type="text" placeholder="Search...">
</div>
</div>
<h3 class="latest">LATEST RECIPES</h3>
<hr>
<div class="recippics">
<img class="choccook" src="file:///C:/Users/Pranavi.Kedari/Pictures/cookies.jpg" href="#"></img>
<img class="oreocak" src="file:///C:/Users/Pranavi.Kedari/Pictures/oreocake.jpg" href="#"></img>
<img class="coffcake" src="file:///C:/Users/Pranavi.Kedari/Pictures/coffeecake.jpg" href="#"></img>
<img class="granbar" src="file:///C:/Users/Pranavi.Kedari/Pictures/granolabars.png" href="#"></img>
<img class="banbread" src="file:///C:/Users/Pranavi.Kedari/Pictures/bananabread.jpg" href="#"></img>
<img class="cinnroll" src="file:///C:/Users/Pranavi.Kedari/Pictures/cinnamonrolls.jpg" href="#"></img>
</div>
<p class="recip"><span class="recipname"> C.C. COOKIES</span> <span class="recipnameone"> OREO CAKE</span> <span class="recipnametwo"> COFFEE CAKE</span> <span class="recipnamethree"> GRANOLA BARS</span> <span class="recipnamefour"> BANANA BREAD</span> <span class="recipnamefive"> CINNAMON ROLLS</span></p>
<h3 class="simple">SO SIMPLE, IT TASTES BETTER</h3>
</hr>
<div class="categories">
<img class="doball" src="file:///C:/Users/Pranavi.Kedari/Pictures/doughcirc.jpg" href="#"></img>
<img class="cookie" src="file:///C:/Users/Pranavi.Kedari/Pictures/cookies.jpg" href="#"></img>
<img class="cake" src="file:///C:/Users/Pranavi.Kedari/Pictures/oreocake.jpg" href="#"></img>
<img class="snacks" src="file:///C:/Users/Pranavi.Kedari/Pictures/granolabars.png" href="#"></img>
<div class="categnames">
<p class="circone"> DOUGHS <span class="circtwo"> COOKIES</span> <span class="circthree"> CAKES</span> <span class="circfour"> SNACKS</span></p>
</div>
</div>
</div>
</body>
</html>
You have your recipe names separate from your recipe images, which is difficult (if not impossible) to get everything to align. It would be easier to associate the names with the images in separate blocks. I set each block to float left to show how to align the text, but you could use flex to setup how your recipes will work on different screen sizes.
.recipe {
position: relative;
float: left;
padding: 0;
margin: 0;
margin-left: 25px;
width: 150px;
}
.recipe img {
width: 100%;
height: auto;
}
.recipe p {
width: 100%;
text-align: center;
}
<div class="recippics">
<div class="recipe">
<img src="file:///C:/Users/Pranavi.Kedari/Pictures/cookies.jpg">
<p>C.C. COOKIES</p>
</div>
<div class="recipe">
<img src="file:///C:/Users/Pranavi.Kedari/Pictures/oreocake.jpg">
<p>OREO CAKE</p>
</div>
<div class="recipe">
<img src="file:///C:/Users/Pranavi.Kedari/Pictures/coffeecake.jpg">
<p>COFFEE CAKE</p>
</div>
</div>
For future questions, you don’t need to include all of the unused stuff like the header CSS. Just include enough to show the problem.
I want to have 2 elements in a div but only one should be visible, and I want to have a vertical scrollbar.
Unfortunately, the second element is visible and there is no scrollbar.
#visu {
top:10px;
height:180px;
width:50%;
overflow:auto;
background-color:yellow;
}
#element1 {
position:absolute;
top:15px;
left:80px;
}
#element2 {
position:absolute;
top:200px;
left:80px;
}
.element {
margin-right:-50px;
}
.namecontainer {
display:flex;
border:4px solid #000033; border-radius:10px;
padding:10px; box-sizing:border-box;
background-color:white;
width:280px;
height:150px;
margin-left:0px;
align-items: center;
justify-content:center:
color:#1a1a1a;
}
.namecontainer p {
font-size:35px;
font-family: 'Arial';
font-weight:bold;
color:#1a1a1a;
text-align:center;
width:380px;
}
<div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class= "name" id="name1" >element 1</p>
</div>
</div>
<div id="element2" class="element">
<div class="namecontainer">
<p class= "name" id="name3" >element 2</p>
</div>
</div>
</div>
You need to play with margin and drop absolute positionnong cause it takes element off the flow and is not necessary here https://jsfiddle.net/vpdc5L4m/13/
#visu {
top: 10px;
height: 180px;
width: 50%;
overflow: auto;
background-color: yellow;
}
#element1 {}
#element2 {}
.element {
margin: 15px auto ;
}
.namecontainer {
display: flex;
border: 4px solid #000033;
border-radius: 10px;
padding: 10px;
box-sizing: border-box;
background-color: white;
width: 280px;
height: 150px;
margin:auto;
align-items: center;
justify-content: center: color: #1a1a1a;
}
.namecontainer p {
font-size: 35px;
font-family: 'Arial';
font-weight: bold;
color: #1a1a1a;
text-align: center;
width: 380px;
}
<div id="visu">
<div id="element1" class="element">
<div class="namecontainer">
<p class="name" id="name1">element 1</p>
</div>
</div>
<div id="element2" class="element">
<div class="namecontainer">
<p class="name" id="name2">element 2</p>
</div>
</div>
<div id="element3" class="element">
<div class="namecontainer">
<p class="name" id="name3">a third one ?</p>
</div>
</div>
</div>
To hide a CSS element, you can use
display: none;
I am building a website and right now I'm just about to complete the homepage. Now, the footer has a few links in it along with a few images next to each other like a contact us bar. But the links don't seem to align with the images even after trying everything. They seem to hang a little lower than the paragraphs or spans. I tried converting the spans on the same line to links but now all of them hang low.
HTML:
<div id="brdr_btm">
<div id="contactOptionContainer">
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/pGiDhI2.png?1"/>
<div id="ctcLinks">
La Martiniere College, Lucknow
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/E8Ow3O7.png?1">
<div id="ctcLinks">
secretariat#lmun.org
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" id="ic_call" src="http://i.imgur.com/1di7mj9.png?1">
<!--<div id="phoneno">-->
<div id="ctcLinks">
+91 9670680417 (Sec. Gen), <!-- was span -->
+91 9415444444 (Dep. Sec. Gen) <!-- was span -->
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/2HZVi1r.png?1">
</div>
</div>
</div>
CSS:
#brdr_btm
{
display:flex;
position:relative;
height: 25px;
width: 100%;
background-color: #70A5DA;
top:100%;
vertical-align:bottom;
margin_top:10px;
clear:both;
box-sizing:content-box;
/*z-index:-1;*/
}
#contactUs
{
margin:auto;
}
#contactOptionContainer
{
position:relative;
display:inline-block;
margin-top:auto;
margin-bottom:auto;
/* text-align:center;*/
box-sizing:content-box;
width:auto;
}
.ctcObject
{
display:inline-block;
margin-left:auto;
margin-right:5em;
/* margin-bottom:6px;*/
/* margin-top:auto;*/
}
.ic_contact
{
position:relative;
margin-top:6.25px;
margin-bottom:6.25px;
height: 12.5px;
width: 12.5px;
-webkit-user-drag:none;
user-select:none;
-ms-user-select:none;
-moz-user-select:none;
-webkit-user-select:none;
user-drag:none;
/* z-index:-1;*/
}
#ic_call
{
margin-top: -2px;
height:10.5px;
width:10.5px;
}
#ctcLinks
{
position:relative;
display:inline-block;
}
#ctcLinks a
{
position:relative;
margin-top:-6px;
margin-bottom:0px;
/* display:inline-block;*/
font-size:0.8em;
color:#FFFFFF;
/* text-align:center;*/
}
#phoneno
{
position:relative;
display:inline-block;
text-align:center;
}
#phoneno span
{
margin-left:0;
margin-right:0;
margin-bottom:6px;
margin-top: -1px;
text-align:center;
display:inline-block;
color:#ffffff;
vertical-align:middle;
font-size:0.9em;
}
How do I prevent this from happening and what causes it?
What might be the solution to the problem?
Here's my JSFiddle: http://jsfiddle.net/mfxefccz/
You should add to .ic_contact and #ctcLinks this style
display: inline-block;
height: 100%;
vertical-align: middle;
#brdr_btm
{
display:flex;
position:relative;
height: 25px;
width: 100%;
background-color: #70A5DA;
top:100%;
vertical-align:bottom;
margin_top:10px;
clear:both;
box-sizing:content-box;
/*z-index:-1;*/
}
#contactUs
{
margin:auto;
}
#contactOptionContainer
{
position:relative;
display:inline-block;
margin-top:auto;
margin-bottom:auto;
/* text-align:center;*/
box-sizing:content-box;
width:auto;
}
.ctcObject
{
display:inline-block;
margin-left:auto;
margin-right:5em;
/* margin-bottom:6px;*/
/* margin-top:auto;*/
}
.ic_contact
{
position:relative;
margin-top:6.25px;
margin-bottom:6.25px;
height: 12.5px;
width: 12.5px;
display: inline-block;
height: 100%;
vertical-align: middle;
-webkit-user-drag:none;
user-select:none;
-ms-user-select:none;
-moz-user-select:none;
-webkit-user-select:none;
user-drag:none;
/* z-index:-1;*/
}
#ic_call
{
margin-top: -2px;
height:10.5px;
width:10.5px;
}
#ctcLinks
{
position:relative;
display: inline-block;
height: 100%;
vertical-align: middle;
display:inline-block;
}
#ctcLinks a
{
position:relative;
margin-top:-6px;
margin-bottom:0px;
/* display:inline-block;*/
font-size:0.8em;
color:#FFFFFF;
/* text-align:center;*/
}
#phoneno
{
position:relative;
display:inline-block;
text-align:center;
}
#phoneno span
{
margin-left:0;
margin-right:0;
margin-bottom:6px;
margin-top: -1px;
text-align:center;
display:inline-block;
color:#ffffff;
vertical-align:middle;
font-size:0.9em;
}
<div id="brdr_btm">
<div id="contactOptionContainer">
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/pGiDhI2.png?1"/>
<div id="ctcLinks">
La Martiniere College, Lucknow
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/E8Ow3O7.png?1">
<div id="ctcLinks">
secretariat#lmun.org
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" id="ic_call" src="http://i.imgur.com/1di7mj9.png?1">
<!--<div id="phoneno">-->
<div id="ctcLinks">
+91 9670680417 (Sec. Gen), <!-- was span -->
+91 9415444444 (Dep. Sec. Gen) <!-- was span -->
</div>
</div>
<div class="ctcObject">
<img class="ic_contact" src="http://i.imgur.com/2HZVi1r.png?1">
</div>
</div>
</div>
Here a demo.
So, displayed it like an inline-block, because display: inline-block; don't work with blocks. And give then a height: 100%. In this case in means 100% from a parent. So we always have an image or block in the vertical center.
You have set margins for .ic_contact. If you remove margin-bottom for .ic_contact, your images and links would align properly. see here
.ic_contact
{
position:relative;
margin-top:6.25px;
height: 12.5px;
width: 12.5px;
}
I'm trying to align these divs correctly but they are repositioning themselves at will! I'm trying to align balance horizontally with history whilst transact is aligned vertically below balance.
Edit: .button style is irrelevant.
HTML:
<div id="main-page-content">
<div id="balance">
<u>Balances</u>
<div class="total-balance">
Total Balance:
</div>
<div class="a-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
<div class="b-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
</div>
<div id="transact">
</div>
<div id="history">
</div>
CSS:
#main-page-content {
max-width:960px;
margin:auto;
max-height: 500px;
padding-top:25px;
height:100%;
}
#balance {
font-family:Lato;
background-color:#00253F;
color:#FFFFFF;
font-size:24px;
padding-left:15px;
font-weight:bold;
padding-right:10px;
padding-top:15px;
height:130px;
width:52%;
float:left;
}
#transact {
font-family:Lato;
background-color:#00253F;
color:#FFFFFF;
font-size:24px;
padding-left:15px;
font-weight:bold;
padding-right:10px;
padding-top:15px;
height:130px;
width:52%;
float:left;
margin-top:10px;
}
#history {
background-color:#00253F;
width:32%;
height:300px;
float:right;
}
.total-balance {
padding-top: 8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
.a-balance {
padding-top: 8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
.b-balance {
padding-top: 8px;
padding-bottom:8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
The result of the above code or Checkout This Demo
You just need to move history above transact in your html:
<div id="history">Hist
</div>
<div id="transact">Trans
</div>
#main-page-content {
max-width: 960px;
margin: auto;
max-height: 500px;
padding-top: 25px;
height: 100%;
}
#balance {
font-family: Lato;
background-color: #00253F;
color: #FFFFFF;
font-size: 24px;
padding-left: 15px;
font-weight: bold;
padding-right: 10px;
padding-top: 15px;
height: 130px;
width: 52%;
float: left;
}
#transact {
font-family: Lato;
background-color: #00253F;
color: #FFFFFF;
font-size: 24px;
padding-left: 15px;
font-weight: bold;
padding-right: 10px;
padding-top: 15px;
height: 130px;
width: 52%;
float: left;
margin-top: 10px;
}
#history {
background-color: #00253F;
width: 32%;
height: 300px;
float: right;
color: #fff
}
.total-balance {
padding-top: 8px;
font-family: Lato;
width: 100%;
float: left;
font-size: 14px;
height: 16px;
}
.a-balance {
padding-top: 8px;
font-family: Lato;
width: 100%;
float: left;
font-size: 14px;
height: 16px;
}
.b-balance {
padding-top: 8px;
padding-bottom: 8px;
font-family: Lato;
width: 100%;
float: left;
font-size: 14px;
height: 16px;
}
<div id="main-page-content">
<div id="balance">
<u>Balances</u>
<div class="total-balance">
Total Balance:
</div>
<div class="a-balance">
Balance:
Deposit
Withdraw
</div>
<div class="b-balance">
Balance:
Deposit
Withdraw
</div>
</div>
<div id="history">Hist
</div>
<div id="transact">Trans
</div>
</div>
This is due to the way that float is handled in the browser. I recommend if you want to do two columns to either do two wrapping colums around the entire document, or use a grid framework which may help you out in the long run.
I set up a jsfiddle to help illustrate this: https://jsfiddle.net/a01cv4ec/
HTML
<h1>Using floats</h1>
<div>
Only the items you want to distort should be floated...
</div>
<div id="main-page-content">
<div id="balance">
<u>Balances</u>
<div class="total-balance">
Total Balance:
</div>
<div class="a-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
<div class="b-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
</div>
<div id="transact">
</div>
<div id="history">
</div>
<h1>Using inline-block positioning</h1>
<div>
This personally is my favorite. Allows for positioning and responsiveness without css hacks to make sure sizes match up.
</div>
<div id="main-page-content-2">
<div id="col-1">
<div id="balance">
<u>Balances</u>
<div class="total-balance">
Total Balance:
</div>
<div class="a-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
<div class="b-balance">
Balance:
<a href="#" class="button"/>Deposit</a>
<a href="#" class="button"/>Withdraw</a>
</div>
</div>
<div id="transact">
</div>
</div>
<div id="column-2">
<div id="history-inline">
history
</div>
</div>
CSS
#main-page-content {
max-width:960px;
margin:auto;
max-height: 500px;
padding-top:25px;
height:100%;
}
#balance {
font-family:Lato;
background-color:#00253F;
color:#FFFFFF;
font-size:24px;
padding-left:15px;
font-weight:bold;
padding-right:10px;
padding-top:15px;
height:130px;
width:52%;
float:left;
}
#transact {
font-family:Lato;
background-color:#00253F;
color:#FFFFFF;
font-size:24px;
padding-left:15px;
font-weight:bold;
padding-right:10px;
padding-top:15px;
height:130px;
width:52%;
float:left;
margin-top:10px;
}
#history {
background-color:#00253F;
width:32%;
margin-left: 58%;
height:300px;
}
.total-balance {
padding-top: 8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
.a-balance {
padding-top: 8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
.b-balance {
padding-top: 8px;
padding-bottom:8px;
font-family:Lato;
width:100%;
float: left;
font-size:14px;
height:16px;
}
.main-page-content-2 {
width:100%;
}
.main-page-content-2 > div {
display:inline-block;
vertical-align:top;
color:#FFF;
}
.main-page-content-2 > div:first-child > div {
margin:2px;
}
#history-inline {
color:#FFF;
background-color:#00253F;
width:32%;
margin-left: 58%;
height:300px;
}
Basically the better way to handle those is either through controlled floats, or even nicer with inline-block positioning.
If the thing you want is to put the history to top of the parent div just because it is like a grid you should use history above your transact.
<div id="history">Hist
</div>
<div id="transact">Trans
</div>