css div height auto not wrapping properly - css

I have a wrapper called #sub-menu and which is displayed in yellow in the here below cssdesk file. I set its height at auto but unfortunately it is not wrapping all its content properly. This issue is driving me crazy. Hope someone can help. Thank you in advance for your replies. Cheers. Marc.
http://cssdesk.com/AVpjR

Add overflow:auto; to your #sub-menu
See: http://cssdesk.com/qBUdf

The floating elements are what disrupts the height. You need to add a new div that will clear all floating elements for the height of the parent container to fill the full length.
HTML:
<div id="sub-menu">
<div id="form-loc">
<a id="appliquer-loc" class="button white">filtrer</a>
<div id="saisi-loc">
<input id="input-loc" type="text"/>
<a id="valider-loc" class="button white">valider</a>
<a id="supprimer-loc" class="button white">supprimer</a>
<span id="msg-loc">Valeur saisie incorrecte</span>
</div>
</div>
<div id="proposition-loc">
<a id="proposer-loc" class="button white">+ Proposer une sortie</a>
</div>
<div class="clear"></div>
</div>
CSS:
#sub-menu{
width:960px;
height:auto;
margin-left:auto;
margin-right:auto;
background-color:yellow;
}
#form-loc{
width:800px;
height:auto;
float:left;
position:relative;
background-color:rgba(1,1,1,0.2);}
#saisi-loc{
background-color:rgba(123,123,123,0.2);
width:auto;}
#input-loc{
width:300px;
height:25px;
border:1px solid gray;}
#msg-loc{
font-size:14px;
padding:0 10px;
font-weight:bold;
background-color:pink;}
#proposition-loc{
text-align:right;}
.clear {
clear: both;
}

Related

how to hide image left part of image when using overflow hidden

