I am trying to get two inline-block elements to position where the left side #faqBlock remains positioned fixed and then #blueBox is positioned relative. This basic functionality is working in the snippet, but the containerRight is overtaking containerLeft.
How can I main the containers width and inline-block display while having #faqBlock being positioned fixed?
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft,
#containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
Elements with position fixed aren't in the regular flow, so it won't ever take up space in the way you are imagining. You can add margin-left: 40%; (equal to the width of the left container) onto the right container to make it look like it's holding space.
If this isn't what you are looking for, let me know!
#page-wrap {
margin-top: 70px;
max-width: 100%;
}
#containerLeft, #containerRight {
display: inline-block;
vertical-align: top;
box-sizing: border-box;
height: 200vh;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: blue;
box-shadow: 10px 5px 5px rgba(0,0,0,0.12);
}
/*-- Container Right --*/
#containerRight {
width: 60%;
position: relative;
margin-left: 40%;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div><div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
All you need to assign is left:40% to your containerRight as it's already positioned relative
As your width of fixed container is 40%.
#page-wrap {
margin-top: 70px;
max-width: 100%;
border: 1px solid;
}
#containerLeft,
#containerRight {
vertical-align: top;
box-sizing: border-box;
height: 200vh;
border: 2px solid red;
}
/*-- Container Left --*/
#containerLeft {
width: 40%;
position: fixed;
}
#faqBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
background: #b82222;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
#blueBlock {
width: 70%;
height: 75vh;
margin: 50px auto;
display: block;
border: 2px solid orange;
background: blue;
box-shadow: 10px 5px 5px rgba(0, 0, 0, 0.12);
}
/*-- Container Right --*/
#containerRight {
left: 40%;
width: 60%;
position: relative;
}
<div id="page-wrap">
<div id="containerLeft">
<div id="faqBlock">
gfsag
</div>
</div>
<div id="containerRight">
<div id="blueBlock">
gfsag
</div>
</div>
</div>
Related
I'm trying to adapt the images from the buttons (#but2, #but1) to their full height possible (in the div) and their corresponding width according to their height (width: auto).
I've tried with this code for the images from the buttons:
#but1 img, #but2 img{
height: 100%;
width: auto;
}
But I can't get the output I want. I share an image showing what's the output of that code and what's the output I want.
Thanks a lot for your help!
#but1 {
margin-left: auto;
margin-right: 5px;
background-color: transparent;
border: 0;
}
#but2 {
margin-left: 5px;
margin-right: auto;
background-color: transparent;
border: 0;
}
#but1 img,
#but2 img {
width: 100%;
height: auto;
}
.button-container {
background-color: #fff;
width: 50%;
height: 50px;
border-radius: 125px;
margin-left: auto;
margin-right: auto;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
}
#but-cont-2 {
margin-top: 25px;
background-color: #79b2f7;
position: relative;
}
#textarea {
width: 85%;
background-color: transparent;
border: 0;
height: 100%;
outline: none;
resize: none;
float: left;
}
.text {
width: 100%;
background-color: transparent;
float: right;
border: 0;
margin: 0;
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: right;
right: 21px;
}
<div>
<div class="button-container" id="but-cont-1">
<textarea id="textarea" name="prod"></textarea>
<button onclick="sub()" id="but1">
<img id="but1" src="https://cdn-icons-png.flaticon.com/512/861/861180.png" alt="">
</button>
</div>
<div class="button-container" id="but-cont-2">
<label id="cont" class="text"></label>
<button id="but2">
<img id="but2" src="https://cdn-icons-png.flaticon.com/128/1078/1078599.png" alt="">
</button>
</div>
</div>
Try using display: flex; for the button and try to resize the images with pixels like width: 20px; and height: auto; or verse versa, it should fix it.
Here is my idea of doing that: https://jsfiddle.net/L1ma5qrc/86/
*{
margin: 0;
padding: 0;
}
body{
padding: 20px
}
#but1 {
/* margin-right: 5px; */
/* background-color: transparent; */
border: 0;
background-color: #fff;
width: 50%;
height: 50px;
border-radius: 125px;
border: 1px solid lightgray;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
}
#but1:before {
content: "";
display: block;
background: url("https://cdn-icons-png.flaticon.com/128/1078/1078599.png") no-repeat;
background-size: 50%;
background-position: center right;
height: 50px;
width: 50px;
margin-right: 16px;
margin-left: auto;
}
#but2 {
/* margin-right: 5px; */
/* background-color: transparent; */
border: 0;
background-color: #fff;
width: 50%;
height: 50px;
border-radius: 125px;
border: 1px solid lightgray;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
}
#but2:before {
content: "";
display: block;
background: url("https://cdn-icons-png.flaticon.com/128/1078/1078599.png") no-repeat;
background-size: 50%;
background-position: center left;
height: 50px;
width: 50px;
margin-right: auto;
margin-left: 16px;
}
<div>
<div class="button-container" id="but-cont-1">
<button id="but1">
</button>
</div>
<div class="button-container" id="but-cont-2">
<button id="but2">
</button>
</div>
</div>
I think I'd look at applying the images as backgrounds. It cleans up the markup quite a bit and makes positioning easier.
Other tips:
Don't use floats for alignment. They're an outdated layout technique and have very few appropriate uses anymore.
Avoid absolute positioning when possible. It can also be troublesome.
Floats don't work with absolute positioning. Use one or the other if you must.
Rely less on IDs in your CSS. Ideally everything is class-based so it's reusable.
Consider not removing outlines. They're important for accessibility.
Avoid using label elements other than with form inputs. That would be nonstandard and also a possible accessibility issue.
.button-container {
background-color: #fff;
width: 50%;
height: 50px;
border-radius: 125px;
margin-left: auto;
margin-right: auto;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
position: relative;
overflow: hidden;
}
.button-container.alt {
margin-top: 25px;
background-color: #79b2f7;
}
.button-container button {
width: 100%;
height: 100%;
background-size: auto 60%;
background-position: 93% 50%;
background-repeat: no-repeat;
border: 0;
}
.button-container button.icon-recycle {
background-image: url("https://cdn-icons-png.flaticon.com/512/861/861180.png");
}
.button-container button.icon-trash {
background-image: url("https://cdn-icons-png.flaticon.com/128/1078/1078599.png");
background-position: 7% 50%;
}
#textarea {
position: absolute;
width: 85%;
background-color: transparent;
border: 0;
height: 100%;
outline: none;
resize: none;
}
.text {
width: 100%;
background-color: transparent;
border: 0;
margin: 0;
position: absolute;
top: 50%;
transform: translateY(-50%);
text-align: right;
right: 21px;
}
<div>
<div class="button-container">
<textarea id="textarea" name="prod"></textarea>
<button class="icon-recycle" onclick="sub()"></button>
</div>
<div class="button-container alt">
<span class="text"></span>
<button class="icon-trash"></button>
</div>
</div>
I am trying to achieve the layout in the image below. The hidden-container div is positioned at 0, 0 on the parent main-container div and shown on button click.
I have done a mock up fiddle here.. The col size is smaller so it is easier to see in the fiddle.
.content {
margin: 50px auto 0 auto;
}
#main-container {
width: 100%;
max-width: 500px;
max-height: 200px;
overflow: hidden;
margin: 50px auto 0 auto;
}
#hidden-container {
padding: 0;
max-width: 500px;
max-height: 200px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1047;
}
#plyr-container {
padding: 0;
max-width: 300px;
max-height: 200px;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1048;
background-color: red;
}
#info-container {
max-width: 300px;
max-height: 200px;
width: 100%;
height: 100%;
z-index: 1048;
right: 0;
top: 0;
box-sizing: border-box;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
}
#plyra,
#plyrb {
padding: 0;
text-align: left;
position: absolute;
max-width: 300px;
max-height: 200px;
width: 100%;
height: 50%;
z-index: 1049;
}
#plyra {
left: 0;
top: 0;
height: 50%;
background-color: green;
}
#plyrb {
left: 0;
top: 50%;
height: 50%;
border-top: 1px solid black;
background-color: yellow;
}
<div class="content">
<div id="main-container">
<div id="hidden-container">
<div id="plyr-container">
<div id="plyra"></div>
<div id="plyrb"></div>
</div>
<div id="info-container"></div>
</div>
</div>
</div>
Any help is appreciated.
You can do this using flexbox. I did some modification with changing the # to class instead. You have some unnecessary properties, like z-index, top, left. Those properties won't work unless you have absolute or relative on the element. You don't need them to position it and in this particular case they really do nothing. Is this something you where looking for?
I strongly recommend reading this article on css-tricks.com about flexbox.
DEMO: Fiddle
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.content {
margin: 50px auto 0 auto;
}
.main-container {
width: 100%;
overflow: hidden;
margin: 50px auto 0 auto;
background-color: deepskyblue;
}
.hidden-container {
width: 100%;
height: 100%;
display: flex;
flex-direction: row;
background-color: lightcoral;
}
.plyr-container {
flex-basis: 100%;
flex-grow: 1;
min-height: 300px;
display: flex;
flex-direction: column;
background-color: red;
}
.info-container {
flex-basis: 300px;
flex-grow: 1;
flex-shrink: 0;
-webkit-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
-moz-box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
box-shadow: -4px 0px 5px 0px rgba(50, 50, 50, 0.3);
background-color: deeppink;
}
.plyra,
.plyrb {
text-align: left;
flex-basis: 50%; //use this instead of width
flex-grow: 1;
flex-shrink: 0;
}
.plyra {
background-color: green;
}
.plyrb {
border-top: 1px solid black;
background-color: yellow;
}
<div class="content">
<div class="main-container">
<div class="hidden-container">
<div class="plyr-container">
<div class="plyra">a</div>
<div class="plyrb">a</div>
</div>
<div class="info-container">d</div>
</div>
</div>
</div>
Refer this as an example you could even do that using display:inline-block, along-with css calc() function to minus the width of 300px from overall container to align two column i.e col1 and col2 as below,
#container {
width: 100%;
height: 100vh;
font-size: 0;
}
#container > .col1 {
width: calc(100% - 300px);
height: 100%;
background: #111;
display: inline-block;
}
#container > .col1 > .c1 {
width: 100%;
height: 50%;
background: pink;
display: inline-block;
}
#container > .col1 > .c2 {
width: 100%;
height: 50%;
background: lightblue;
display: inline-block;
}
#container > .col2 {
width: 300px;
height: 100%;
background: yellow;
display: inline-block;
}
<div id="container">
<div class="col1">
<div class="c1"></div>
<div class="c2"></div>
</div>
<div class="col2"></div>
</div>
I am trying to set three divs side by side with each equal width and height.
I am unable to remove that extra space at right at right most div. If I set its margin-right to 0 the rightmost div becomes bigger than other two.
Here is the fiddle.
Css:
.recordpopup {
position: fixed;
z-index: 10000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: rgba( 0, 0, 0, .8);
background-position: 50% 50%;
background-repeat: no-repeat;
display: block;
}
.recordpopup .retry {
background-color: black;
border: 1px solid white;
xborder-radius: 8px;
box-sizing: border-box;
color: white;
font-family: ProximaNova-Regular;
font-size: 16px;
font-weight: bold;
xheight: 50px;
margin-left: auto;
margin-right: auto;
padding-top: 0px;
position: relative;
text-align: center;
top: 30%;
width: 40%;
z-index: 15000;
border-radius: 8px;
padding: 20px 10px;
background-image: url('images/gray_bar.png');
background-repeat: repeat-x;
background-color: white;
}
#product-wrapper {
overflow: hidden;
margin-top: 25px;
}
.product {
float: left;
width: 33%;
display: table-cell;
width: 33.33333333%;
}
.product .container {
margin-right: 10px;
padding: 10px;
background-color: #000;
}
.product .container img {
display: block;
margin: 0 auto;
width: 100%;
}
#closeRecord {
background: black none repeat scroll 0 0;
border: 2px solid white;
border-radius: 50%;
color: white;
cursor: pointer;
height: 25px;
right: -15px;
left: right;
position: absolute;
top: -10px;
width: 25px;
}
Html:
<div class="recordpopup">
<div class="retry">
<div id="closeRecord">x</div>
<div style="width: 100%;text-align: left;margin: 5px 0;font-size: 12px;color:#333;"><span class="TitleText">Lorem Ipsum Lorem Ipsum</span> </div>
<div id="product-wrapper">
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
<div class="product">
<div class="container">
<img src="images/circle.png">
<p>Dummy</p>
</div>
</div>
</div>
</div>
</div>
Here is my solution.
The key is removing the margin-right: 10px and adding
.product:nth-child(1) .container{
margin-right:5px;
}
.product:nth-child(2) .container{
margin: 0 5px 0 5px;
}
.product:nth-child(3) .container{
margin-left: 5px;
}
JSFiddle ===> https://jsfiddle.net/kjkk3f9d/1/
The margin-right: 10px was pushing out your divs, replace it with margin: 0 5px to give a uniform look
.product .container {
margin: 0px 5px;
padding: 10px;
background-color: #000;
}
https://jsfiddle.net/kjkk3f9d/3/
check out my fiddle:
https://jsfiddle.net/kjkk3f9d/2/
the important styles are
#product-wrapper {
overflow: hidden;
margin-top: 25px;
display: flex;
justify-content: space-between;
}
.product {
flex-basis:0;
flex: 1 1 auto;
margin: 5px;
}
I have an outer div with box-shadow and I want this to appear over an inner div. But it always appears under it. The jsfiddle is here.
My HTML is:
<div class="wrapper">
<div class="inner">
</div>
</div>
And CSS:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner{
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
}
Is it possible to get it so that the box-shadow appears over the inner blue div? The semantics of the HTML cannot change.
Set the position of the child to relative and the z-index to -1:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
<div class="wrapper">
<div class="inner">
</div>
</div>
update the styles of inner class with position absolute and give z-index: -1;;
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
Here is the updated jsFiddle
You can do what you are wanting without the inner container as well.
http://codepen.io/creativenauts/pen/rLWZqp
* {
box-sizing: border-box;
}
.wrapper {
width: 200px;
height: 100px;
border: 20px solid #fff;
background-color: lightblue;
box-shadow: 0px 0px 1px rgba(#000, 0.5);
position: relative;
&:before {
position: absolute;
content: '';
width: 100%;
height: 100px;
top: -20px;
left: -20px;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
}
My HTML:
<!-- Content -->
<div class="content">
<!-- Content left -->
<div class="content-left"></div>
<!-- Content center -->
<div class="content-center">
</div>
<!-- Content right -->
<div class="content-right"></div>
</div>
My CSS:
.content
{
background-color: black;
height: auto;
margin: 80px auto 0px auto;
min-height: 100px;
padding: 10px 10px;
width: 1200px;
}
.content-center
{
-khtml-box-shadow: 0px -3px 5px rgba(0,0,2,2);
-moz-box-shadow: 0px -3px 5px rgba(0,0,2,2);
-webkit-box-shadow: 0px -3px 5px rgba(0,0,2,2);
background-color: #ffffff;
border-left: 1px solid;
border-right: 1px solid;
border-color: #999999;
box-shadow: 0px -3px 5px rgba(0,0,2,2);
height : 900px;
float: left;
width : 800px;
}
.content-left
{
background-color: #fff;
float: left;
height: 300px;
width: 190px;
}
.content-right
{
background-color: #fff;
float: left;
height: 300px;
width: 190px;
}
My problem is DIV with class "content" don't have same height with other element as child of this tag. I want div with class "content" have dynamic height according to "content-center", "content-left" or "content-right". I have use min-height and height : auto in class "content" but it still not correct.
Add overflow:auto to .content
.content{
width: 1200px;
min-height: 100px;
height: auto;
margin: 80px auto 0px auto;
background-color: black;
padding: 10px 10px;
overflow:auto
}
DEMO
Try this:
* {
margin: 0;
padding: 0;
}
html, body {
height:100%;
}
.content {
width: 1200px;
min-height: 100px;
height: auto;
margin: 80px auto 0px auto;
background-color: black;
padding: 10px 10px;
display:table;
overflow:hidden;
height:100%;
}
Demo Here