how to make a div scrollable to left and right? - html

I have created a big menu that has its width set to 100%, I want this div to be scrollable from left to right.(on the X axis). I have set the scroll-left and scroll right properties accordingly but it still doesnt work. Im sure im doing something wrong, any advice is appreciated. Thanks.
code is on jsFiddle

You need to have a width in place that isn't 100%. Set the menu into a container div with your dimensions and overflow on and then set the actual menu to be really wide inside it. Think of the box div like a frame.
http://jsfiddle.net/spacebeers/WkUNn/19/
.box {
max-height:150px;
border: 2px solid red;
width: 100%;
overflow: scroll;
}
.megamenu {
width: 3000px;
overflow: hidden;
max-height:100px;
-webkit-box-shadow: 0px -1px 12px rgba(0, 0, 0, 0.48);
-moz-box-shadow: 0px -1px 12px rgba(0, 0, 0, 0.48);
box-shadow: 0px -1px 12px rgba(0, 0, 0, 0.48);
padding-bottom:45px;
padding-top:5px;
background: grey;
border-top:1px solid #767676;
font-family:Verdana, Tahoma, Sans-Serif;
z-index: 100;
}
EDIT: As pointed out by #c_kick (and in the original) you can use overflow-x, overflow-y. I was trying to keep things simple.

Related

Box-shadow not appearing OVER a div with lower z-index

So guys, I've here a header:
As you can see, the box-shadow works just fine. However, putting a background-color on the content <div> yields this:
Visually, the box-shadow was covered by the background-color. The content <div> has lower z-index value than the header though. How can I make the box-shadow appear over the <div> to make it seem like the content is under the header?
If this will help, here is the CSS for both markups:
header{ /* the header, obviously */
background: #fee;
height: 60px;
padding: 40px 20px 0px 20px;
border-bottom: 5px solid #f53301;
-webkit-box-shadow: 0 12px 16px -6px gray;
-moz-box-shadow: 0 12px 16px -6px gray;
box-shadow: 0 12px 16px -6px gray;
border-radius: 20px 20px 0px 0px;
z-index: 9999;
}
#content-inside { /* the content */
padding:20px;
z-index:1; /* changed this to -1 but it still didn't work */
background:white;
border:1px solid black;
}
I hope someone can help me with this. Cheers!
z-index only applies to element where the position has been set (i.e. not the default static position). Trying position:relative would be the most likely solution here.

Unwanted white space on right side of page

I am building a responsive site. On the large desktop size, I seem to have a bit of white space on the right side of the large sliding banner. I am guessing this is due to some css in the slider causing this. This white space seems to be pushing outside of the boundaries of the body tag. You can see this by moving the horizontal scroll bar to the right. The framework this is built on is Twitter Bootstrap 3.
The slider I used is called FlexSlider.
I would post HTML and CSS, but since I am not totally sure where to start, there would be a lot of it and I am not sure how helpful it would be.
Thanks for any help.
URL to live page: http://sevenclanscasino.designangler.com/warroad/warroad-home
The footer tag is overflowing out .. change/update the css that is applied to this tag.
article, aside, details, figcaption, figure, footer, header, hgroup, main, nav, section, summary {
display: block;
width: 99%;
}
I just tried setting the width to 99% as above.
It's a CSS rule:
.flexslider {
margin: 0 0 20px;
background: #fff;
border: 4px solid #fff;
position: relative;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
-o-box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
zoom: 1;
}
You must to comment this lines to see the change:
background: #fff;
border: 4px solid #fff;
Comment this line and you will not have this white space.
Luiggi
you can try to modify it? please, and tell me something, if you want my email send me a private message.
.flexslider {
margin: 0px 0px 20px;
position: relative;
/* background: none repeat scroll 0% 0% #FFF;
border: 4px solid #FFF;
border-radius: 4px;
box-shadow: 0px 1px 4px rgba(0, 0, 0, 0.2);*/
}
I comment this lines, and the white space it's not on the page!
Tell me something
Luiggi

Header won't go to the edge on the top

I want to move the header up to the topmost. But it won't go, here's the fiddle http://jsfiddle.net/DCtH7/4/
As you see in the fiddle, there is a white space above the header. I tried padding: 0 but it won't work.
Add position: absolute to the header
header {
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5);
color: white;
width: 100%;
height: 34px;
box-shadow: 0px 3px 3px black;
margin: 0 auto;
position: absolute;
}
An example : http://jsfiddle.net/DCtH7/6/
As an alternative way change margin to padding here:
header #header-content {
padding: 10px;
}
This will also fix the problem without use any absolute position
An example : http://jsfiddle.net/DCtH7/7/

How to give priority to a div in terms of overlapping divs on a drop down menu?

