Align Divs at Top and create space between Divs - html

How do I align my three divs to be at the top?
- See how Google Mail and Google Maps dropdown since they have less content? I'd like them to be aligned at the top no matter how little text is below them
Also, I have three divs at 33.3333%.
- If I wanted to put more space inbetween the divs (say like 5px, how would I do that?
Here's my Jsfiddle: http://jsfiddle.net/huskydawgs/Z7dZR/
Here's my code:
<div id="wrapper-threecol">
<div id="threecol_row">
<div class="threecol_cell1">
<p class="summary-headline">Google Mail</p>
<p class="summary-description">Gmail's inbox helps you stay organized by sorting your mail by type. Plus, you cannot work correctly.</p>
</div>
<div class="threecol_cell2">
<p class="summary-headline">Google</p>
<p class="summary-description">Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for.</p>
</div>
<div class="threecol_cell3">
<p class="summary-headline">Google Maps</p>
<p class="summary-description">Find local businesses, view maps and get driving directions in Google Maps.</p>
</div>
</div>
</div>
Here's my CSS:
#wrapper-threecol {
position:relative;
width:100%;
border: none;
margin: 20px 0 0 0;
}
#threecol_row {
height:100%;
white-space:nowrap;
}
.threecol_cell1, .threecol_cell2, .threecol_cell3 {
height:100%;
width:33.3333%;
display:inline-block;
white-space:normal;
}
.summary-headline {
color: #232323;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: 20px;
line-height: 24px;
margin:0;
text-align: center;
}
.summary-description {
color: #232323;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: 13px;
line-height: 23px;
margin: 0;
text-align: center;
}

I put 5% spacing
http://jsfiddle.net/Z7dZR/1/
.threecol_cell1, .threecol_cell2, .threecol_cell3 {
height:100%;
width:30%;
display:inline-block;
white-space:normal;
vertical-align: top;
margin-left: 5%;
}
.threecol_cell1{
margin-left: 0;
}
You need to vertically align the inline-block elements to the top vertical-align: top;
For spacing, I made your blocks width 30%, which means you have 10% left of the 100%. So I set 5% to margin left for each block then set the first block margin-left to 0 so you have a perfect 100%. Since you have width in %, it would be wise to set the margin in % as well

.threecol_cell1, .threecol_cell2, .threecol_cell3 {
vertical-align: top;
}
that should do it.

Related

Container won't center

This container stubbornly refuses to center. Demo: http://codepen.io/Diego7/pen/KzXgZN
I've tried just about every centering code I can find on the web, to no avail.
Removing width: 90%; from the css aligns the container to the left, even though margin: 0 auto; is telling it to center.
Sorry if this question isn't up to StackOverflow's 'standards', but codingforums.com are down at the moment :(
Thanks heaps!
HTML
<div class="container">
<article>
<header>
<img src="https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png" width="972px"><br />
<h2>Information</h2>
</header>
<p>There's currently is no information available. Sorry.</p>
<footer>
© 2016
</footer>
</article>
</div>
CSS
##import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
body {
font-family: 'Open Sans', sans-serif;
background: #fff;
}
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
background: #fff;
border-radius: 6px;
box-sizing: container-box;
}
article header h2 {
color: #282828;
font-size: 1.2em;
font-weight: normal;
display:inline;
line-height: 1.3;
}
article p {
font-size: 1em;
display:inline;
line-height: 1.5em;
color: #282828;
max-width: 972px;
}
article footer {
font-size: .9em;
display:inline;
color: #999;
}
a {
color: #2790ae;
text-decoration: none;
outline: none;
}
a:hover {
color: #0f6780;
}
Your .container is already centered: if you change background to red you will see it. And, if you add text-align property its content will be centered too.
.container {
list-style:none;
margin:0 auto;
width:90%;
padding-top: 20px;
border-radius: 6px;
box-sizing: container-box;
text-align:center;
background: red;
}
If you make the width a bit narrower (like 70%), you see that it IS centered.
by the way: " list-style:none;" has no effect whatsoever, and "box-sizing: container-box;" should be "box-sizing: content-box;"
Looks like you're centering the <div class="container">, but it doesn't look like it, because you're looking at the image.
If you want the image to take up the entire <div> element (so that any centering takes effect on both), try something like the following, instead of using an <img> element:
div.container {
background-image: url(https://softwarereviews.files.wordpress.com/2016/04/bg-header-no-logo.png);
}
There are other properties you can use to fiddle with precisely how the image is displayed. You can find more info here.
If you are using container after float tag. It can create problem sometimes. So to avoiding this user <div class="clear"></div>. Also clear class properties would be:
.clear{
clear:both;
margin:0px;
padding:0px;
height:0px;
font-size:0px;
line-height:0px;
float:none;
}
Hope it will be helpful..

HTML/CSS Text Not aligning

I'm making a website and my text won't align to the center for the index-intro h1!
.index-intro {
width:100%;
background-color: #00C8FF;
height: 20px;
float:center;
}
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
text-align:center;
display:inline-block;
}
<section>
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
</section>
And thanks :)
Here is a trimmed down set of HTML and CSS:
.index-intro {
background-color: #00C8FF;
text-align:center;
}
.index-intro h1 {
font-size: 15px;
text-transform: uppercase;
}
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
This aids the vertical alignment issues too, since you had fixed the height of the containing <div>. Although I guess you may have wanted that?
Here it is with some padding thrown in:
https://jsfiddle.net/9a3b4f7g/1/
Your Css is okay.
Just add this class in style tag
<style type="text/css">
.wrapper
{
text-align: center;
}
</style>
Please try following code snippet
.index-intro {
width:100%;
background-color: #00C8FF;
height: 20px;
text-align:center
}
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
}
<section>
<div class="index-intro">
<div class="wrapper">
<h1>Welcome to Anime!</h1>
</div>
</div>
</section>
Believe it or not, you can do what you're looking for with just
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
text-align:center; /*this makes the text go in the middle*/
display:inline-block;
width:100%;
background-color: #00C8FF; /*your bar color*/
padding-top:20px; /* this "fattens" the blue bar topside */
padding-bottom:20px; /* this "fattens" the blue bar bottomside */
}
What this basically does is, 'make a blue bar that fits 100% the window width, with text in the middle, fatten it top and bottom'. It's better to keep your CSS simple like this if you can. Keeps you from getting confused in the long run.

