Align Divs in HTML + CSS - html

I am trying to align three divs inside of a fourth div to create something similar to what you see on this page: http://www.thedistillerydistrict.com/
I can't seem to get the inside divs (#Entertainment, #Community, #welcome) align side by side inside the #HomeMain div
This is from the html
<div id = "HomeMain">
<div id="welcome">
<p>Finest Booze around, come taste for yourself Home to many of Toronto's hottest designer boutiques, unique cafes, artisan shops, breathtaking art galleries, performance venues and award-winning restaurants, The Distillery District is the place to see and be seen. An internationally acclaimed pedestrian-only village, The Distillery features more than 70 ground-floor cultural and retail establishments in the restored red brick, Victorian-era buildings of the renowned Gooderham & Worts whiskey distillery. One of Canada's hottest tourist attractions, centrally-located and just a short walk from downtown Toronto there is always something happening at The Distillery.</p>
<div class = "Oldman"></div>
</div>
<div id = "Entertainment">
<img src="images/Entertainment1.jpg" id="EntSlide" width=125 height=70 />
</div>
<div id = "Community">
<img src="images/Victoria1.jpg" id="ComSlide" width=125 height=70 />
</div>
</div>
Here is the CSS
#HomeMain{
width: 100%;
float: left;
overflow:hidden;
margin:0 auto;
padding:5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
}
#Entertainment #Community{
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
}
#welcome{
float: left;
width:50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px 5px 5px 5px;
font-weight: bold;
padding:15px;
}

Check this fiddle link http://jsfiddle.net/hek7fLy2/
All i have done is use the box-sizing css property to achieve the desired result. Also I assume you would want the images in the 2 smaller divs to be centered, so this takes care of that.
I have not changed your HTML code but i tweaked just a little bit of css code including the typo..
#HomeMain{
width: 100%;
float: left;
overflow:hidden;
margin:0 auto;
padding:5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
box-sizing:border-box;
}
#Entertainment, #Community{
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
box-sizing:border-box;
}
#welcome{
float: left;
width:50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px 5px 5px 5px;
font-weight: bold;
padding:15px;
box-sizing:border-box;
}
img{
display:block;
margin: 0 auto;
}

You forgot the the comma in the second rule and in order to make it right you have to use the box-sizing: border-box;.
#HomeMain {
width: 100%;
float: left;
overflow: hidden;
margin: 0 auto;
padding: 5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px;
box-sizing: border-box;
}
#Entertainment,
#Community {
float: left;
width: 25%;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px;
box-sizing: border-box
}
#welcome {
float: left;
width: 50%;
position: relative;
border-style: groove;
border-width: 3px;
border-color: white;
border-radius: 5px;
font-weight: bold;
padding: 15px;
box-sizing: border-box
}
<div id="HomeMain">
<div id="welcome">
<p>
Finest Booze around...
</p>
<div class="Oldman"></div>
</div>
<div id="Entertainment">
<img src="http://dummyimage.com/125x70" id="EntSlide">
</div>
<div id="Community">
<img src="http://dummyimage.com/125x70" id="ComSlide">
</div>
</div>

Check this fiddle
First of all it should be
#Entertainment,#Community{
and not
#Entertainment #Community{
next, why your divs arent aligning is because you are specifying a border of 3px each for the 3 divs which makes the divs to jump to the next line.So, here i've used box-sizing: border-box property for each of the divs.
Try it..

<div id = "HomeMain">
<div id="welcome">
Finest Booze around
</div>
<div id = "Entertainment">
Finest Booze around,
</div>
<div id = "Community">
Finest Booze around,
</div>
</div>
css use display property
#HomeMain{
width: 100%;
float: left;
overflow:hidden;
margin:0 auto;
padding:5px;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
display:block;
}
#Entertainment, #Community,#welcome{
width: auto;
border-style: groove;
border-width: 3px;
border-colour: white;
border-radius: 5px 5px 5px 5px;
background:#ccc;
display:inline-block;
}
fiddle
http://jsfiddle.net/tnmzo1gc/

You have a typo in the CSS
#Entertainment #Community{
should be
#Entertainment, #Community{
I hope it solves your problem:) If not, please elaborate on a question.

Related

Nested divs won't create a box inside a box?

