Two div columns. Dynamic width of one - css

What i am trying to achieve, is get to divs, next to each other. One would be menu, 150px width, on the left of the screen, and second one, should fill rest of container.
Thats what i came up with:
http://jsfiddle.net/Ln49F/3/
But, the contend div is also "under" menu, and working with text, moving it to right a little is impossible. Is it possible, to make div "content" to be wide for "100% - 150px" somehow, and be placed next to the menu div?
To achieve something like that:
http://jsfiddle.net/Ln49F/4/
Float left, puts the div "next to" menu div, and padding works well, but i dont know how to make it to be wide for the rest of the container div.

Take out the width:100% (just leave it to auto, which is default) and use this:
div.content{
margin-left:150px;
background: green;
}
jsfiddle.

Write like this:
CSS
.wrapper{
overflow:hidden;
padding-bottom:10px;
}
.first{
float:left;
height:200px;
width:150px;
background:red;
}
.second{
overflow:hidden;
height:200px;
background:green;
}
HTML
<div class="wrapper">
<div class="first">first</div>
<div class="second">second</div>
</div>
Check this http://jsfiddle.net/TbRuB/10/
OR
You can also achieve this with display:table property but it's work till IE8 & above.
Check this http://jsfiddle.net/TbRuB/12/

You can view your first fiddle, but updated to work according to your spec, here: http://jsfiddle.net/ramsesoriginal/Ln49F/12/
This works by specifying the right margin on the second div, and simply leaving the width on auto.
the HTMLis unchanged:
<div class="container">
<div class="menu">Menu to the left</div>
<div class="content">Content of site<br>x<br><br><br><br><br></div>
</div>
And the CSS is pretty similar to yours:
div.container{
width: 90%;
height: 150px;
background: red;
}
div.menu{
width: 150px;
height: 100px;
float: left;
background: blue;
}
div.content{
margin-left: 150px;
background: green;
}
I took away the width: 100%; from div.content and replaced it with margin-left: 150px;
As you can see, you nearly had it right!
EDIT: BONUS: (fake) Equal height columns!
I updated the fiddle with some code to create "faux columns" with CSS3, so that it looks as if both divs are expanding down to the bottom of the container. You can see it here: http://jsfiddle.net/ramsesoriginal/Ln49F/13/ I don't know if you actually need it, but it's a common requirement for this kind of scenarios.
I simply placed a gradient background on the container, with a single hard stop in the middle:
background: linear-gradient(left, blue 150px, green 150px);
And then I expanded that with various vendor prefixes:
background: -moz-linear-gradient(left, blue 150px, green 150px); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(150px,blue), color-stop(150px,green)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, blue 150px, green 150px); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, blue 150px, green 150px); /* Opera 11.10+ */
background: -ms-linear-gradient(left, blue 150px, green 150px); /* IE10+ */
background: linear-gradient(left, blue 150px, green 150px); /* W3C */
I don't know if you need it, but sometimes this can be very useful!

Use simple solution
<div class="container">
<div class="menu">Menu to the left</div>
<div class="content">Content of site<br>x<br><br><br><br><br></div>
</div>
div.container{
width: 90%;
height: 150px;
background: red;
}
div.menu{
width: 150px;
height: 100px;
float: left;
background: blue;
}
div.content{
background: green;
margin-left: 150px;
}
http://jsfiddle.net/thirtydot/Ln49F/16/

div.container{
width: 90%;
background: red;
display: inline-block;
}
div.menu{
width: 150px;
float: left;
background: blue;
display: inline;
}
div.content{
display: inline;
float: left;
width: 65%;
background: green;
padding-left: 20px;
}
look at this
i hope this helps

Check this fiddle out. Basically, using box-sizing, some padding and a negative margin, you can line the two elements up to the top of their container. and have the content box stretch the expanse of its parent.

Related

How to achieve a left and right background split leaving middle div visible?

