how to change css when a scrollbar appears inside div - css

I have a question about the scrollbar that appears when it does not fit.
For example here I have one news item. Below a screenshot of the layout:
And when you add more items the scrollbar will appear over the date.
It's default behauviour for a scrollbar to appear inside a div, but is it possible to
apply css when the scrollbar appears inside. For example I could use a padding-right: 16px;
to the container. The only problem then, is another container is floated to it and these are inside a big container then the layout would collapse because of the extra padding.
Is there another way to keep the layout without breaking apart?
Here is the link: http://jsfiddle.net/EANbh/
and the css to the container:
.container {
width: 200px;
height:200px;
border: 1px solid grey;
overflow-y:auto;
overflow-x: hidden;
/*padding-right:16px;*/
}
Regards, Chris.

Another option without using the padding is:
.item {
display:inline-block;
width:184px;
height: auto;
border-bottom: 1px solid grey;
}

Related

CSS overflow layout

I'm trying to make a layout like native desktop application for my needs but i'm not very familiar with css.
Here an example of layout I need: JSFiddle
I'm trying to use overflow like this but not work:
.scrollable-container {
border: 1px solid #00f;
height: auto;
overflow: scroll;
}
What I'm trying to do:
- make .content div fit space between .navigation (green) and .footer (yellow) div even if window is resized
- make .scrollable-container scrollable if content size is larger
- make table header fixed when scrolling
Thank you.
Try to put max-height to the .scrollable-container class:
.scrollable-container {
border: 1px solid #00f;
overflow-y: auto;
max-height: calc(100vh - 190px);
}
190px is the "approximate" sum of the height of header, footer, navigation and page title.
Here is the updated fiddle

Center 2 divs horizontally without a wrapper

I want to simply center 2 divs horizontally regardless of the screen width and without using a wrapper. I have the following simple code:
#div1 {
display: inline-block;
width: 100px;
border: 1px solid #000000;
}
#div2 {
display: inline-block;
width: 200px;
border: 1px solid #000000;
}
I created the following fiddle for illustration:
http://jsfiddle.net/axe89/
The reason I don't want to use a wrapper is that I want to make a cross platform website and if I define a width for the wrapper it will break mobile screen.
#setek has the solution above, just wanted to add this quick rule of thumb:
To horizontally center display:inline and display:inline-block items, use text-align:center;.
To horizontally center display:block items, use margin: 0 auto;.
as alluded to by setek, you can define a container for your divs, with a width of 100% so that it scales with the screen/device width. Also set its text align to center to achieve your desired effect.
#container{text-align:center;width:100%;}
here is your updated fiddle
and for slightly modified markup and css - http://jsfiddle.net/axe89/5/
Use css margin properties.
margin-left:40%
to the first div.
You can add
text-align: center;
to the body tag or to whatever you are planning to wrap the divs with.
fiddle link

css min-width issue

.mainCoverWrapper {
position: relative;
min-width:312px;
background:red
}
I'm trying to center a div with min-width of 312px and make it expand according to its dynamic content while keeping it centered.
Right now the min-with doesn't work at all because it needs a float. I can't use a float because I need the div centered on the page.
In other words, div starts out with margin auto with a width of 312px and expands with its added content while being centered. Is this possible?
Any help would be greatly appreciated.
http://jsfiddle.net/FVmvA/
Here's a working example of the parent to follow the width of the child, and the child will expand according to the text given in it.
.myCoverWrapper {
border: 1px solid Peru;
margin:auto;
min-width: 200px;
max-width: 100%;
display: inline-block;
background: red;
}
.test {
height: 100px;
margin: 10px;
background: cyan;
}
This makes the parent div follow the width of the kid.
This however, will disallow you to "center" it. There's no way you can have both. This is because you cant center an image without knowing the width of the element.
The solution is to use jQuery, to add CSS in when necessary.
Here's an example. There's some bugs, but well, you have the general idea.
If you want the width to be fluid, your best bet is to set display: inline-block; on the to-be-centered element, and text-align: center; to the parent element.
See: CSS center display inline block?

DIV to inherit height of all elements inside

I have a DIV that will be containing a product's information. This DIV is within a PHP for argument, so for each product this DIV will be created containing it's information.
The problem I encounter is that the DIV shows very small. However, all items inside the div are showing, but the DIV's height is minimal.
How must I force the DIV to inherit the total height of all the products inside it?
Here is my DIV:
.cartItem {
border-top: 1px solid #dddddd;
display: block;
padding-bottom: 0.5em;
}
Thanks!
I think
Overflow: hidden;
does the trick...

Getting image to stretch a div

How can I get an image to stretch the height of a DIV class?
Currently it looks like this:
However, I would like the DIV to be stretched so the image fits properly, but I do not want to resize the `image.
Here is the CSS for the DIV (the grey box):
.product1 {
width: 100%;
padding: 5px;
margin: 0px 0px 15px -5px;
background: #ADA19A;
color: #000000;
min-height: 100px;
}
The CSS being applied on the image:
.product{
display: inline;
float: left;
}
So, how can I fix this?
Add overflow:auto; to .product1
In the markup after the image, insert something like <div style="clear:left"/>. A bit messy, but it's the easiest way I've found.
And while you're at it, put a bit of margin on that image so the text doesn't butt up against it.
Assuming #John Millikin is correct, the code
.product + * { clear: left; }
would suffice to do the same thing without forcing you to manually adjust the code after the div.
One trick you can use is to set the <div>'s overflow property to hidden. This forces browsers to calculate the physical size of the box, and fixes the weird overlap problem with the floated image. It will save you from adding in any extra HTML markup.
Here's how the class should look:
.product1 {
width: 100%;
padding: 5px;
margin: 0px 0px 15px -5px;
background: #ADA19A;
color: #000000;
min-height: 100px;
overflow: hidden;
}
This looks like a job for clearfix to me ...
Try the following:
.Strech
{
background:url(image.jpg);
background-size:100% 100%;
background-repeat:no-repeat;
width:500px;
height:500px;
}
display:inline
float:left
is your problem
Floating makes the parents width not be stretched by the child, try placing the image without the float. If you take the float off, it should give you the desired effect.
Another approach would be to make sure you are clearing your floats at the end of the parent element so that they don't scope creep.
Update: After viewing your link Your height issue as displayed, is because the floats are not being cleared.

Resources