I'm creating a section that spans 50% of the page. Within that section I would like to place a box of text containing two lines which will lineup with the bullet points on the list to the righthand side. Why is it not putting the box inside the main section if I nested the divs?
<div class="content">
<h2>Brigham Young University</h2>
<h3><span>Computer Engineering, Minor in Computer Science</span></h3>
<ul>
<li>3.36 GPA</li>
<li>4.0 STEM GPA</li>
</ul>
<div id="grad_date">
<p>Provo, UT <br>
Expected 2018</p>
</div>
</div>
The Css:
.content {
border-width: 3px;
border-style: solid;
border-color: black;
margin-left: 15px;
margin-right: 15px;
width: 50%;
}
.content #grad_date {
border-width: 2px;
border-color: red;
border-style: solid;
width: 100px;
float: right;
}
Add display: inline-block; to .content:
JS Fiddle
You need to change the display rule for the unordered list to inline-block.
Also make sure to clear the float by adding overflow: hidden to the .container div. Which is one way to do it.
.content {
border-width: 3px;
border-style: solid;
border-color: black;
margin-left: 15px;
margin-right: 15px;
width: 50%;
overflow: hidden;
}
.content ul {
display: inline-block;
}
.content #grad_date {
border-width: 2px;
border-color: red;
border-style: solid;
width: 100px;
float: right;
}
<div class="content">
<h2>Brigham Young University</h2>
<h3><span>Computer Engineering, Minor in Computer Science</span></h3>
<ul>
<li>3.36 GPA</li>
<li>4.0 STEM GPA</li>
</ul>
<div id="grad_date">
<p>Provo, UT <br />
Expected 2018</p>
</div>
</div>

Something like float:top?

I have this problem: http://jsfiddle.net/5bpwckot/
As you can see, if a div is larger than the other, the other gets down.
I'd like to keep the two divs in place, regardless of the top div..
I was wondering if I could do something like float:top;
Thanks :)
Here is the code:
HTML:
<div style="display:inline-block;">
<div id="halftitle" style="float:left;">Last posted threads</div>
<div id="halfbloc"> Thread
</br>by Username, 1 hour ago.</div>
</div>
<div style="display:inline-block">
<div id="halftitle" style="float:left;">Last users registered</div>
<div id="halfbloc">
<img style="float: left; height: 32px; width: 32px; margin-right:3px;" src="img/default.png">User3
</br>3 hours ago
<div class="sep"></div>
<img style="float: left; height: 32px; width: 32px; margin-right:3px;" src="img/default.png">User2
</br>3 hours ago
<div class="sep"></div>
<img style="float: left; height: 32px; width: 32px; margin-right:3px;" src="img/default.png">User1
</br>4 hours ago
</div>
CSS
#halftitle {
background-image:linear-gradient(to top, #0e75ba, #021c55);
padding: 2px 5px;
font-size: 13px;
font-weight: bold;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border: 1px solid #000;
color: white;
margin-left: 15px;
margin-right: 15px;
width:241px;
position:relative;
}
#halfbloc {
background-color: #f7fafb;
padding: 5px;
font-size: 13px;
margin-right: 15px;
margin-left: 15px;
border-left: 1px solid #000;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
margin-bottom: 8px;
width:241px;
clear: both;
position:relative;
}
/*ignore this*/
.sep {
margin-top:2px;
margin-bottom:2px;
border-bottom: 1px dotted #000;
}
just include vertical-align:top; to get this fixed
HTML
<div style="display:inline-block; vertical-align: top;">
Fiddle Demo

HTML Button Tag misaligned