I have a header-Container div which stretches 100% of the width of the browser, just like on StackOverflow. Within this div is the actual header with a fixed width which is centered on the page.
What I want is to have a particular background colour only applied to the left side of the header, and a different colour applied to the right side of the header. I'm essentially trying to create a split background colour scheme on the header-Container div.
Here is a JSFiddle of where I am at the moment http://jsfiddle.net/1orddfn7/
HTML:
<div id="header-Container">
<div id="header">
</div>
</div>
CSS:
#header-Container { background-color: #CCC; position: relative; height: 190px;}
#header { background-color: red; width: 400px; height: 190px; margin-right: auto; margin-left: auto; }
I can't apply two background colours and split them at the 50% mark on the header-container div (I'd like maximum browser compatibility if possible). So I was thinking that I need to create two additional divs such as header-bg-left and header-bg-right and float them left and right respectively of the main center header div. But then I don't understand how to make them fill the remaining space to the edge of the browser window but stop at the edge of the header div. Is there a better way to do this?
One way is to use :after and :before to create elements with the color you want
#header-Container:before,
#header-Container:after{
content:'';
position:absolute;
z-index:-1;
width:50%;
top:0;
bottom:0;
}
#header-Container:before{left:0;background-color:yellow;}
#header-Container:after{right:0;background-color:green;}
Demo at http://jsfiddle.net/1orddfn7/2/
Another is to use a gradient background with two colors.
#header-Container { position: relative; height: 190px;
background: -moz-linear-gradient(left, #eaf700 0%, #eaf700 50%, #0fe500 50%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#eaf700), color-stop(50%,#eaf700), color-stop(50%,#0fe500));
background: -webkit-linear-gradient(left, #eaf700 0%,#eaf700 50%,#0fe500 50%);
background: -o-linear-gradient(left, #eaf700 0%,#eaf700 50%,#0fe500 50%);
background: -ms-linear-gradient(left, #eaf700 0%,#eaf700 50%,#0fe500 50%);
background: linear-gradient(to right, #eaf700 0%,#eaf700 50%,#0fe500 50%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eaf700', endColorstr='#0fe500',GradientType=1 );
}
Demo at http://jsfiddle.net/1orddfn7/3/
(gradient css from http://www.colorzilla.com/gradient-editor/)

CSS image border transparency/color issue

I wanted to make a cool div, so I made this image to get its borders:
The problem is that half of the borders are transparent area, so when I try to fill the empty center of the div with background-color it also paints the outer, transparent area. I'd like the background color not to get past the border.
Here's what I'm talking about:
#charset "utf-8";
/* CSS Document */
#testDiv{
border-image-source:url(https://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
min-height:600px;
width:600px;
}
#body {
height:100%;
width: 100%;
background: #CCC;
position: absolute;
margin: 50px 0 0 0;
}
<div id="testDiv">
</div>
Or see http://jsfiddle.net/6M59T/119/.
How can I solve this? I've thought on putting a slightly smaller div inside this one, but I don't know how to adjust it so it always covers a bit less than its parent. Also, I'd like to keep it as simple as possible. Any ideas?
Maybe i am mistaken, but you can try to play with border-image-outset and margin attribute.
float:left;
margin:50px 20px;
border-image-source:url(http://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
border-image-outset:30px;
http://jsfiddle.net/6M59T/120/

Centering text on top of multiple Divs?

I have a percentage bar and I'm trying to put some text over the front of it.
My example does that, but it centers over the smaller bar, not the full thing.
My Question: How can I get the word "test" centered over the full bar, not just the inner-smaller one.
HTML
<div id="bar1">
<div style="width:55%; text-align:center;">test</div>
</div>
CSS
#bar1 {
background-color: black;
border-radius: 13px; /* (height of inner div) / 2 + padding */
padding: 3px;
}
#bar1 div
{
background-color: green;
height: 20px;
border-radius: 10px;
-webkit-background-size:50px 50px;
background-image:
-webkit-repeating-radial-gradient(center, circle, green, #00BB00 40%, green 80%);
-webkit-animation:upbar 3s linear infinite;
}
#-webkit-keyframes upbar
{
0%{background-position:0 0}
100%{background-position:0px -100px}
}
(apologies for the cheesiness of the bar. I'm trying to find a decent upward animation for it, so any suggestions welcome)
There's probably a better way but this works: http://jsfiddle.net/SFHft/
Use a second div with position:absolute:
<div id="bar1">
<div class="anim" style="width:55%;"></div>
<div class="text">TEST</div>
</div>
#bar1 div.anim
{
background-color: green;
height: 20px;
border-radius: 10px;
-webkit-background-size:50px 50px;
background-image:
-webkit-repeating-radial-gradient(center, circle, green, #00BB00 40%, green 80%);
-webkit-animation:upbar 3s linear infinite;
}
#bar1 div.text
{
text-align:center;
position:absolute;
color:#fff;
top: 3px;
left: 50%;
width: 100px;
margin-left: -50px;
}
You can center horizontally the child div with margin: 0 auto:
Fiddle
MDN about margin
that's because your inner bar has width:55% of the parent div(div.bar1).
either give it a full width, to bring the text to the center, or place your text outside.
you can also play with position:absolute
see this fiddle

CSS fluid elements running into each other

I'm having some trouble with my css and I was gonna post on stackoverflow but I thought maybe this would be the right place to post seeing its strictly a css problem. I have a jquery cycle plugin tor rotate images and I want to have a block of text to the right of the the rotator but I don't want it to run into the rotator and I also would like it to not crop of when the page is shrunk within reason. right now if you pull the browser window in to the left it just slides under the rotator I would much rather the rotator move to the left as well until it can't anymore then the text should start expanding downward if that is even possible. but I cant seem to figure it out.
here is the site http://falconesuits.com/
hdere is the css (well at least the important part)
#story2 {
margin: 100px;
width:300px;
float:right;
color:#FFF;
}
.slideshow {
width:300px;
height:450px;
background: #cc9966; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#cc9966)); /* for webkit browsers */
background: -moz-linear-gradient(top, #fff, #cc9966); /* for firefox 3.6+ */
min-height: 100%;
border:10px;
border-style:groove;
border-color:#939598;
margin-left: auto;
margin-right: auto;
top: 100px;
}
One approach that might help is to restructure your html by putting your story and slideshow in the same div container:
<div id="content">
<div id="story2">...</div>
<div class="slideshow">...</div>
</div>
Then styling #content so that it has the fluid margins instead.
#content {
overflow: hidden;
margin: 0 auto;
width: 650px;
margin-top: 100px;
}
#story2 {
width: 300px;
float: right;
color: #fff;
}
.slideshow {
float: left;
width:300px;
height:450px;
background: #cc9966; /* for non-css3 browsers */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000'); /* for IE */
background: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#cc9966)); /* for webkit browsers */
background: -moz-linear-gradient(top, #fff, #cc9966); /* for firefox 3.6+ */
min-height: 100%;
border:10px;
border-style:groove;
border-color:#939598;
}
As for expanding the text downwards, you could try setting your #story width to a percentage instead of a fixed pixel value, I guess.

IE 7/8 CSS div size problem with a img background

I'm designing a clean style to use in some web apps. And I've come across a IE bug (always the same).
Well its pretty simple. I have a gradient background, and on top of it a rectangle with no border and its filled with nothing and with a shadow around it, giving the illusion that its on top of the background, as you can see in the snapshot.
Its displayed well in all browsers except IE. IE displays like this.
IE increases about 4 px to the top div with the class "content-top-shadow". And it shouldn't. I have used margin and padding 0 to fix it and no luck.
PS: The png's have transparency.
Any idea how can i fix this bug, or whats wrong in the CSS?
Thanks.
Here is the code:
HTML
<div class="content-holder">
<div class="content-center">
<div class="content-top-shadow"></div>
<div class="content-center-holder"></div>
<div class="content-bottom-shadow"></div>
</div>
</div>
CSS
.content-holder {
width: 100%;
height: 570px; /*once complete change to auto*/
background-image: url(images/content-holder-bg.png);
background-repeat: repeat-x;
padding-top: 20px;
text-align: center; /*IE Bug Fix to Center the other divs inside this one*/
}
.content-center {
width: 918px;
height: auto;
margin-left: auto;
margin-right: auto;
}
.content-top-shadow {
width: 918px;
height: 9px;
background-image: url(images/content-top-shadow-bg.png);
background-repeat: no-repeat;
}
.content-center-holder {
width: 918px;
height: 200px; /*once complete change to auto*/
background-image: url(images/content-center-holder-bg.png);
background-repeat: repeat-y;
}
.content-bottom-shadow {
width: 918px;
height: 9px;
background-image: url(images/content-bottom-shadow-bg.png);
background-repeat: no-repeat;
}
IE thinks your div should be bigger than 9px, because of text size, even if there is no text in it (!), so you need to set
font-size:1px;
or something like that, on the top and bottom divs.
Here's something that helps me overcome cross-browser incompatibilites when it comes to empty spaces especially within DIVs and TDs. Place this as the sole content of the empty space, while making sure your spacer.gif image is a 1px x 1px transparent dot. Cheers!
<div style="width:1px;height:1px;visibility:hidden;overflow:hidden;clip:rect(1px,1px,1px,1px);color:#FFFFFF;font-size:1px;"><img src="/images/spacer.gif"></div>

Resources