I am new to CSS programming . Using overflow:hidden for hiding image greater than DIV area. Perhaps I want hidden part of image should be in the left part, but currently its taking right part. My code follows as below.
Html code:
<div class="a1">
<img src="img/image4.jpg">
</div>
CSS:
.a1{height:200px;width:100px; overflow:hidden;}
Try this (notice the direction: rtl;):
.a1 {
height:200px;
width:100px;
overflow:hidden;
direction: rtl;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b">
</div>
.a1 {
height:200px;
width:100px;
overflow:hidden;
background:#ff0;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b">
</div>
Seems to work fine for me. I added the yellow background to show where the DIV is at and linked to an SO sprite.
If you're getting a different effect, then it's quite likely the CSS on your page elsewhere which is cascading and causing the conflict.
Side note: Writing a stylesheet in CSS is not really called "programming". :)
Click Run code snippet to see this in action.
Or, for the converse:
.a1 {
height:200px;
width:100px;
overflow:hidden;
background:#ff0;
}
<div class="a1">
<img src="http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b" align="right">
</div>
.a1 {
height:200px;
width:100px;
overflow:hidden;
direction: rtl;
}
<div class="a1">
<img src="https://www.google.com.pk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">
</div>
use float:right for image element
<div style="width:200px; height:200px; overflow:hidden">
<img style="float:right" src="url" />
</div>

make the div stay even when click

I wanted to change div content between clicking 2 links.
I solved it but upon clicking on the 2nd link, if you click on other spaces it will return to the default div. basically what i want is when you click on the second link, and when you click on the space around it, it would not return to previous link! Can anyone help me solve this?
JSFiddle example
CSS:
#button1 {position:fixed;top:120px;left:150px;}
#button2 {position:fixed;top:120px;left:290px;}
#button1:focus~#content #default,
#button2:focus~#content #default
{display:none;}
#button1:focus~#content div:nth-child(2),
#button2:focus~#content div:nth-child(3) {display:block;}
#content {
border:1px dashed black;
width:800px;
height:auto;
position:fixed;
left:150px;
top:150px;
background-color:#E2E2E2;
color:black;
font-size:10px;
text-align:center;
}
#percent,#dollar {display:none;}
#default,#percent{
width:800px;
height:499px;
background-image:url(images/image2.jpg);
}
#dollar{
width:800px;
height:499px;
background-image:url(images/image1.jpg);
}
.bar1{
width:54px;
height:138px;
margin-left:102px;
padding-top:110px;
}
HTML
<a id="button1" href="#" tabindex="1">View in Percentage</a>
<a id="button2" href="#" tabindex="2">View in Absolute Dollar</a>
<div id="content">
<div id="default">
<div class="bar1">
<img src="images/trypic/bar1.jpg" onmouseover="this.src='images/trypic/bar1_percent.jpg'" onmouseout="this.src='images/trypic/bar1.jpg'" /></div>
</div>
<div id="percent">
<div class="bar1">
<img src="images/trypic/bar1.jpg" onmouseover="this.src='images/trypic/bar1_percent.jpg'" onmouseout="this.src='images/trypic/bar1.jpg'" /></div>
</div>
<div id="dollar">dollar content will go here.</div>
</div>
try this
html
<div id="main">
<a id="button1" href="#" tabindex="1">View in Percentage</a>
<a id="button2" href="#" tabindex="2">View in Absolute Dollar</a>
<div class="content_one">
percentage viewed
</div>
<div class="content_two">
Absolute dollar viewed
</div>
</div>
css
*
{margin:0;
padding:0;
}
#main
{width:1000px;
margin:0 auto;
}
.content_one
{width:500px;
height:300px;
background:#CCC;
position:absolute;
}
.content_two
{width:500px;
height:300px;
background:#333;
position:absolute;
z-index:-1;
}
js
$("#button1").click(function() {
$(".content_two").hide();
$(".content_one").show();
});
$("#button2").click(function() {
$(".content_one").hide();
$(".content_two").show();
});
Try a little bit of javascript and avoid the css~focus. Fiddle Link. You can use plain javascript to achieve this. No need for extra libraries or anything. Once I removed the focus, the issue of changing the div was solved.
refer the following code
View in Percentage
View in Absolute Dollar
<div id="content">
<div id="percent">
<div class="bar1">
<img src="images/trypic/bar1.jpg" onmouseover="this.src='images/trypic/bar1_percent.jpg'" onmouseout="this.src='images/trypic/bar1.jpg'" /></div>
</div>
<div id="dollar">dollar content will go here.</div>
</div>
script
function show1(){
document.getElementById('percent').style.display = 'block';
document.getElementById('dollar').style.display = 'none';
}
function show2(){
document.getElementById('percent').style.display = 'none';
document.getElementById('dollar').style.display = 'block';
}
css
#button1 {position:fixed;top:120px;left:150px;}
#button2 {position:fixed;top:120px;left:290px;}
#content {
border:1px dashed black;
width:800px;
height:auto;
position:fixed;
left:150px;
top:150px;
background-color:#E2E2E2;
color:black;
font-size:10px;
text-align:center;
}
#dollar {display:none;}
#percent{
width:800px;
height:499px;
background-image:url(images/image2.jpg);
}
#dollar{
width:800px;
height:499px;
background-image:url(images/image1.jpg);
}
.bar1{
width:54px;
height:138px;
margin-left:102px;
padding-top:110px;
}

CSS IE issue with having two divs in one line

I have got the following code working fine on FF. As you can guess, I want the following two divs stays on one line without breaking when browser resize.
<div style="float: left; margin-right: 10px; ">
</div>
<div style="overflow: hidden;">
</div>
But as per usual, when I tested the page with IE 9, the right div was already below the left one.
Can someone pls help me out here, thanks,
Either add "float:right" in your second div or
add "width:XXpx" into your first div.
Wrap it with another div
<div>
<div style="float: left; margin-right: 10px; ">
</div>
<div style="float:right; overflow: hidden;">
</div>
</div>
you also float the other div
<div style="float: left; margin-right: 10px; ">
</div>
<div style="float:right; overflow: hidden;">
</div>
==========================================================>>>
UPDATE
HTML
<div class="marginRight"></div>
<div></div>
CSS
div {
float:left;
border:1px solid red;
width:45%;
height:100px;
}
.marginRight {margin-right: 10px;}
WORKING DEMO
it is working fine
if you want more configuring
<div style="display:table-row;">
<div style="width:49%; margin-right:2%; height:100px; float:left; display:table-cell;"> any thing you wanted </div>
<div style="width:49%; height:100px; float:left; display:table-cell;"> any thing you wanted </div>
</div>
Use a container div and set the two divs to either % of total width or total px of the page.
#containerdiv {
width:100%;
overflow:hidden;
}
#leftdiv {
width:20%;
overflow:hidden;
float:left;
#rightdiv {
width:80%;
overflow:hidden;
float:left;
}
<div id="containerdiv">
<div id="leftdiv"> TEST </div>
<div id="rightdiv"> TEST </div>
</div>
Remember if you use margins and paddings you will need to adjust the percentages or pixels for it to line up next.
For example. If you add padding 1% to left div, it will push the right div down to second line since you are now at a total of 101% of the container divs width.

