I'm trying to figure out why contact and disclaimer divs are ignoring the left margin.
http://jsfiddle.net/RLdYC/4/
HTML:
<!-- Package 1 -->
<div class="package2">
<div class="pkgtop">
<div class="pkgtype"> <span id="ratings">SINGLE PANEL</span> </div>
<div class="pkgcost"><sup class="dolladollabill">$</sup><span id="cost">4,100</span></div>
<center><div class="pkglength">PER FOUR WEEKS</div></center>
</div>
<div class="pkgbottom">
<div class="pkgselect">Select Plan</div>
<ul class="pkgdesc">
<li><span id="panelnum">1</span> Panels</li>
<li><span id="impressions">400K</span> Impressions</li>
<li>Reach: <span id="reach">15.2%</span> </li>
</ul>
</div>
</div>
<div class="contact">why are you ignoring the left margin?</a></div>
<div class="disclaimer">disclaimer</div>
If you inspect the layout using the Inspector in firefox or firebug you can see that a margin of 15 is applied to the contact div. However the left half of the contact div with the margin is hidden behind the floated package2 div and the text in the contact div is just pushed over.
If you want to have the whole div lined up next to the package2 div then you can do as Micallef suggested and use float:left on the contact/disclaimer div(s).
You can also change to use table layout (display:table-row, display:table-cell) if you do not want the contact/disclaimer to drop down underneath the package2 when the view width is not wide enough.
.package-row {
display: table-row;
}
.package2 {
...
display: table-cell;
}
.contact {
...
display: table-cell;
}
.disclaimer {
...
display: table-cell;
}
http://jsfiddle.net/AJw7x/1/
Adding float:left will solve the problem - jsfiddle
.contact{
margin-left:15px;
color:#000;
font-size:16px;
line-height:16px;
height:auto;
float:left;
}
.disclaimer{
margin: 15px 15px 15px 15px;
color:#939292;
line-height:15px;
font-size:14px;
height:auto;
float:left;
}
Related
Well, I coded this page, but I got stuck at why does the third column is pushing down my text (or other elements). It uses the same style from the first box, but while the first box is ok, the third one is pushing the elements down by some pixels.
Like this:
HTML
<div id="contentWrapper">
<div id="sideBar">
<div class="sidebarBox"></div>
<div class="sidebarContent">
<h4>
Índice
</h4>
<ul class="tree">
<li>
Sinopse
</li>
<li>
Tropas
</li>
<li>
Geladeira
<ul>
<li>
Lógica
</li>
<li>
Gênio
</li>
<li class="last">
Horror
</li>
</ul>
</li>
<li>
Notas
</li>
<li>
Mídia
</li>
<li class="last">
Referências
</li>
</ul>
</div>
</div>
<div id="mainBody"></div>
<div id="infoBar">
<div class="sidebarBox"></div>3º Column
</div>
</div>
CSS
* {
margin:0;
padding:0;
font:normal normal 14px/20px Helvetica,Arial,sans-serif
}
h4 {
font-size:14px;
font-weight:700;
text-transform:uppercase;
padding-top:10px;
border-bottom:2px solid #2a558c;
margin-bottom:10px
}
#contentWrapper {
display:table;
border-spacing:0;
width:100%;
height:500px
}
#contentWrapper > div {
display:table-cell
}
#sideBar {
background-color:#E4E5DD;
width:200px
}
#mainBody {
background-color:#EEEEE6
}
#infoBar {
background-color:#e4e5dd;
width:200px
}
#footer {
background-color:#323540;
height:50px
}
.sidebarBox {
background-color:#323540;
height:30px;
width:100%
}
.sidebarContent {
padding:15px
}
I messed a lot with the Firebug and even tried to open it in IE and Chrome, with same results. Both columns use the same CSS, and this difference is freaking me out. I thought about "fixing" it with some negative margins, but I want to understand the problem first, insted of "workahacking" away.
Thanks a lot in advance!
Add vertical-align: top to #contentWrapper > div. Currently it is baseline.
Have a fiddle!
CSS
#contentWrapper > div {
display: table-cell;
vertical-align: top;
}
Without vertical-align: top, the div is basing its vertical alignment on .sidebarContent which has 15px of padding. This is resulting in the 15px gap.
Change the following and it should fix your problem. I've found that when using display:table-cell it always mis-aligns the last cell unless I specifically give it a vertical alignment
#contentWrapper > div {
display: table-cell;
vertical-align:top;
}
Example
Add display:inline-block to this class:
.sidebarBox {
background-color: #323540;
height: 30px;
width: 100%;
display: inline-block;/*Add this*/
}
fiddle
.sidebarBox {
float:right;
}
will work.
I'm trying to sort HTML elements. Basically, I would like to set UL LI menu (inline) to the right side, and the INPUT on the left to take all the remaining space, not to be fixed, and all that in 1 line. 3 LI elements, take just as many space as it needs (minimum, not fixed couse i might add some elements), and INPUT take everything else as far as it can (100% of whats left in line) .
I tried with various display: block, inline, inline-block, table, table-cell (with this I almost succeeded), float left, right, and i can't set it without putting fixed width on something...
<main>
<div id="searchBar">
<form>
<input id="searchInput"/>
</form>
<ul id="searchOptions">
<li></li>
<li></li>
<li></li>
</ul>
</div>
</main>
maybe to put some margins, overflows, hacks?
please help!
Like this, maybe?
ul {
list-style-type: none;
display: table-cell;
width: 1px;
padding:0 0 0 5px;
}
form {
display:table-cell;
width:100%;
}
li {
display:table-cell;
white-space: nowrap;
padding:0 5px
}
input {
width:100%;
}
Answer from Alohci is what I was looking for! I solved it like this:
<main>
<div id="searchBar">
<div id="searchText">
<form>
<input id="searchQuery" />
</form>
</div>
<div id="searchOptions">
<ul>
<li>Cla</li>
<li>Res</li>
<li>Pro</li>
</ul>
</div>
</div>
</main>
main div#searchBar {
display:table;
width:100%;
}
main div#searchText {
display:table-cell;
width:100%;
}
main div#searchOptions {
display:table-cell;
width:100%;
}
main input#searchQuery { width:100%; }
main ul { display:table; }
main ul li { display:table-cell; }
main ul li a { display:table-cell; }
I've created more divs around elements, and make main div as table, and those divs as cells, and after that UL as table and LI's as cells... I guess before it didn't work as FORM and INPUT was not in div, and wasn't able to fill 100% up to UL...
But Alochi gave me more compact version of this, THNX!
I'm trying to create something that looks like this:
so far I have: http://jsfiddle.net/ePse6/
Without using something like: margin-top:-25px;, how can I position the Edit/Delete links to be on the right of the title (the part that says "iPhone" or "Android") and have both the title and links halfway between the borders?
Thanks!
just like most of answers, here i come with text-align:right and float:left .
I reduced code to minimal and plain CSS for your actual structure and to make it clear to you : http://jsfiddle.net/ePse6/7/
ul , a { /* basic reset we need */
padding:0;
margin:0;
color:gray;
text-decoration:none;
}
.mini > ul > li {
display:block;/* reset from list-item */
border-bottom:solid;
text-align:right;
overflow:hidden;/* wraps floatting element within */
}
.mini > ul > li> h3 {
float:left;
margin:0;
}
.mini > ul > li ul,
.mini > ul > li li {
display:inline-block;
}
Why not use something simple and really handy?
I have removed all of your messy code, and have created a new fiddle for you.
http://jsfiddle.net/afzaal_ahmad_zeeshan/ePse6/4/
I have used just a few lines of code, I have used a div and inside that, I have used 2 paragraphs to seperate each of them. Then inside that I used span element to seperate the right and left floating elements.
Using CSS I selected the classes and then styled them to get the desired input!
Here is the code:
<div>
<p>
<span class="left">Android</span><span class="right">Delete Edit</span>
</p>
<p>
<span class="left">iPhone</span><span class="right">Delete Edit</span>
</p>
</div>
CSS is as:
p {
border: 1px solid #333; // border that you wanted!
padding: 20px; // padding all around the element
padding-bottom: 40px; // padding at the bottom of the element
}
.left {
float: left; // making the elements float at the left
}
.right {
float: right; // floating elements at the right side
}
You can go to the fiddle page, and check for the design of the layout now. It was a simple thing. Hope its what you wanted.
This is without the lists. Just some CSS to do the trick: http://jsfiddle.net/Lg96p/
CSS:
.wrap{
width:100%;
border-bottom:solid 1px #666666;
margin-bottom:20px;
padding-bottom:10px;
}
.title{
font:bold 16px arial;
}
.fl{
float:left;
}
.fr{
float:right;
}
.lnk{
color:#6c6c6c;
display:inline-block;
text-align:right;
margin:0 10px 0 0;
text-decoration:none;
font:normal 14px arial;
}
HTML:
<div class="wrap fl">
<div class="title fl">iPhone</div>
<div class="fr"><a class="lnk" href="">Edit</a><a class="lnk" href="">Delete</a></div>
</div>
<div class="wrap fl">
<div class="title fl">Android</div>
<div class="fr"><a class="lnk" href="">Edit</a><a class="lnk" href="">Delete</a></div>
</div>
You should create two columns that fill the parent div. Make them both float:left; and for the right column you can align the text to the right text-align:right; or put two divs in it with float:right; for edit and delete.
Here is my fiddle: http://jsfiddle.net/ePse6/5/
Whatever you put into the columns or how to format it is up to you. But from here you have 2 columns independently next to each other.
If you want multiples of these stacked on top of each other i would change the container to a class and just add multiple of these containers with the columns to keep it tidy and readable. Like in this fiddle: http://jsfiddle.net/ePse6/6/
HTML:
<div class='container'>
<div class='leftCollumn'>
Iphone
</div>
<div class='rightCollumn'>
<a hreft="">Edit</a><a hreft="">Delete</a>
</div>
</div>
<div class='container'>
<div class='leftCollumn'>
Iphone
</div>
<div class='rightCollumn'>
<div class="button">Edit</div><div class="button">Delete</div>
</div>
</div>
CSS:
.container
{
width:600px;
margin:auto;
}
.leftCollumn
{
float:left;
width:400px;
background-color:#999;
}
.rightCollumn
{
float:left;
width:100px;
text-align:right;
background-color:#CCC;
}
.rightCollumn a
{
margin-left:10px;
margin-right:5px;
}
.button
{
margin-left:10px;
margin-right:5px;
background-color:#000;
color:#FFF;
float:right;
}
I am trying to position a text in the middle height of an image, but the margin-top or margin-bottom would not work as I want.
Any tips on this?
I created an JsFiddle to show the work -
http://jsfiddle.net/HdW7Y/1/
As you see the the text Login User is below the login button.
HTML
<div id="topNav">
<ul>
<li class="topMenu-bg1 show_hide_contact">
</li>
<li class="topMenu-bg2 show_hide_login">
User Login</p>
</li>
</ul>
</div>
CSS
#topNav li {
margin-top:5px;
padding-top:7px;
list-style:none;
float:left;
border-right:1px solid black;
}
.icon2text{
font-weight: bold;
font-size: 0.7em;
display: inline;
}
You can use the vertical-align property on .icon2text and set it to top:
http://jsfiddle.net/HdW7Y/2/
Add
.topMenu-bg2 show_hide_login{
valign:middle;
}
If you replace the p tag with a span and remove the top padding from the li item and the top padding from the a tag it should all line up.
I have a nav bar that displays fine when I have 5 navigation objects in it but when I add 3 more it drops below the main header why?
5 Objects:
7 Objects:
HTML:
<div id="header">
<div class="w960">
<div id="logo">
<h2>Text</h2>
<p>Text</p>
</div>
<nav>
<ul>
<li class="first active">
1
</li>
<li>
2
</li>
<li>
3
</li>
<li>
4
</li>
<li class="last">
5
</li>
</ul>
</nav>
</div>
</div><!-- end of header -->
CSS:
#header{background:#2d2d2f;width:100%; height:120px;clear:both;font-family:Signika,Arial,sans-serif;}
.w960 { width:960px; margin:auto; }
nav{width:auto; float:right;line-height: 50px;}
nav ul li{font-size:14px; float:left;display: inline-block;padding: 0px 11px;text-transform:uppercase;}
nav ul li a{padding: 0px 10px; color:#ffb400; text-decoration:none;}
nav ul li a:hover, .active a{color:#fff}
#logo{width: 40%;float: left;height: 90px;}
#logo h2{line-height: 41px;color:#FFB400;font-size:28px;}
#logo h2 span{color:#FFB400;}
#logo p {margin-top: -25px;color:#b8bbbc;}
You have two floating elements in the same line, if the sum of both width and they are bigger than the available space, they will break the line and place the second floating element below the previous: in your case nav below logo. Add borders to each of them and you will see that they are just too big.
One alternative is this: http://jsfiddle.net/Bs93k/
nav{width:auto; /*float:right;*/ overflow:auto; line-height: 50px;}
This will make nav to take the available space, however, I don't think its contents would behave as you like.
A second alternative is this: http://jsfiddle.net/PU7hV/
#header{display:table;}
.w960 {position:relative;}
nav{/*float:right;*/ position:absolute; top:0; right:0;}
Note that i wrote what you have to add and commented what to delete, the rest, leave them as you already had.
If you mean to ask why the background of the header container does not appear behind the links, it's because of the floated lis.
You will need to add a clearfix class.
.clearfix:before,
.clearfix:after {
content: "";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
And apply that class to your header:
<div id="header" class="clearfix">
If you mean why do they break down a line at all, it's because of the fixed width on the <div class="w960"> container.
.w960 { width:960px; margin:auto; }
As long as you have no dropdown submenu I'd recommend to use overflow: hidden.
nav ul {
overflow: hidden;
}
If you can not change the HTML (for example you don't have access to the script which outputs the HTML) adding clearfix, you could just change the CSS like that:
#header {
background: none repeat scroll 0 0 #2D2D2F;
clear: both;
float: left;
font-family: Signika,Arial,sans-serif;
height: auto;
width: 100%;
}