('Boy... I saw on search that misalign topic about the <input> wrapped on an <a> tag... LOL)
Anyway...
I'm in a bit of a pickle here... I have a bunch of divs as an inline block lead by a lone <button>, and this lone button --- no matter how much design genius I summon from myself, I can't get to align properly.
Just look at the code at the end of the post.
Notes:
The button-holder class didn't used to exist; it was just the <button><span> combo. I added it thinking I can fix it by doing negative values on the margin (to no avail).
Can anyone advise?
FULL code:
<style type="text/css">
body { margin:0; padding:0;font-size: 9pt; }
#main { margin: 0; padding: 0; width:100%; text-align:center; }
#bar {display: table; margin: 0; padding: 0; width:100%; height:45px }
[class~=banner] { font-size: 14pt;
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
display: table-cell;
height: 45px;
vertical-align: middle;}
.cellOne { background-color:#FFC316;
color: #35549A;
width: 8%;
text-align:center;}
.cellTwo { background-color: #35549A;
color: #FFF;
padding: 0px 0px 0px 2%;
width: 68%;
text-align: left;}
.cellThree { background-color: #35549A;
color: #FFC316;
width: 12%;
text-align: left;}
#three_element {margin: 0 auto; padding:0% 18.5% 0% 18.5%; text-align:center; }
.button-holder {
width: 250px;
height: calc(250px / 1.604);
margin: -1.45% 1.5% -1.65% 1.5%;
display:inline-block;
padding:5px;
box-sizing:border-box;
}
#addbutton {
border-radius: 25px 25px 25px 25px;
-moz-border-radius: 25px 25px 25px 25px;
-webkit-border-radius: 25px 25px 25px 25px;
display:table;
border: 0px;
box-sizing:border-box;
padding:0px;
margin:0px;
background-color:#E6E7E8;
text-align:center;}
#addbutton .add {
display: table-cell;
font-size: calc(250px / 1.604 - 50px);
color: #384D94;
width: 240px;
height: calc(240px / 1.604);
vertical-align: middle;
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
[class~=objective-edit-tile] {
width: 250px;
height: calc(250px / 1.604);
margin: 1.5%;
display:inline-block;
box-sizing:border-box;
padding:5px;}
[class~=objective-edit-tile] div {
font-family:"Yanone Kaffeesatz","Arial Narrow",Arial,sans-serif;
box-sizing:border-box;
color:#FFFFFF;
margin:0px;
display:inline-block;
}
.tr-1-square-red div {background-color: #BE1E2D;}
.tr-1-square-yellow div {background-color: #E39F15;}
.tr-1-square-green div {background-color:#266733;}
.text-block-name {
border-radius: 25px 25px 0px 0px;
-moz-border-radius: 25px 25px 0px 0px;
-webkit-border-radius: 25px 25px 0px 0px;
border:#FFFFFF 1px solid;
width: 100%;
height: 66.7%;
font-size: 180%;
padding-top:17%;
}
.text-block-days {
border-radius: 0px 0px 0px 25px;
-moz-border-radius: 0px 0px 0px 25px;
-webkit-border-radius: 0px 0px 0px 25px;
border-top: #FFF 1px solid;
font-weight:700;
width: 34%;
height: 33%;
padding-top:6.5%;}
.text-block-next-step {
border-radius: 0px 0px 25px 0px;
-moz-border-radius: 0px 0px 25px 0px;
-webkit-border-radius: 0px 0px 25px 0px;
border-top: #FFF 1px solid;
font-size:9px;
width: 64%;
height: 33%;
padding:8% 2px 0px 1px;}
</style>
</head>
<body>
<div id="main">
<div id="bar">
<div class="banner cellOne">Pipeline</div>
<div class="banner cellTwo"> <Title> </div>
<div class="banner cellThree">PracticePipeline.com</div>
</div>
<div role="content" id="three_element">
<div class="button-holder">
<button id="addbutton" name="buttton">
<span class = "add">+</span>
</button>
</div>
<div class = "tr-1-square-red objective-edit-tile" id="tile-n">
<div class = "text-block-name" >GGN </div>
<div class = "text-block-days" > -10 Days</div>
<div class = "text-block-next-step" >Research GGN background </div>
</div>
<div class = "tr-1-square-yellow objective-edit-tile " id="tile-n">
<div class = "text-block-name" >GGN </div>
<div class = "text-block-days" > -10 Days</div>
<div class = "text-block-next-step" >Research GGN background </div>
</div>
<div class = "tr-1-square-green objective-edit-tile " id="tile-n">
<div class = "text-block-name" >Stark Indust.. </div>
<div class = "text-block-days" > 7 Days</div>
<div class = "text-block-next-step" >Invite Stark Industri.. </div>
</div>
</div>
</div>
</body>
I dont know if this is going to help much but it worked when i tried it.
The tag padding-bottom keep making a little bit higher if you want it to align better.
#addbutton .add {
display: table-cell;
font-size: calc(250px / 1.604 - 50px);
color: #384D94;
width: 240px;
height: 140px;
vertical-align: middle;
margin: 0px;
padding: 0px;
box-sizing: border-box;
padding-bottom: 7%
}
I actually solved my own problem:
The problem was just that I was over analyzing things. Basic lay-outing worked:
.button-holder {
margin:1.5%;
display:inline-block;
padding:5px;
box-sizing:border-box;
}
#addbutton {
border-radius: 25px 25px 25px 25px;
-moz-border-radius: 25px 25px 25px 25px;
-webkit-border-radius: 25px 25px 25px 25px;
width: 240px;
height: calc(250px / 1.604 - 10px);
border: 0px;
margin:0px;
padding: 0px;
background-color:#E6E7E8;
box-sizing:border-box;
text-align:center;
}
#addbutton .add {
font-size: 97px;
color: #384D94;
}

position of website elements