css float and border problem

I got this css:
.post-user {
background:black;
color:white;
width:auto;
float:left;
}
.img-side {
border-style:solid;border-width:medium;width:75px;margin-bottom:2px;
}
.top-head {
background:cyan;
width:100%;
height:20px;
display:block;
}
.main-box {
border-style:solid;
border-width:1px;
display:block;
height:auto;
}
And html looks such :
<div class="main-box">
<div>
<div class="top-head"><span>At top</span>
</div>
<div class="side">
<div class="img-side">
<img src="http://st2.gsmarena.com/vv/pics/htc/htc-snap-1.jpg" width="75px" height="75px" />
</div>
<div class="post-user">User name</div>
</div>
</div>
</div>
demo
But the div post-user is going outside the border.
How can i fix it ?
(P.S. : Its something similar to layout of forums)
http://jsfiddle.net/PGFTz/5/ I added a clear fix after post-user which allows it to stay within the box.
add overflow:hidden to your .main-box css
extensive explenation about how and why it works can be found here
http://www.quirksmode.org/css/clearing.html
A great guide for the working of float can be found here:
http://www.alistapart.com/articles/css-floats-101/
You could change float:left to text-align:left
.post-user {
background:blue;
color:white;
width:auto;
/*float:left;*/
text-align:left;
}
That worked for me =)

few styling problems

http://img263.imageshack.us/img263/6803/32007451.jpg http://img263.imageshack.us/img263/6803/32007451.jpg
I have two problems with my friendlisting box.
1. Images are set 100px in width but they vary in height. Problem here is, friendlisting div is not extending along with image's height as it should. As a result image overpositioned on bottom border.
2. Commonfriends div needs to extend in height and fully fill friendlisting box. Not happening.
I spent hours to fix these two issues, just couldn't make it. Any advise appreciated!
My html
<div class="friendlisting">
<img src="http://www.hurriyet.com.tr/_np/3375/8623375.jpg" alt="xxxx" class="profile" />
<div class="userinfo">
<span><strong>George Lexington</strong></span>
<span>Bruges, Belgium</span>
</div>
<div class="commonfriends">13 common friends</div>
<div class="tools">
<span><img src="images/icons/user_add.png" />Add to friend list</span>
<span><img src="images/icons/email_edit.png" />Send Message</span>
</div>
</div>
css
#content .friendlisting { min-height:40px; padding:5px 0 5px; border-bottom:1px solid #DDD; }
#content .friendlisting img.profile { float:left; width:100px; }
#content .friendlisting .userinfo { float:left; width: 200px; padding:10px; }
#content .friendlisting .userinfo span { display:block; }
#content .friendlisting .commonfriends { float:left; width:150px; height:100%; background:#ffe996; }
#content .friendlisting .commonfriends:hover { background:#FEDF62; }
#content .friendlisting .tools { float:left; width:160px; }
#content .friendlisting .tools span { display:block; }
you could try using a clearing div like this:
<div class="friendlisting">
<img src="http://www.hurriyet.com.tr/_np/3375/8623375.jpg" alt="xxxx" class="profile" />
<div class="userinfo">
<span><strong>George Lexington</strong></span>
<span>Bruges, Belgium</span>
</div>
<div class="commonfriends">13 common friends</div>
<div class="tools">
<span><img src="images/icons/user_add.png" />Add to friend list</span>
<span><img src="images/icons/email_edit.png" />Send Message</span>
</div>
<div style="clear:both;"></div>
</div>
or if you dont like the in-line style
.clear
{
clear:both;
}
then <div class="clear"></div>

Resources