I've been struggling with this for the past day and I can't seem to understand (nor fix) this problem.
The problem is that the content overflows the "sidebar" div instead of expanding it, when there's less "main" content than "sidebar" content. (As you can see in the following image).
Here's a JSFiddle!
The #sidebar is position: absolute; since I'm using left: 0; and left: -200; to show and hide the sidebar. The #sidebar-handle is also crucial as I have a click event listener and a hover animation connected to it, for the purpose of toggling show and hide for the #sidebar. (When toggling show and hide I also do change the margin-left of #main.
Does anybody have a solution?
I'm of course searching for a pure CSS solution and a solution which works in the major browsers.
CSS
html, body {
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
color: #333;
background-color: #EEE;
}
#container {
height: 100%;
min-height: 100%;
}
#header {
height: 50px;
background-color: #303030;
-webkit-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
#header-content {
height: 100%;
}
#sidebar {
width: 210px;
min-height: 100%;
position: absolute;
left: 0;
top: 50px;
bottom: 0;
background-color: #404040;
-webkit-box-shadow: 3px 4px 10px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 3px 4px 10px rgba(0, 0, 0, 0.5);
box-shadow: 3px 4px 10px rgba(0, 0, 0, 0.5);
}
#sidebar-content {
width: 200px;
position: absolute;
left: 0;
}
#sidebar-handle {
width: 10px;
position: absolute;
right: 0;
top: 0;
bottom: 0;
background-color: #303030;
border-left: 1px solid #272727;
}
#main {
margin-left: 210px;
padding: 30px;
}
ul {
margin: 0;
padding-left: 0;
list-style: none;
}
li {
margin: 0;
margin-top: 16px;
background-color: #AAA;
}
p {
margin-top: 0;
}
HTML
<div id="container">
<div id="header">
<div id="header-content"></div>
</div>
<div id="content">
<div id="sidebar-container">
<div id="sidebar">
<div id="sidebar-content">
<ul>
<!-- lots of li tags for testing -->
</ul>
</div>
<div id="sidebar-handle"></div>
</div>
</div>
<div id="main">
<!-- some random content for testing -->
</div>
</div>
</div>
Remove the bottom: 0 from the sidebar, that limits it to the height of the window.
Remove the absolute positioning on the sidebar-content, so that it's not taken out of the flow. That way it can affect the size of the sidebar.
Demo: http://jsfiddle.net/Guffa/gfu1snhm/3/
I don't know if this has some unwanted effect in some other situation, but it solves this situation, and should help you see why it does what it does.
Remove the line with absolute and set margin:0;
Related
First of all excuse me for explanation if I am not up to the mark, as this is my first post in this platform, Well, I am working on overlay where it has to be shown in right side of the page with given width of say 416px and 100vh of height, but things are getting cut if I do decrease the browser window and as I am decreasing the size of the browser window the button at bottom start appearing on content of overlay which has to remain at bottom even the height is getting decreased, here is the my code as below:
.advanced-overlay {
width: 100%;
min-height: 100vh;
background-color: rgba(35, 0, 18, 0.5);
position: fixed;
z-index: 100002;
top: -41px;
left: 0;
bottom: 0;
.advance-overlay-footer {
display:flex;
justify-content: space-between;
align-items:center;
position: fixed;
right: 24px;
width:156px;
bottom: 24px;
height:6%;
}
.advanced-overlay-content {
position: relative;
// min-height: 83vh;
width: 416px;
margin-top: 108px;
margin-left: auto;
margin-right: 6px;
opacity: 1;
z-index: 100004;
border-radius: 16px 16px 16px 16px;
background-color: #f5f4f6;
box-shadow: 0 2px 30px 0 rgba(0, 0, 0, 0.07),
0 19px 18px 0 rgba(0, 0, 0, 0.05), 0 8px 12px 0 rgba(0, 0, 0, 0.05),
0 1px 5px 0 rgba(0, 0, 0, 0.04), 0 0 2px 0 rgba(0, 0, 0, 0.03);
.close-advance-overlay {
position: absolute;
background-color: #fff;
width: 110px;
height: 40px;
display: flex;
border-radius: 20px;
padding: 5px 22px;
top: -18px;
right: 155px;
opacity: 1;
cursor: pointer;
img {
height: 20px;
width: 20px;
align-self: center;
}
.button-text {
align-self: center;
margin-left: 5px;
font-weight: 600;
font-size: 16px;
color: #000000;
}
}
.advnaced-overlay-content-secion {
//min-height:89vh;
width: 100%;
bottom:10%;
// height:100vh;
.select-box {
margin-top: 40px;
margin-bottom: 40px;
}
.accordinan-filter {
margin-bottom: 24px;
}
.accordian-title {
font-weight: 900;
}
.accordian-content {
margin: 0;
font-size: 16px;
}
}
}
}
.is-maximum {
height: 73vh;
overflow-y: auto;
overflow-x: hidden;
&::-webkit-scrollbar {
width: 4px;
background-color: #fff;
}
&::-webkit-scrollbar-thumb {
border-radius: 3px;
background-color: #d3d3d3;
}
}
<div class="advanced-overlay" v-if="toggleFilter">
<div class="advanced-overlay-content">
<div class="close-advance-overlay" #click="toggleAdvanceFilterOverlay">
<img class src="../assets/icons/close.svg" />
<span class="button-text">Close</span>
</div>
<div class="advnaced-overlay-content-secion is-maximum">
<div class="select-box"></div>
<div class="accordinan-filter"></div>
</div>
<div class="advance-overlay-footer">...two buttons</div>
</div>
</div>
So, I what I would like to achieve eventually is that, I want respsonsive overlay at right side of the browser window, provided if I am decreasing height of the browser the buttons at bottom should stay there (fixed position) and content should be within limit of .advnaced-overlay-content-secion
for a responsive design I recommend you to read into the use of grid and espacially for mobile designs also the use of #media breakpoints.
for having some thing to stick at the bottom simply use:
position: fixed;
bottom: 0;
I am working on a service that will be load in front of a video. Here is some basic code that shows the main shape of the service : CodePen link
Here is the code :
HTML
<div class="container">
<div class="sidezone">
<div class="header">
</div>
<div class="tab">
<div class="tab_elt active_tab">Tab 1</div>
<div class="tab_elt">Tab 2</div>
<div class="tab_elt">Tab 3</div>
<div class="tab_elt">Tab 5</div>
</div>
<div class="content">
</div>
</div>
</div>
CSS
.container {
position: relative;
width: 1280;
height: 720px;
margin: auto 50px;
background-color: green;
}
.sidezone {
box-sizing: border-box;
position: absolute;
background-color: rgba(0, 0, 0, 0.5);
top: 0; right: 0;
width: 500px;
height: 720px;
padding: 26px 52px 26px 16px;
}
.sidezone:before {
content: '';
position: absolute;
top: 0; left: -50px; bottom: 0;
width: 0;
height: 0;
border-top: 0px solid transparent;
border-bottom: 720px solid transparent;
border-right: 50px solid rgba(0, 0, 0, 0.5);
}
.header {
color: #fff;
background-color: #000;
overflow: hidden;
font-family: o-HelveticaNeue, Helvetica, Arial, sans-serif;
font-weight: 700;
position: relative;
padding: 10px 10px 20px 10px;
margin-bottom: 10px;
height: 200px;
background-repeat: no-repeat;
background-size: cover;
background-image: url("http://lorempixel.com/550/200/sports");
background-position: center top;
}
.tab {
background: #000;
}
.tab_elt {
color: white;
display: inline-block;
width: 24%;
text-align: center;
padding: 4px 0;
margin-bottom: -2px;
}
.active_tab {
color: #f16e00;
border-bottom: 2px solid #f16e00;
}
.content {
height: 419px;
background-color: white;
}
My question is : How can I "fill" the "sidezone" part from the top to the bottom of my "tab" part with a color or a picture in pure CSS ?
I'd like to make something that looks more "natural" but now I feel like my header is just "stick" in my block...
I tried to make it work by cutting my ":before" element in two part : one that could be black as my tab (and my header if I remove the image) that will go from top to the bottom of the "tab", and an other that will start just after and go to the bottom. This way I could keep my current shape and have 2 differents color to do what i want, but can't achieve it...
I insist on the "pure CSS" (no SVG, no lib,...), I'm very limited in possibilities.
Is it possible ?
Edit : here a visual representation of what I try to achieve (sorry for my paint talent !)
Change the borders of your pseudo element to these:
border-top: 294px solid rgba(0, 0, 0, 0.5);
border-left: 20px solid transparent;
border-right: 30px solid rgba(0, 0, 0, 0.5);
You may have to adjust the border widths. But the idea is to draw a trapezium/trapezoid using the borders.
Then remove the background color on your sidezone and replace it with this:
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.5) 294px, transparent 294px);
Again, you can change the dimensions as you see fit.
See here: https://codepen.io/anon/pen/OKzWrN
Do you mean a background gradient?
Like this:
background: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(246,41,12,1) 66%, rgba(240,47,23,1) 71%, rgba(231,56,39,1) 100%);
I hope that this refers to what you were asking, but if you set one of the border-sides to a large size and solid color such as border-top: 10px solid blue;, then that could mimic the behavior that you are wanting.
EDIT: (I'm still not totally sure of what you are asking) I would create a div for the side, fill the background, and then have any elements that are inside the div to have background: transparent;. In my opinion, you should try not to use the ::before selector, as it might be difficult to tell where it actually goes.
Thanks to Frank Fajardo I manage to achieve what I wanted : https://codepen.io/mleger06/pen/WVddVg
HTML
<div class="container">
<div class="sidezone">
<div class="header"></div>
<div class="tab">
<div class="tab_elt active_tab">Tab 1</div>
<div class="tab_elt">Tab 2</div>
<div class="tab_elt">Tab 3</div>
<div class="tab_elt">Tab 5</div>
</div>
<div class="content"></div>
</div>
</div>
CSS
.container {
position: relative;
width: 1280;
height: 720px;
margin: auto 50px;
background-color: green;
}
.sidezone {
box-sizing: border-box;
position: absolute;
background-image: linear-gradient(to bottom, #000 294px, rgba(0, 0, 0, 0.5) 294px);
top: 0; right: 0;
width: 500px;
height: 720px;
padding: 26px 52px 26px 16px;
}
.sidezone:before {
content: '';
position: absolute;
top: 0; left: -50px; bottom: 0;
width: 0;
height: 0;
border-top: 294px solid #000;
border-left: 20px solid transparent;
border-right: 30px solid #000;
}
.sidezone:after {
content: '';
position: absolute;
top: 294px; left: -30px; bottom: 0;
width: 0;
height: 0;
border-top: 426px solid rgba(0, 0, 0, 0.5);
border-left: 20px solid transparent;
border-right: 10px solid rgba(0, 0, 0, 0.5);
}
.header {
color: #fff;
background-color: #000;
overflow: hidden;
font-family: o-HelveticaNeue, Helvetica, Arial, sans-serif;
font-weight: 700;
position: relative;
padding: 10px 10px 20px 10px;
margin-bottom: 10px;
height: 200px;
}
.tab {
background: #000;
}
.tab_elt {
color: white;
display: inline-block;
width: 24%;
text-align: center;
padding: 4px 0;
margin-bottom: -2px;
}
.active_tab {
color: #f16e00;
border-bottom: 2px solid #f16e00;
}
.content {
height: 419px;
background-color: white;
}
I change the color a little bit and add a :after element in CSS to fill the bottom part and keep the same shape of the left of my sidezone.
Thanks for helping !
Edit : here is an other result by a collegue with an other "tricks" to make it works with image : https://codepen.io/anon/pen/zgpjRQ
I'm trying to achieve something like the image I've attached
And this is what I'm trying to do in css but couldn't get it to work.
#div_1 {
width: 90%;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
#div_2 {
height: 110%;
width: 30%;
margin-top: -5%;
margin-left: 60%;
vertical-align: top;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
<div id="div_wrapper">
<div id="div_1">
<div id="div_2"></div>
</div>
</div>
Give position: relative to the parent and position: absolute to the child element, which will make sure that the child is positioned relative to the parent element. Then you can place it wherever you want based on the appropriate top and left positioning properties which replaced the unnecessary margins:
#div_1 {
position: relative; /* added */
width: 90%;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0,0,0,.1);
}
#div_2 {
position: absolute; /* added */
height: 110%;
width: 30%;
top: -5%; /* modified */
left: 60%; /* modified */
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0,0,0,.1);
}
<div id="div_wrapper">
<div id="div_1">
Div 1
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div id="div_2">
Div 2
</div>
</div>
</div>
You can try something like below snippet. You need not mention .child div's height as it will be calculated when you set top and bottom.
.parent {
position: relative;
width: 80%;
height: 80vh;
margin: 5% auto;
background: #fff;
box-shadow: 0px 0px 5px #000;
}
.child{
position: absolute;
top:-5%;
bottom:-5%;
right: 10%;
width: 30%;
background: #fff;
box-shadow: 0px 0px 5px #000;
}
<div class="parent">
<div class="child">
</div>
</div>
What you need to do is to set your wrapper div position as relative and set it's display property to block.
Now you can set your desired width and height to the wrapper.
Wrapper is marked with red dashed line.
Now you have to set the height for the child elements to expand to their wrapper div.
You can do that by providing a
height: 100%
to div1
Next is to align child items to their parent element.
Usually to align a child element to it's parent you can set the position of parent as relative and child as absolute.
You can set position: absolute to div2 and position:relative to div1
I would suggest to set the location of div2 using top and left rather than margin-top and margin-left.
Here is a very nice explanation about positions and the common mistakes:
https://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/
and here https://css-tricks.com/absolute-positioning-inside-relative-positioning/ you can find some tips on how to position parent and child elements.
I have modified your code a bit, have a look at it here:
#div_wrapper {
display: block;
position: relative;
height: 200px; /* Change to whatever height you like */
width: 400px; /* Change to whatever width you like */
top: 50px; /* Just for demo */
left: 10px; /* Just for demo */
}
#div_1 {
display: block;
position: relative; /* Added */
width: 90%;
height: 100%; /* Added */
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
#div_2 {
position: absolute; /* Added */
height: 110%;
width: 30%;
top: -5%; /* Modified */
left: 60%; /* Modified */
vertical-align: top;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
<div id="div_wrapper">
<div id="div_1">
<div id="div_2"></div>
</div>
</div>
Try following code it can be work for you may be. You will see effect when "#div_1" have content or height.
#div_1 {
width: 90%;
position: relative;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
#div_2 {
width: 30%;
position: absolute;
top: -5%;
bottom: -5%;
left: 60%;
vertical-align: top;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
<style type="text/css">
#div_wrapper{
position: relative;
width: 100%;
}
#div_1 {
width: 90%;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
height: 300px;
margin-top: 100px;
position: relative;
}
#div_2 {
position: absolute;
height: 120%;
width: 30%;
right: 5%;
top:-10%;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
</style>
<div id="div_wrapper">
<div id="div_1"> div 1
<div id="div_2">div 2</div>
</div>
</div>
For this layout it would be good, if you use position:absolute for div_2 ID and position:relative for div_1 ID, this will let you position the child div anywhere relative to the parent and it is dependent on the height of div_1.
#div_1 {
width: 90%;
background: #FBFBFB;
display:inline-block;
position:relative;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
#div_2 {
width: 30%;
position:absolute;
right:10%;
top:-10px;
bottom:-10px;
vertical-align: top;
background: #FBFBFB;
box-shadow: 1px 1px 30px rgba(0, 0, 0, .1);
}
#div_wrapper{
text-align:center;
margin:50px 0px;
}
<div id="div_wrapper">
<div id="div_1">test
<div id="div_2">test2</div>
</div>
</div>
I'm coding some fancy stuff for teaching myself.
I have an aslope left corner. Now, i want to add the box shadow and it showed like the following image:
This is my code snippet:
html, body {
margin: 0px;
}
.navbar {
position:relative;
content:"";
border-left: 300em solid #454545;
border-bottom: 120px solid transparent;
z-index: 2;
box-shadow: 0px 8px 23px 4px black;
}
.under-bar {
margin-top: -40px;
background: #851e39;
height: 200px;
opacity: 0.8
}
<html>
<body>
<div class="navbar">
</div>
<div class="under-bar">
</div>
</body>
</html>
Can someone help me to set a box-shadow under the header?
You can use transform: rotate(); instead of the border tricks.
body {
margin: 0;
}
.navbar {
height: 200px;
background-color: #9d4b61;
position: relative;
overflow: hidden;
}
.navbar:before {
content: "";
position: absolute;
left: 0;
top: -50px;
width: 100%;
height: 100px;
box-shadow: 0px 8px 23px 4px #000;
transform: rotate(-1deg);
background-color: #333;
}
.menu {
position: relative;
left: 20px;
top: 20px;
color: #fff;
}
<div class="navbar">
<div class="menu">menu</div>
</div>
You can use a border-radius and transform: scale:
body {
margin: 0;
background: #9d4b61;
}
.navbar {
width: 100%;
height: 50px;
background: #5c5c5c;
border-radius: 0 0 100%/22px 0;
box-shadow: 0px 8px 23px 4px rgba(0,0,0,0.8);
transform: scale(1.1,1);
}
<div class="navbar"></div>
The border-radius: 0 0 100%/22px 0 set a radius in the bottom right corner, which is 100% wide and 22px height, giving the radius a "stretched" look.
The transform: scale(1.1,1) is stretching the entire element, to hide the box-shadow in each side.
I have two divs on top of each other (adjoined) and they booth as one unit shall have one box-shadow. Now the upper div gives shadow on the lower div which I don't want. I have tried to manipulate it with a "z-index:2" to be more on top but no luck.
I would like to hide the bottom shadow of the upper div and hide the top shadow of the lower div
Also I don't want the shadow to fold into the adjoined sides. The two divs should be one unit having one shadow
In my example here I have simpified the html
<div class="upper-box" style="width:100px;height:100px;">
</div>
<div class="lower-div" style="width:100px;height:100px;">
</div>
In the jsfiddle the css is all in original and here goes all the work of change.
.upper-box {
border-top: 0 none;
margin-bottom: 2px;
margin-top: -2px;
overflow: auto;
position: relative;
padding-top: 0;
/* Expanded panel gets emphasized by a shadow */
box-shadow: 0px 6px 50px 7px rgba(255,255,255,0.75),
0px 6px 50px 7px rgba(88,88,88,0.75),
0px 6px 50px 7px rgba(88,88,88,0.75),
0px 6px 50px 7px rgba(88,88,88,0.75)
;
z-index: 3;
border-style: solid;
border-color: #000000;
border-width: 0px;
position: relative;
}
.lower-div {
border-bottom: 0px;
box-shadow: 0px 6px 50px 7px rgba(88,88,88,0.75);
z-index: 2;
border-style: solid;
border-color: #000000;
border-width: 0px;
}
I would like to hide the bottom shadow of the upper div and hide the top shadow of the lower div
Also I don't want the shadow to fold into the adjoined sides. The two divs should be one unit having one shadow
Here is my live demo
https://jsfiddle.net/y289sdeb/
You could use a pseudo element, like this
.upper-box {
position: relative;
width: 100px;
height: 100px;
background: white;
}
.lower-div {
position: relative;
width: 100px;
height: 100px;
background: white;
}
.upper-box::after,
.lower-div::after {
content: '';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
box-shadow: 0px 6px 50px 7px rgba(88, 88, 88, 0.75);
z-index: -1;
}
<div class="upper-box">
</div>
<div class="lower-div">
</div>
Based on a comment, a wrapper can be used
.wrapper {
position: relative;
display: inline-block;
}
.upper-box {
position: relative;
width: 100px;
height: 100px;
}
.lower-div {
position: relative;
width: 100px;
height: 100px;
}
.wrapper::after {
content: '';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
box-shadow: 0px 6px 50px 7px rgba(88, 88, 88, 0.75);
z-index: -1;
}
<div class="wrapper">
<div class="upper-box">
</div>
<div class="lower-div">
</div>
</div>