How can I vertically align this text when I also need inline display?

I'm trying to make a headers for the chapters in my short story using a collapsible div. I use two different fonts / styles and three layers of divs to make it look the way I want it to. Unfortunately the text is several pixels too low, and it hurts my eyes when I see it.
I know that inline display doesn't really allow for vertical align (my paddings are ignored). I tried using "inline-block" to no avail. I tried top-padding the left ">" symbol, but that makes the entire construction move downwards. I've been hammering at this for the past 2 hours, I give up :D.
Here is my HTML markup as well as the CSS.
<div class="ShortStoryHeaderDiv" onclick="toggleContentDiv('h1','c1');">
<div class="ShortStoryHeaderCenterDiv">
<div id="h1L" class="ShortStoryHeaderDivLeft">></div>
<div class="ShortStoryHeaderText">Must... align... text</div>
<div id="h1R" class="ShortStoryHeaderDivRight"><</div>
</div>
</div>
CSS:
.ShortStoryHeaderDiv
{
margin-top: 1em;
margin-bottom: 1em;
width: 100%;
height: 3em;
text-align: center;
background-color: #DDD;
cursor: pointer;
}
.ShortStoryHeaderCenterDiv
{
padding-top:0.2em;
width: 70%;
margin-left: auto;
margin-right: auto;
}
.ShortStoryHeaderDivLeft
{
display:inline-block;
padding-right: 3em;
font-family: Verdana;
font-weight: bold;
text-shadow: 0 0 4px #555;
color: #000;
font-size: 17pt;
}
.ShortStoryHeaderDivRight
{
display:inline-block;
padding-left: 3em;
font-family: Verdana;
font-weight: bold;
text-shadow: 0 0 4px #555;
color: #000;
font-size: 17pt;
}
.ShortStoryHeaderText
{
display:inline;
font-family: "Times New Roman", Times, serif;
font-size: 1.5em;
text-align: center;
text-decoration: underline;
color: #00F;
}
You could try and use display:table-cell to vertically-align:middle
or set a height and then set the line height to the same.
e.g. height: 40px; line-height:40px;
Managed to make it work by using this in ShortStoryHeaderText CSS class, thanks to SkelDave for reminding me about vertical align. It is awkward that the padding-top ONLY started to work once that vertical-align: top was specified. It is ignored otherwise.
display:inline-block;
padding-top:3px;
vertical-align:top;

Can't remove padding on an image

