I have boxes floated inside a div sort of like the SO Chat except i am making a box for my own website where users can make their own chat room, these boxes on the page represent chatrooms and i want to make a perfect width for them so they will fit exactly on the page without any excess space in the margins. the main div they are positioned in is 965px with a padding of 15px on the left and right side of it making a 935px width i reduced the width from 965px to 935px to keep a total width of 965px.
To get an idea of my scenario check out A Fiddle
As you can see there is some space left at the end right side of the div and i dont want that, i want the chat boxes to fit pixel perfectly the full width and remember to take into account that borders count as widths too. If someone could help me that would be great!
CSS Styles
body {
width:1000px;
}
#Body {
width:935px;
padding:15px;
height:500px;
background-color:#F1F1F1;
margin:0 auto;
}
.ChatRoom {
float:left;
width:223px;
height:200px;
border:1px solid #666;
cursor:pointer;
margin-right:8.75px;
background-color:#FFF;
}
.ChatTitle {
width:100%;
height:30px;
line-height:30px;
font-size:13px;
font-weight:bold;
text-align:center;
background-color:#C6D6D9;
border-bottom:2px solid #9C0;
}
You can accomplish this using box-sizing:border-box. What it does is includes the padding and border sizes from the width, as opposed to its normal behaviour of adding to it (which makes the <div> overflow to the next line). I've added a div.Inner here which will have the border and white background while the .ChatRoom is used to provide space using padding.
jsFiddle
HTML
<div class="ChatRoom">
<div class="Inner">
<div class="ChatTitle">My Chat Room</div>
</div>
</div>
CSS
.ChatRoom {
float:left;
width:25%;
height:200px;
padding:8px;
box-sizing:border-box;
}
.ChatRoom .Inner {
border:1px solid #666;
box-sizing:border-box;
background-color:#FFF;
cursor:pointer;
height:100%;
}
Without border-box
Turns out it's pretty easy without border-box too, utilising margin on .Inner.
jsFiddle
.ChatRoom {
float:left;
width:25%;
height:200px;
}
.ChatRoom .Inner {
border:1px solid #666;
margin:8px;
background-color:#FFF;
cursor:pointer;
height:100%;
}
http://jsfiddle.net/DyTT8/1/
The last div needs to have the margin reset if not it will add to the 15px of padding. I did this by giving it class="last and making the .ChatRoom div 225px; This will give you the proper spacing.
You could also put the divs in an unordered list and target the last div with li:last-child and remove the margin that way.
Related
I have this CSS Code:
.topBar {
width:100%;
height:70px;
position:absolute;
/*position:fixed;
z-index:999;*/
top:0;
left:0;
padding:10px;
color:#000000;
background-color:#eeeeee;
border-bottom:2px solid #F36F25;
}
but because it is 100% wide and has a 10px padding it shows a horizontal scroll bar.
how can i stop this from happening but keep the padding and 100% width?
I have tried:
overflow-x: none;
in my css but i still want the horizontal scrollbar to show when the screen gets too small
Basically the div.topBar is 100% + 10px (x2). So it's actually more than 100% (hence the scroll box). The general way to do this is the add another div inside the parent div and add the padding:10px to that. Another way is to use box-sizing:border-box which actually honours the 100% rule!
Take a look at this sample.
You can use the box-sizing CSS property. Add this to .topBar : box-sizing:border-box;
.topBar {
width:100%;
height:70px;
position:absolute;
/*position:fixed;
z-index:999;*/
top:0;
left:0;
padding:10px;
color:#000000;
background-color:#eeeeee;
border-bottom:2px solid #F36F25;
box-sizing:border-box; /** <- Add this **/
}
<div class="topBar"></div>
This property includes padding (and borders if you have some) in the width you set to the element. so if you set width: 100%; it won't overflow the parent container anymore.
More info about box-sizing on MDN
I'm struggling with this:
I want to place a range slider next to an output tag. Both tags should be on the same line while the input range slider takes the full width of the given space.
Problem: I have to
display:block
the span element, because i want to set a fix width. This and the
width:100%;
for the range slider makes it impossible (for me) to achieve my goal.
I've set up a JSFiddle.
So, how can i achieve this?
fixed width for the output tag
output and input should be sitting side-by-side on one line
the input slider should be taking the full width of the given space
Without float and IE8 and above supported way
use display:table
working demo
.form-inline {
display:table;
border:1px solid green;
table-layout:fixed;
width:100%;
margin:0;
padding:0;
}
.input_button {
display:table-cell;
width:104px; /* Fixed span width*/
margin:0;
padding:0;
text-align:center;
border:1px solid black;
}
#range_slider {
border:1px solid red;
display:table-cell;
border:1px solid red;
margin:0;
padding:0;
}
You need to set left float on span and instead of giving range slider a width of 100%, give span 19% and range slider 78%. You need to divide 100% among themselves.
.input_button{
float:left;
width:19%;
}
#range_slider{
width:78%;
margin-top:33px;
margin-left:10px;
}
Here is a fiddle
Rather than setting display:block for span element, try Can using display:inline-block
<div id="container">
<div id="top"></div>
<div id="left"></div>
<div id="right"></div>
<div id="clear"></div>
</div>
#container{
width:200px;
margin-left:auto;
margin-right:auto;
margin-top:50px;
}
#top{
width:200px;
height:20px;
border:medium ridge #FFF;
}
#left{
float:left;
width:50px;
height:20px;
border:medium ridge #FFF;
}
#right{
float:right;
width:40px;
height:20px;
border:medium ridge #FFF;
}
#clear{
clear:both;
}
Why the #right and #top are not right aligned?
Its because the top element is actually overflowing the bounds of the container, while the floated element right is being restricted to it. The top element is overflowing the container because the border is not included in the width. So top is actually occupying 204px.
Problem Illustrated via Example: http://jsfiddle.net/KhJ6e/2/
To fix, adjust top to account for the 2px border on each side. (subtract 4 from width of container) or specify width as auto depending on your intentions.
#top{
width:196px;
height:20px;
border:medium ridge #FFF;
}
Example: http://jsfiddle.net/KhJ6e/1/
The top is wider than it's parent container
#top{
width:auto;
}
The problem is how the width is calculated for the box model. All elements on the screen have 4 components (inner to outer): content, padding, border, margin. By default, the width includes only the content. By adding the borders, top becomes larger than 200 pixels. Using the developer tools in chrome, it was rendering as 206px.
There are two possible solutions, one is fudge the widths, or two modify the box model. The first will work, but it is difficult to maintain. Any small change can mess up the alignment.
A better solution is to use box-sizing: border-box. By adding that CSS style, the width attribute will include content, padding, and border. So, originally padding and border wrap around the outside, but with border-box, the encroach on the inside.
Original: http://jsfiddle.net/deafcheese/Gv5BZ/
Corrected (using
boz-sizing: border-box): http://jsfiddle.net/deafcheese/Gv5BZ/1/
box-sizing reference: http://css-tricks.com/box-sizing/
I am trying to push down the boxes after the .slidetoggle panel is activated. But what happens is that it either goes over or under (depending on z-position) the positioned boxes. I want to it so that when the slidetoggle panel is activated, it will push down all of the boxes.
Here is the JSFIDDLE: http://jsfiddle.net/iqab/8QHdB/3/
And here is an example of the type of functionality I am talking about:
http://www.michaelnagy.at/
Replace the CSS with this. The modified lines are commented.
Other fixes applied (see comments in CSS).
.wrapper{
width:800px;
/*height:800px;*/ /*let wrapper auto resize itself based on contents height*/
border:solid thin #000;
position:relative;
margin:auto;
}
.wrapper .Boxes{
display:inline-block; /*fix for box overlap out of wrapper. replacement for "float:left" below*/
width:200px;
height:200px;
/*float:left;*/ /*fix for box overlap out of wrapper. replaced with "display:inline-block" above*/
border:solid thin #000;
margin:33px;
}
.wrapper .hbox{
width:734px;
height:400px;
border:solid thin #100;
/*position:absolute;*/ /*fix for panel overlap over boxes*/
top:33px;
margin:33px;
display:none;
background-color: #000;
}
I have a div within a div, and when viewing the web page in IE6, it does not display spacing between the bottom of div class="video-tour" and the bottom of div class="content-body"
Here is what it looks like in IE6: http://i42.tinypic.com/20zs7s7.png
Here is what it looks like displaying correctly in Safari: http://i44.tinypic.com/2h69de1.png
The css for .video-tour <-- there are multiple videos that are split up into different boxes as you'll see, they have a width of 31%
.video-tour {
float:left;
width:31%;
border:1px solid #fdbe2f;
background-color:#ffc;
text-align:center;
padding:3px;
overflow:auto;
margin:6px;
}
.video-tour img {
border:1px solid #fdbe2f;
padding:3px;
}
CSS for .content-body which .video-tour is within
.content-body {
padding:10px 15px;
font-size:.8em;
font-family:arial;
overflow:auto;
}
Any help as to why there is no spacing at the bottom in IE6 and spacing in other browsers would be helpful.
Try adding a div at the bottom after video-tour that has a style of clear: both.
I believe its because you need to clear the floats.
You could try place a
<div style="width: 100%; overflow: hidden;"><!-- floats go here --></div>
Around the entire content with video-tour's.