I added a new navigation menu to my website. It's one I found from a tutorial and I am having an issue with it. It appears to be hiding behind the div directly below it. I have tried z index but that does not work in this case. I am using z index though. I have the div above the nav menu fixed so that it moves with the page when I scroll.
This fiddle is of most of the site. there is a lot of code but I do not know where the issue is so I added most of it. The last bit of css is for the datatables.
The following code is the div containing the nav menu (not sure if that's relevant.)
.box{
margin-left:auto;
margin-right:auto;
width:1000px;
position:relative;
margin-top:220px;
z-index:1;
}
So basically how can I make it so that the nav menu does not hide behind the bottom div. the content which is the datatables.
As always thanks in advance!
EDIT: I removed overflow:hidden from the .box and now it shows me the menu but it pushes all the divs and content below it down when the menu drops down. Anyway to fix this?
Here is your solution. Adjust to whatever you need it to be.
http://jsfiddle.net/cornelas/eNp8F/16/
.box{
margin-left:auto;
margin-right:auto;
width:1000px;
position:relative;
margin-top:220px;
z-index:999;
height: 400px;
}
#content {
/* Background color, gradients & Rounded Corners */
background-color: #121212;
border: 1px solid #343434;
-webkit-border-radius: 0px 0px 0px 0px;
border-radius: 0px 0px 0px 0px ;
-webkit-box-shadow: 1px 4px 15px 1px rgba(0, 0, 0, 9);
box-shadow: 1px 4px 15px 1px rgba(0, 0, 0, 9);
-webkit-box-shadow: 1px 4px 15px 1px rgba(0, 0, 0, 9);
box-shadow: 1px 4px 15px 1px rgba(0, 0, 0, 9);
margin:20px;
padding:5px 5px 5px 5px;
position: absolute;
top: 20em;
}

How to get box-shadow on left & right sides only

