I'm currently trying to code my own portfolio website and struggling to position three text boxes. On my website I would like to have the boxes positioned left, centre and right on the page all in a line.
I have tried different things such as putting each text box in a separate div and trying to position them but they only position below and not next door to each other putting the css rule inline. I have also tried putting the boxes as a list and trying to inline them.
Any ideas?
Try this
<div id="con">
<div class="float">Hello</div>
<div class="float">World</div>
</div>
And the css
.float { float:left; width:100px; height:100px; background:yellow; }
Check JSFiddle here
Maybe this
.foo
{
float: left;
width: 33%;
}
Your html is smth like this:
<div></div>
<div></div>
<div></div>
And the css:
div{width:30%;margin:1%;border:1px solid blue; float:left; height:100px;}
Here is an example:http://jsfiddle.net/795T4/.
have some html like this
<ul class="portfolio">
<li><input id="txtBox1" type="text"></li>
<li><input id="txtBox2" type="text"></li>
<li class="last"><input id="txtBox3" type="text"></li>
</ul>
and css along the lines of
.portfolio{
margin:10px auto;
width:1000px
}
.portfolio li{
float:left;
display:block;
width:330px;
height:200px;
background-color:#e4e4e4;
margin-right:15px
}
.portfolio .last{
margin-right:0
}
this is based on a fixed width site, and i'd use an Unordered List <ul> because semantically you have a list of 3 boxes.
Related
I'm making a form with two input area, the second area should be content editable div somehow.
I want to make the #topic_title_input sitting above the #topic_content_input with the same width. It could be easily achieved by giving them display:inline-block, But for some complicated reason, I can't change the display-inline property of the second input area
Any idea how to make the #topic_title_input sitting above the #topic_content_input?
html
<div class="left_container">
<input id="topic_title_input" >
<div id="topic_content_input" contenteditable="true" ></div>
</div>
<div class="right_container">
</div>
<div class="clear_float">
</div>
css
#topic_title_input{
width:521px;
}
#topic_content_input{
/*do not change the display:inline */
width:521px;
display:inline;
background-color: orange;
border: solid 1px black;
}
/*do not change the css below*/
.left_container{
position:relative;
float:left; width:50%;
}
.right_container{
position:relative;
float:right; width:50%;
}
</style>
I had three divs inside a main div with id main_div and has css already as below
<div id="main_div" style="height:10px; line-height:50px; margin-top:1px; position:relative;>
</div>
I just want to insert three divs in the main div as below
<div id="main_div" style="height:10px; line-height:50px; margin-top:1px; position:relative;>
<div>
Div One should be Left(breadcrumb_text)
</div>
<div>
Div Two should be Center(dropdownlist)
</div>
<div>
Div Three should be Right(Pagination)
</div>
</div>
So i want the div format to display the text like
breadcrumb_text dropdownlist Pagination
I tried with different css by using position attribute and various css options but could n't able to align them in a horizontal line with one div as left , one div as center and other div to right.
So can anyone let me know me know the css to place them in an horizontal line ?
This maybe help you Fiddle
#main_div > div {
width: 33%;
float: left;
}
I have modified your code little bit with spacing equally for each div and removed Position in the Main div.
Sometimes position will overlap with other div (position) based on z-index value. so if you really need use position unless not required.
#main_div{
height:10px; line-height:50px; margin-top:1px;
box-sizing:border-box;
}
#main_div > div{
width:31.1%;
float:left;
box-sizing:border-box;
border:1px solid grey;
margin-right: 10px;
display:inline-block;
}
#main_div > div:first-child{
margin-left:10px;}
<div id="main_div">
<div>
Div One should be Left(breadcrumb_text)
</div>
<div>
Div Two should be Center(dropdownlist)
</div>
<div>
Div Three should be Right(Pagination)
</div>
</div>
I think this is what you are asking for
JSFiddle
CSS
body
{
margin:0%;
}
.main_div
{
display:block;
margin:0% 5%;
width:90%;/*Just random, modify as per your requirement*/
height:300px; /*Just random, modify as per your requirement*/
background:#eee;
position:relatve;
}
.left-div, .center-div, .right-div
{
display:inline-block;
height:100%;
position:relative;
float:left;
width:33%;
border:1px solid #000;
text-align:center;
padding-top:5px;
}
HTML
<div class="main_div">
<div class="left-div">
Div One should be Left(breadcrumb_text)
</div>
<div class="center-div">
Div Two should be Center(dropdownlist)
</div>
<div class="right-div">
Div Three should be Right(Pagination)
</div>
</div>
Unnecessary white space is added to my nested divs in between .boxwrap and .lsmlbox + .rsmlbox which is making it impossible to line up .smlbox + .rsmlbox with .box
I believe this is a much more difficult problem to solve than expected?
I would like for the "inner" (referring to center of screen) margins of .lsmlbox and .rsmlbox to be dependent on screen size, but I would like the outer borders to always remain "sticky" to .boxwrap so that when the screen size changes the boxes only get narrower but remain lined up to the full sized .box div above it.
.box
{
margin-left:5%;
margin-right:5%;
margin-bottom:80px;
}
.boxheader
{
font-size:17pt;
letter-spacing:3px;
padding-bottom:10px;
text-transform:capitalize;
}
.boxcontent
{
text-align:left;
border: 1px dotted #000000;
border-top: 0px;
border-bottom: 0px;
padding-left:15px;
padding-right:15px;
letter-spacing:3px;
}
.boxwrap
{
margin:0 5%;
}
.lsmlbox
{
display:inline-block;
max-width: 30%;
margin-bottom:80px;
margin-right:4%;
vertical-align:top;
}
.rsmlbox
{
display:inline-block;
max-width:30%;
margin-bottom:80px;
margin-left:4%;
vertical-align:top;
}
HTML:
<div class="box">
<div class="boxheader">SLDKFJSDLFKJSDLKJF.</div>
<div class="boxcontent">
SDFSDFLSDFSDFLKJ
</div>
</div></div>
<div class="boxwrap">
<div class="lsmlbox">
<div class="boxheader">Meet the Owner</div>
<div class="boxcontent">SDFSDFSDF</div></div>
<div class="rsmlbox">
<div class="boxheader">Your Best Source Since 1977</div>
<div class="boxcontent">
SDFSDFSDFSDFSDF
</div></div>
</div>
Edit: got rid of floating divs but now I'm in a deeper problem.
it really depends on what you want it for, but you could use:
display: inline-block;
on each item you want on the same line
You can also use position:absolute;. For your case just remove the float in both .lsmlbox and .rsmlbox and put this in your .rsmlbox:
.rsmlbox
{
position:absolute;
top:8px;
left:700px;
margin-right:20%;
width:27.5%;
margin-bottom:80px;
}
Hope this helps!
You can use float without breaking your layout by wrapping your code in a container.
CSS
.clearfix {
position:relative;
}
.clearfix:after {
content: " ";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
HTML
<div class="clearfix">
<div class="lsmlbox">
<div class="boxheader">Meet the Owner</div>
<div class="boxcontent">
SDFSDFSDFSF
</div></div>
<div class="rsmlbox">
<div class="boxheader">Your Best Source Since 1977</div>
<div class="boxcontent">
SDFSDFSDFSDF
</div></div>
</div>
It depends. In some cases float is good.
In some - inline-block. I personally like inline-block.
You can read more about it here http://css-tricks.com/fighting-the-space-between-inline-block-elements/
http://jsbin.com/qikubuce/1/edit?html,css - sample
Yes, display-block is the better way to go. Float was originally intended for images.
Here is a fiddle that demonstrates using inline-block
I have added a class name of box for the two boxes, and changed their current class names to ID's instead:
.box{display:inline-block;}
#lsmlbox{}
#rsmlbox{}
By using one class name for the two boxes will help reduce the need to write duplicate rules.
Another thing you may want to do, is change the inner <div>'s to paragraphs instead. You could then define a standard rule for them using the following css:
.box p{padding:10px;color:#333;etc....}
Here's an updated fiddle demonstrating that.
Hope this helps.
I need to center align the yellow boxes (no matter how many are they) inside the blue container. The yellow boxes can go down on the 2nd (or 3rd row, etc) if they are many but they should remain center aligned inside the blue container. Any ideas how to do it?
HTML
<div id="container">test
<br />
<div class="box">foo bar</div>
<div class="box">foo bar</div>
<div class="box">foo bar</div>
<div class="box">foo bar</div>
</div>
CSS
#container {
background:lightblue;
width:100%;
}
.box {
width:10em;
float:left;
background:yellow;
margin:1em;
}
http://jsfiddle.net/585Eq/
Remove the float on the divs and replace it with display:inline-block. Add a text-align:center rule to the container div:
#container {
background:lightblue;
width:100%;
text-align:center;
}
.box {
width:10em;
display:inline-block;
background:yellow;
margin:1em;
}
jsFiddle example
Change your css to following:
#container { background:lightblue; width:100%;text-align:center }
.box { width:10em; display:inline-block; background:yellow; }
I dont know if you use auto margin will work.. but i recommend you to deal with it as a menu. It will work just like a div. Im showing you this way because thats the way im sure it works.
<ul id="container">test
<br />
<li class="box">foo bar</li>
<li class="box">foo bar</li>
<li class="box">foo bar</li>
<li class="box">foo bar</li>
</ul>
the CSS:
#container {
text-align: center;
height: <-- Specify a fixed height.
}
#container li {
display: inline-block;
margin-right: 30px; <-- This will the the margin between the items
list-style-type: none;
}
Thats what you want? Or you want that all the yellow boxes be automatically adjusted inside the blue div?
You may try with display:inline-block;
Change your CSS like:-
#container {background:lightblue;width:100%; text-align:center;}
.box {width:10em; display:inline-block; background:yellow; margin:1em;
}
DEMO JSFIDDLE
JSFIDDLE
HTML:
<div class="SummaryTable">
<div class="AddressContainer">
<div class="Address">
<b>Ship To: </b>
<ul>
<li>John Smith</li>
<li>45 Holland drv.</li>
</ul>
</div>
<div class="Address">
<b>Bill To: </b>
<ul>
<li>John Smith</li>
<li>P.O Box 456</li>
</ul>
</div>
</div>
</div>
CSS:
.SummaryTable
{
width: 650px;
text-align:center;
}
.SummaryTable .AddressContainer
{
width:650px;
}
.SummaryTable .Address
{
width:323px;
background-color:Yellow;
float:left;
border: 1px solid black;
height:200px;
}
.Address ul
{
width:130px;
min-width:130px;
max-width: 280px;
margin-left:auto;
margin-right:auto;
background-color:Green;
text-align:left;
padding:0px;
}
.Address li
{
list-style-type: none;
}
JSFIDDLE
I want to keep the green box\element (ul) centred in the 323px wide/200px or Auto high (.Address) layer both horizontally and vertically.
I have achieved horizontal centering of <ul> by setting fixed width + margin:0px auto, but addresses vary in length and I don't just want some fixed size box where one longer address would appear centred under (Ship To\Bill To) heading and another shorter one will look out of place since text is aligned to the left.
I want to see the text in the <li> stretch to the <ul> green box up to the maximum-width setting (e.g 280px) and the green box, whatever its size will be to remain centered horizontally and vertically in the .Address layer and consequently under the Ship To\Bill To headings.
Main reason for this is that shorter addresses would look offset to the left in a fixed width ul element and if I make the width small than a line break would ensue for longer address, spreading the first and last name and or address over two lines. Using centrally aligned text in the ul element
-Of course solves this problem, but I need left aligned text.
DEMO jsBin
If I understood well your question
Here is the modified CSS:
.SummaryTable{
width: 650px;
text-align:center;
}
.AddressContainer{
width:650px;
}
.Address{
width:323px;
background-color:white;
float:left;
border: 1px solid black;
height:200px;
}
.address b{
display:block; /*should do the trick*/
}
.Address ul{
display:inline-block; /*should do the trick*/
background-color:orange;
text-align:left;
padding:0px;
}
.Address li{
list-style-type: none;
}
I removed some margin-reft/right:auto, widths, min-width, max width and formatted a bit your .summaryTable css 'appearances'. Than a bit of playing with display property have done the trick.
Here is a demo using jQuery : demo jsBin with jQ