I'm trying to make a simple 3-cell div that will show a list of ratings for cigars. I want the left cell to be a square image of the cigar, the middle to be the name, and the right to be the rating. The code works fine until I add the image - it then seems to add an 8px border on the bottom of the image, revealing the cell's background color. Using Wordpress (if that helps). Any help is appreciated!
This is the page: http://cigardojo.com/best-cigars/
HTML
<div class="ratingWrapTopRated">
<div class="cigarImage"><img src="http://cigardojo.com/wp-content/uploads/2014/08/cigar-test.jpg" alt="test" width="90" height="90" class="alignnone size-full wp-image-14045" /></div>
<div class="cigarName">Opus XXX Power Ranger</div>
<div class="numericalScoreTopCigars"></div>
</div>
CSS
.ratingWrapTopRated {
background:#fff;
width:600px !important;
height: 90px !important;
margin: 0 auto;
display:table;
font-family:Helvetica, Arial, sans-serif;
margin-bottom: 10px;
}
.cigarImage {
background:#fff; color:#fff;
display:table-cell;
width: 90px;
}
.cigarName {
background:#ff5100; color:#fff; text-align:center;
display:table-cell;
vertical-align:middle;
text-transform: uppercase;
}
.numericalScoreTopCigars {
background:#000; color:#fff; text-align:center;
width:25%;
display:table-cell;
vertical-align:middle;
font-weight:bold;
border-left: 4px solid; border-color: #fff;
}
Add line-height: 0; to .cigarImage and you will get rid of it. Many people will tell you to use display: block; and that will work but that is not the real problem. The problem is that img tags are inline and you get that space because you get the image plus the line-height it is in that container, and that creates the space you see below your image. The correct solution to that is to add what I just told you.
So edit your class like this:
.cigarImage {
background:#fff; color:#fff;
display:table-cell;
line-height: 0; /* Here is the solution */
width: 90px;
}
And you will get that working right :)
This is because images are inline (that is, they're treated like they're on a line of text) by default, and the bottom of them is aligned to the "baseline" of the line of text, not the absolute bottom. Below the image you get the space from the rest of the line below the baseline. If you just set the image to display: block; it should get rid of it (then it won't be considered part of a line of text, and will instead be its own block).
Just add a padding right of 5px or so on the .cigarImage class. You should also increase your image height or decrees the height of the info bar next to your images as they dont line up.
In your class ratingWrapTopRated class set line-height to 0:
.ratingWrapTopRated {
background:#fff;
width:600px !important;
height: 90px !important;
margin: 0;
display:table;
font-family:Helvetica, Arial, sans-serif;
padding-bottom: -8px;
margin-bottom: 10px;
line-height: 0; /*here*/
}

how to get 2 div's text to align along the bottom?

I'm designing a contact page and would like to have 2 columns, one with a label (e.g. facebook, twitter) and one with the actual details. The thing is I want the two lines (which have text of different size) to both align along the bottom edge.
It's probably easier if I show you: http://goonbee.com/contact
At the moment, the label and details are vertically aligned along the centre. How can I make them align along the bottom?
My CSS is:
#contactbox {
display: block;
margin-top: 25px;
}
#contactboxlabels {
font-family: Arial, Helvetica, sans-serif;
font-size: 17px;
color: #c9c9c9;
line-height: 42px;
text-align: right;
float: left;
padding: 0;
margin: 0;
}
#contactboxdetails {
font-family: Arial, Helvetica, sans-serif;
font-size: 35px;
color: #545454;
line-height: 42px;
text-align: left;
vertical-align: bottom;
float: left;
padding: 0;
margin: 0;
margin-left: 15px;
}
My HTML:
<div id="contactbox">
<div id="contactboxlabels">
<span>email<br />twitter<br />facebook<br />phone</span>
</div>
<div id="contactboxdetails">
<span>x#x.com<br />#goonbee<br />facebook.com/goonbee<br />+44 000000</span>
</div>
<div style="clear:both"></div>
</div>
at the moment you have the labels in one container and the values in another. this will make it harder to work with and is also not semantic and meaningful.
put each label and value in its own container. you'll end up with 4 pairs of label/value.
give the container position:relative; and then use position:absolute; for both the label and value. as long as the bottom for both is 0 then they should both be aligned along the bottom edge.
First, your markup is not very semantic. The keys belong with their values, they are not an independent column. This would be the most semantic, minimal markup:
<dl>
<dt>email</dt> <dd>touch#goonbee.com</dd>
<dt>twitter</dt> <dd>#goonbee</dd>
<dt>facebook</dt> <dd>facebook.com/goonbee</dd>
<dt>phone</dt> <dd>+44 7825 163256</dd>
</dl>
For styling this, the only drawback is that you need to set the width of your dt "column" explicitly in order to get them to line up:
dl { font-family: Arial, Helvetica, sans-serif; }
/* column layout */
dt {
float: left;
clear: left;
width: 4.25em; /* needs to be set for longest item */
margin: 0 1em 0 0;
}
dd {
overflow: hidden; /* creates an implicit column from remaining space */
}
You can then adjust line-height on the dt and add padding-top to keep the heights the same and match up the baselines:
/* typography */
dt {
font-size: 17px;
line-height: 29px; /* 42 - padding-top */
padding-top: 13px; /* ceil( (42 - font-size) / 2 ) */
color: #c9c9c9;
text-align: right;
}
dd {
font-size: 35px;
line-height: 42px;
color: #545454;
text-align: left;
}
Alternatively, if you don't want to set the width of the left column and have it align based on the longest element, like a table column, then use a table! This would give you better control over the vertical-align as well. I don't think a table would be inappropriate here, especially if you mark up the left column as th headers.
<div>
<div style="float: left; width: 75px; text-align: right; padding-right: 10px; padding-top:15px;">email</div>
<div>touch#goonbee.com</div>
</div>
or...
<div>
<span style="vertical-align: bottom; padding-right: 10px;">email</span>
touch#goonbee.com
</div>