I have an issue with rendering my website for IE, Chrome and Opera. In Firefox the positioning works well:
while in the other browsers it looks like crap:
I have tried several positioning and padding options, but no luck. The problems appeared as I replaced the drop down menu with a jQuery replacement to enhance it graphically. The original dropdown is still there but with the css-option "display: none". I'd be thankful for a hint!
Here is the css:
This is the big blue box
.searchHomeForm a, .searchHomeForm a:hover {
color:#000000;
}
A invisible box around the three elements
div.searchHomeForm , .searchform {
height: 37px;
margin-left: auto;
margin-right: auto;
}
The white search bar
.search_bar {
position: inherit;
height: 25px;
letter-spacing: 0.02em;
line-height: 25px;
padding: 9px 0 0px 9px;
width: 390px;
border: 1px solid #95B6D6;
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.11) inset;
border-radius: 0.25em 0 0 0.25em;
}
the jQuery Dropdown replacement
#searchformReplacement {
background: #EBEBEB;
padding: 0px 1px 5px 0;
margin-bottom: 3px;
border-top: 1px solid #95B6D6;
border-bottom: 1px solid #95B6D6;
width: 109px;
position: inherit;
}
the find button
.find_button {
background: url("../images/lupevufindsearchsubmit1.png") no-repeat scroll #bBbBbB;
-moz-border-radius: 0.25em;
border-radius: 0 0.25em 0.25em 0;
position: inherit;
height: 36px;
line-height: 36px;
margin: 0px 0 3px -1px;
padding: 4px 10px 4px 10px;
width: 60px;
border-top: 1px solid #95B6D6;
border-right: 1px solid #95B6D6;
border-bottom: 1px solid #95B6D6;
border-left: none;
box-shadow: 2px 2px 5px rgba(76, 133, 187, 0.50) inset;
transition: all 0.2s ease-in-out 0s;
}
Try removing position: inherit from the .search_bar {}, #searchformReplacement {}and .find_button {} add display:inline-block for each
or add display:inline and float:left for each. You may have to clear floats if you use float:left
maybe use float: left; on the three elemetns next to each other?
I made you a little example to have the required position, I'm using the inline-block propriety (and I love it) :
Html
<div id="container">
<input type="text" class="inline-block" />
<div class="inline-block">
Your custom select
</div>
<button type="submit" class="inline-block">Search</button>
</div>
CSS
.inline-block {
display:inline-block;
*display:inline; /*IE hack*/
*zoom:1; /*IE hack*/
}
#container {
background:lightBlue;
width:300px;
margin:0 auto;
text-align:center;
}
See the working fiddle !
Yes, clearing your floats are important as madhushankarox has pointed out. But you don't always need to use floats, especially not in your case. Plus here's an extra bonus if you ever need to place your form into a liquid layout page. It should proportion itself out equally on most screens that are wide or thin.
CSS
/*the blue rounded box*/
#bluebox {
padding:3% 5%;
margin:0 25%;
background:#d0dcea;
border:solid 1px #b7c2d2;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
.fieldset-search {
text-align:center;
}
/*The white search bar*/
.input-search {
padding:5px;
margin:0;
width:50%;
vertical-align: baseline;
border: solid 1px #b7c2d2;
background: #fff;
outline: 0;
}
/*the jQuery Dropdown replacement*/
.list-search {
padding:4px;
margin:0 0 0 -5px;
}
/*the find button*/
.submit-search {
padding:4px 10px;
margin:0 0 0 -5px;
}
HTML
<div id="bluebox">
<div class="fieldset-search">
<input type="text" name="search" class="input-search">
<select name="list" class="list-search"><option></option></select>
<button type="search" class="submit-search">Go</button>
</div>
</div>

How to get rid of extra white space within a wrapper

As you can see on the example picture, there is some type of white space above the "news" header (padding? margin?) I have tried messing around with padding-top, margin-top but nothing I did would get rid of the white space. Thanks!
HTML:
<div id="news_wrapper">
<div id="newsheader">
<p>News</p>
</div>
<div class="news">
<p>"News Post 1"</p>
</div>
<div class="news">
<p>"News Post 2"</p>
</div>
<div class="news">
<p>"News Post 3"</p>
</div>
<div class="news">
<p>"News Post 4"</p>
</div>
</div>
CSS:
#news_wrapper {
border: 1px solid black;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
width: 650px;
height: auto;
margin: 6px;
}
#newsheader {
background-color: Black;
color: white;
width: auto;
margin: 0px;
height: 30px;
text-align: center;
font: 'Helvetica', sans-serif;
text-transform: bold;
}
.news {
display: block;
margin: auto;
text-align: center;
border: 1px solid black;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
margin: 4px;
}
add this to your css
#newsheader p{
margin:0;
}
I believe the issue is with your margin: auto
I generally use margin: 0 auto for this effect.