Any way to get box-shadow on left & right (horizontal?) sides only with no hacks or images. I am using:
box-shadow: 0 0 15px 5px rgba(31, 73, 125, 0.8);
But it gives shadow all around.
I have no borders around the elements.
NOTE: I suggest checking out #Hamish's answer below; it doesn't involve the imperfect "masking" in the solution described here.
You can get close with multiple box-shadows; one for each side
box-shadow: 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 8px -4px rgba(31, 73, 125, 0.8);
http://jsfiddle.net/YJDdp/
Edit
Add 2 more box-shadows for the top and bottom up front to mask out the that bleeds through.
box-shadow: 0 9px 0px 0px white, 0 -9px 0px 0px white, 12px 0 15px -4px rgba(31, 73, 125, 0.8), -12px 0 15px -4px rgba(31, 73, 125, 0.8);
http://jsfiddle.net/LE6Lz/
I wasn't satisfied with the rounded top and bottom to the shadow present in Deefour's solution so created my own.
inset box-shadow creates a nice uniform shadow with the top and bottom cut off.
To use this effect on the sides of your element, create two pseudo elements :before and :after positioned absolutely on the sides of the original element.
div:before, div:after {
content: " ";
height: 100%;
position: absolute;
top: 0;
width: 15px;
}
div:before {
box-shadow: -15px 0 15px -15px inset;
left: -15px;
}
div:after {
box-shadow: 15px 0 15px -15px inset;
right: -15px;
}
div {
background: #EEEEEE;
height: 100px;
margin: 0 50px;
width: 100px;
position: relative;
}
<div></div>
Edit
Depending on your design, you may be able to use clip-path, as shown in #Luke's answer. However, note that in many cases this still results in the shadow tapering off at the top and bottom. This taper is subtle and depending on your colour scheme and blur radius you may find it acceptable. In this example I have added a 2nd box to make the taper easy to see:
div {
width: 100px;
height: 50px;
background: #EEE;
box-shadow: 0 0 15px 0px #000;
clip-path: inset(0px -15px 0px -15px);
position: relative;
margin: 0 50px;
}
<div>1</div>
<div>2</div>
Negative spread and Masking shadow
CSS box-shadow uses 4 parameters: h-shadow, v-shadow, blur, spread:
box-shadow: 10px 0 8px -8px black;
The blur parameter adds the gradient effect, but adds also a little shadow on top and bottom borders. To get rid of this side effect we can use:
Negative spread reduces the shadow on all borders: you can play with it trying to remove that little vertical shadow without affecting too much the one obn the sides (it's easier for small shadows, 5 to 10px.)
Masking shadows of the same color of the background (white in this case), which allows for ticker shadows. Note that this masking shadow needs to have blur = 0 to fully cover the side effects.
Here two examples, the second one uses Masking shadow:
div{
width: 100px;
height: 100px;
border: 1px solid green;
margin: 10px;
float: left;
}
#example1{
box-shadow: -10px 0 8px -8px black, 10px 0 8px -8px black;
}
#example2{
box-shadow:
0 -6px white,
0 6px white,
-7px 0 4px -3px black,
7px 0 4px -3px black;
}
<div id="example1"></div>
<div id="example2"></div>
If none of these approaches suit your needs, you can also add an absolute div on the side of any existing divs.
Just remember to set the container div as position: relative so this absolute div will stay inside.
#example3 {
position: relative;
width: 100px;
height: 100px;
margin: 10px;
border: 1px solid green;
}
.shadow {
position: absolute;
height: 100%;
width: 4px;
left: 0px;
top: 0px;
box-shadow: -4px 0 3px black;
}
<div id="example3">
content here
<div class="shadow"></div>
</div>
Try this, it's working for me:
box-shadow: -5px 0 5px -5px #333, 5px 0 5px -5px #333;
clip-path is now (2020) the best way I have found to achieve box-shadows on specific sides of elements, especially when the required effect is a "clean cut" shadow at particular edges, like this:
.shadow-element {
width: 100px;
height: 100px;
background-color: #FFC300;
box-shadow: 0 0 10px 5px rgba(0,0,0,0.75);
clip-path: inset(0px -15px 0px -15px);
/* position and left properties required to bring element out from edge of parent
so that shadow can be seen; margin-left would also achieve the same thing */
position: relative;
left: 15px;
}
<div class="shadow-element"></div>
...as opposed to an attenuated/reduced/thinning shadow like this:
.shadow-element {
width: 100px;
height: 100px;
background-color: #FFC300;
box-shadow: 15px 0 15px -10px rgba(0,0,0,0.75), -15px 0 15px -10px rgba(0,0,0,0.75);
/* position and left properties required to bring element out from edge of parent
so that shadow can be seen; margin-left would also achieve the same thing */
position: relative;
left: 15px;
}
<div class="shadow-element"></div>
Simply apply the following CSS to the element in question:
box-shadow: 0 0 Xpx Ypx [hex/rgba]; /* note 0 offset values */
clip-path: inset(Apx Bpx Cpx Dpx);
Where:
Apx sets the shadow visibility for the top edge
Bpx right
Cpx bottom
Dpx left
Enter a value of 0 for any edges where the shadow should be hidden and a negative value (the same as the combined result of the blur radius + spread values - Xpx + Ypx) to any edges where the shadow should be displayed.
Another way is with overflow-y:hidden on the parent with padding:
body {
padding: 30px;
}
#wrap {
overflow-y: hidden;
padding: 0 10px;
}
#wrap > div {
width: 100px;
height: 100px;
box-shadow: 0 0 20px -5px red;
}
<div id="wrap">
<div></div>
</div>
You must use the multiple box-shadow; . inset property makes it look nice and inside:
div {
box-shadow: inset 0 12px 15px -4px rgba(31, 73, 125, 0.8), inset 0 -12px 8px -4px rgba(31, 73, 125, 0.8);
width: 100px;
height: 100px;
margin: 50px;
background: white;
}
<div></div>
This works fine for all browsers:
-webkit-box-shadow: -7px 0px 10px 0px #000, 7px 0px 10px 0px #000;
-moz-box-shadow: -7px 0px 10px 0px #000, 7px 0px 10px 0px #000;
box-shadow: -7px 0px 10px 0px #000, 7px 0px 10px 0px #000;
For a nice inset shadow in right and left sides on images, or any other content, use it this way (the z-index:-1 does a nice trick when showing images or inner objects with insets):
.shadowcontainer{
display:inline-flex;
box-shadow: inset -40px 0px 30px -30px rgba(0,0,0,0.9),inset 40px 0px 30px -30px rgba(0,0,0,0.9);
}
.innercontent{
z-index:-1
}
<div class="shadowcontainer">
<img src="https://www.google.es/images/srpr/logo11w.png" class="innercontent" style="with:100%"/>
</div>
In some situations you can hide the shadow by another container. Eg, if there is a DIV above and below the DIV with the shadow, you can use position: relative; z-index: 1; on the surrounding DIVs.
Another idea could be creating a dark blurred pseudo element eventually with transparency to imitate shadow. Make it with slightly less height and more width i.g.
You can use 1 div inside that to "erase" the shadow:
.yourdiv{
position:relative;
width:400px;
height:400px;
left:10px;
top:40px;
background-color:white;
box-shadow: 0px 0px 1px 0.5px #5F5F5F;
}
.erase{
position:absolute;
width:100%;
top:50%;
height:105%;
transform:translate(0%,-50%);
background-color:white;
}
You can play with "height:%;" and "width:%;" to erase what shadow you want.
I tried to copy the bootstrap shadow-sm just in the right side, here is my code:
.shadow-rs{
box-shadow: 5px 0 5px -4px rgba(237, 241, 235, 0.8);
}
This worked for me:
box-shadow: 0 5px 5px 0 #000;
If you want your div to have an arrow on top of it, use this:
box-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
For horizontal only, you can trick the box-shadow using overflow on its parent div:
.parent{
overflow:hidden;
}
.box-shadow{
box-shadow: box-shadow: 0 5px 5px 0 #000;
}
<div class="parent">
<div class="box-shadow">content</div>
</div>