Here is the codepen. As you can see using position: sticky; the div width is not overlapping. However when I tried using position: fixed the div width is overlapping. Can anyone help me with how to achieve it? My goal is I what my footer class to fixed at the bottom even I scroll.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
font-size: inherit;
}
.left {
position: fixed;
top: 0;
width: 43px;
left: 0;
bottom: 0;
/* border-right: 1px solid #e8edf3; */
background-color: red;
padding: 6px;
overflow: hidden;
transition: .18s ease-out width;
}
.main {
margin: 0;
padding: 0;
position: absolute;
top: 0;
left: 42px;
right: 0;
bottom: 0;
overflow: auto;
transition: .22s ease left;
background: green;
}
.tool {
display: flex;
padding: 3px 4px;
/* box-sizing: border-box; */
align-items: center;
width: 100%;
border-bottom: 1px solid #e8edf3;
position: sticky;
top: 0;
background-color: #ffffff;
z-index: 13;
justify-content: space-between;
}
.footer {
padding: 3px 4px;
align-items: center;
width: 100%;
border-bottom: 1px solid #e8edf3;
position: fixed;
bottom: 0;
background-color: #ffffff;
z-index: 13;
display: flex;
justify-content: space-between;
}
<div class="left">
</div>
<div class="main">
<div class="tool">
<div class="test">Test toolbar design</div>
<div class="test">Test toolbar design</div>
</div>
<div class="footer">
<div class="test">Test footer design</div>
<div class="test">Test footer design</div>
</div>
<div>
Change the footer width to width: calc(100% - 43px);. Where 43px is the value of the left property of its relative parent (.main).
.footer {
width: calc(100% - 43px);
}
.left.expand ~ .main .footer {
width: calc(100% - 320px);
}
Related
In a css/html element on a webpage I've made, if a user zooms in or out on their browser, artifacts emerge showing a line. Here is a code pen of the issue. Zoom in or out on your browser to see the red line at top emerge like below:
I've read that these problems can emerge because a browser can set the zoom to 1.5x, thus creating rounding issues for pixels. See slack post here. But I'm not sure what the appropriate fix should be. In my case I want the triangles at each end of my rectangle element which I create via css styling. Besides recreating the graphic via svg, is there any good tricks?
Here is the html/css in codepen:
#root {
display: block;
width: 100%;
height: 100%;
background-color: lightgrey;
padding: 24px;
max-width: 400px;
float: center;
position: relative;
}
#gridRoot {
display: flex;
flex-flow: column wrap;
top: 50%;
left: 50%;
align-content: center;
}
#LegendContainer {
box-sizing: border-box;
display: flex;
flex-flow: row nowrap;
width: 100%;
align-items: center;
justify-content: space-between;
}
#container {
background-color: grey;
postion: relative;
height: 120px;
justify-content: center;
left: calc(50% - 60px);
text-align: center;
top: calc(50% - 60px);
}
#circle {
transform: rotate(7.39deg);
}
#jss {
display: flex;
position: absolute;
background: red;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss::before {
left: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss::after {
right: 0;
width: 0;
bottom: 0;
height: 0;
content: '';
position: absolute;
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="gridRoot">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
</div>
</div>
</div>
</div>
</div>
The ::before and ::after elements seemed to be causing the issue. Solution;
body {
margin: 0;
}
#container {
background-color: grey;
position: relative;
display: flex;
height: 120px;
justify-content: center;
text-align: center;
}
#jss {
display: flex;
position: absolute;
top: 40px;
width: 110px;
opacity: 80%;
height: 20px;
}
#jss-internal {
background: red;
width: 100%;
}
#jss-before {
content: '';
transform: rotate(180deg);
border-top: 10px solid white;
border-left: 10px solid #00007f;
border-bottom: 10px solid white;
}
#jss-after {
border-top: 10px solid white;
border-left: 10px solid #7f0000;
border-bottom: 10px solid white;
}
<div id="root">
<div id="LegendContainer">
<div id="container">
<div id="circle">
</div>
<div id="jss">
<div id="jss-before">
</div>
<div id="jss-internal">
</div>
<div id="jss-after">
</div>
</div>
</div>
</div>
</div>
can anyone help me on how to remove the huge white space between the two images? Both images are in their respective divs with layer effects when hovered. I have tried changing display to inline-block and setting font-size to 0 but nothing works. I also want the two images to be at the center when adjusted. I may have incorrectly apply the mentioned efforts to different classes or divs throughout the process but I am not sure where I did wrong.
Attached are the html and css along with a screenshot of how it looks like on local server. I hope the attachments are useful. Thank you.
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.campus-col{
flex-basis: 32%;
border-radius: 10px;
margin-bottom: 30px;
position: relative;
overflow: hidden;
}
.campus-col img{
width: 100%;
display: block;
}
.layer{
background: transparent;
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
transition: 0.5s;
}
.layer:hover{
background: rgba(226,0,0,0.7);
}
.layer h3{
width: 100%;
font-weight: 500;
color: #fff;
font-size: 26px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
position: absolute;
opacity: 0;
transition: 0.5s;
}
.layer:hover h3{
bottom: 49%;
opacity: 1;
<div class="row">
<div class="campus-col">
<img src="#">
<div class="layer">
<h3>TEXT</h3>
</div>
</div>
<div class="campus-col">
<img src="#">
<div class="layer">
<h3>MESSENGER</h3>
</div>
</div>
</div>
Like this?
If so you just need to use display: flex and align-items: flex-start
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.row {
display: flex;
align-items: flex-start
}
.campus-col{
flex-basis: 32%;
border-radius: 10px;
margin-bottom: 30px;
position: relative;
overflow: hidden;
}
.campus-col img{
width: 100%;
display: block;
}
.layer{
background: transparent;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: 0.5s;
}
.layer:hover{
background: rgba(226,0,0,0.7);
}
.layer h3{
width: 100%;
font-weight: 500;
color: #fff;
font-size: 26px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
position: absolute;
opacity: 0;
transition: 0.5s;
text-align: center;
}
.layer:hover h3{
bottom: 49%;
opacity: 1;
<div class="row">
<div class="campus-col">
<img src="https://via.placeholder.com/150">
<div class="layer">
<h3>TEXT</h3>
</div>
</div>
<div class="campus-col">
<img src="https://via.placeholder.com/150">
<div class="layer">
<h3>MESSENGER</h3>
</div>
</div>
</div>
Try to make row flex container, then align content to center, with gap you can make space between images:
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.row {
display: flex;
justify-content: center;
gap: 1em;
}
.campus-col{
flex-basis: 32%;
border-radius: 10px;
margin-bottom: 30px;
position: relative;
overflow: hidden;
}
.campus-col img{
width: 100%;
display: block;
}
.layer{
background: transparent;
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
transition: 0.5s;
}
.layer:hover{
background: rgba(226,0,0,0.7);
}
.layer h3{
width: 100%;
font-weight: 500;
color: #fff;
font-size: 26px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
position: absolute;
opacity: 0;
transition: 0.5s;
}
.layer:hover h3{
bottom: 49%;
opacity: 1;
<div class="row">
<div class="campus-col">
<img src="https://picsum.photos/200">
<div class="layer">
<h3>TEXT</h3>
</div>
</div>
<div class="campus-col">
<img src="https://picsum.photos/200">
<div class="layer">
<h3>MESSENGER</h3>
</div>
</div>
</div>
you can use bootstrap class for width .campus-col or use custom width
You can use (justify-content: center) to center the children in the flex displayed parent, in short: center the .img in .row.
Then you can add margin for spaces between them (the method used in the code below).
Or you can use (justtify-content: space-between) and set the width of the parent (.row), then each .img will be at the edge or it's direction (left or right)
Check this for more detalis: A Complete Guide to Flexbox
The Code:
.row {
display: flex;
justify-content: center;
}
.img {
width: 200px;
height: 300px;
border: 1px solid;
border-radius: 6px;
}
.img {
margin: 0 20px;
}
<div class="row">
<div class="img img1"></div>
<div class="img img2"></div>
</div>
Solution based on your code:
Edited:
.row {
display: flex;
justify-content: center;
}
.campus-col{
height: 200px; /* delete later, added to see the changes */
border: 1px solid #ddd; /* delete later, added to see the changes */
margin: 0 10px; /* add/remove spaces (left right of each one) */
}
The Code:
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.row {
display: flex;
justify-content: center;
}
.campus-col{
flex-basis: 32%;
border-radius: 10px;
margin-bottom: 30px;
position: relative;
overflow: hidden;
height: 200px;
border: 1px solid #ddd;
margin: 0 10px;
}
.campus-col img{
width: 100%;
display: block;
}
.layer{
background: transparent;
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
transition: 0.5s;
}
.layer:hover{
background: rgba(226,0,0,0.7);
}
.layer h3{
width: 100%;
font-weight: 500;
color: #fff;
font-size: 26px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
position: absolute;
opacity: 0;
transition: 0.5s;
}
.layer:hover h3{
bottom: 49%;
opacity: 1;
}
<div class="row">
<div class="campus-col">
<img src="#">
<div class="layer">
<h3>TEXT</h3>
</div>
</div>
<div class="campus-col">
<img src="#">
<div class="layer">
<h3>MESSENGER</h3>
</div>
</div>
</div>
In my webpage I have a left and a right part, they are not on the same nesting though. I want the left part to fill 25% of the page and the right part to fill the rest of the width.
Simply putting 75% isn't cutting it for me because the right part also needs a 30px right margin. A right padding won't work because my content and background-color overflows then.
Do you have an idea how to solve this?
The .left (blue) and .right(yellow) div should always perfectly meet each other and the .right needs to keep it's 30px right margin.
body {
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
overflow: hidden;
}
.main {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
overflow: hidden;
background-color: grey;
}
.left {
position: absolute;
top: 0;
bottom: 0;
padding-top: 0;
padding-bottom: 0;
left: 0;
width: 25%;
border-right: 1px solid #eeeeee;
background-color: lightblue;
}
.right {
position: absolute;
width: 75%;
right: 0px;
top: 45px;
bottom: 0;
/*padding-right: 30px;*/
margin-right: 30px;
background-color: yellow;
}
<body>
<div class="main">
<div class="left">TEST</div>
</div>
<div class="right">TEST</div>
</body>
It's not a good idea to create a layout using only absolute position. You may better rely on flexbox for example:
body {
height: 100vh;
margin: 0;
display: flex;
background: grey;
}
.left {
flex: 1;
border-right: 1px solid #eeeeee;
background-color: lightblue;
}
.right {
flex: 4;
margin-top: 45px;
margin-right: 30px;
background-color: yellow;
}
<div class="left">TEST</div>
<div class="right">TEST</div>
But in case you want to keep your code, you need to consider the margin within the calculation of the width:
body {
display: block;
position: absolute;
width: 100%;
height: 100%;
top: 0;
bottom: 0;
overflow: hidden;
}
.main {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
overflow: hidden;
background-color: grey;
}
.left {
position: absolute;
top: 0;
bottom: 0;
padding-top: 0;
padding-bottom: 0;
left: 0;
width: 25%;
border-right: 1px solid #eeeeee;
background-color: lightblue;
}
.right {
position: absolute;
width: calc(75% - 30px);
right: 0px;
top: 45px;
bottom: 0;
/*padding-right: 30px;*/
margin-right: 30px;
background-color: yellow;
}
<body>
<div class="main">
<div class="left">TEST</div>
</div>
<div class="right">TEST</div>
</body>
The thing is, i have a sided fixed nav menu with 230px width and now I want to make a fixed top nav bar with 100% width.
But when I add any element with right float in the top navigation bar, the elements are all hidden because the bar has 100% width plus 230px from the sidebar.
nav#fixed-nav-top {
position: fixed;
top: 0;
left: 230px;
z-index: 9999;
width: 100%;
height: 50px;
border-left: 1px solid #191b1b;
background-color: #141616;
border-bottom: 1px #252525 solid;
}
nav#nav-sided {
position: fixed;
font-family: "Helvetica"; /* Tahoma */
color: #c1c1c1;
height: 100%;
width: 230px;
top: 0;
left: 0;
background-color: #262626;
border-right: 1px #252525 solid;
z-index: 8888;
}
<nav id="fixed-nav-top">
<div id="top-main">
</div>
<div id="user-area">
</div>
</nav>
<nav id="nav-sided">
<div id="logo">
<div class="main-logo">:)</div>
</div>
other stuffs
</nav>
With your current styles, instead of width:100% (remove this), add right:0:
nav#fixed-nav-top {
position: fixed;
top: 0;
left: 230px;
right:0;
z-index: 9999;
height: 50px;
border-left: 1px solid #191b1b;
background-color: #141616;
border-bottom: 1px #252525 solid;
}
Example:
nav#fixed-nav-top {
position: fixed;
top: 0;
left: 230px;
right:0;
z-index: 9999;
height: 50px;
border-left: 1px solid #191b1b;
background-color: #141616;
border-bottom: 1px #252525 solid;
}
nav#nav-sided {
position: fixed;
font-family: "Helvetica"; /* Tahoma */
color: #c1c1c1;
height: 100%;
width: 230px;
top: 0;
left: 0;
background-color: #262626;
border-right: 1px #252525 solid;
z-index: 8888;
}
<nav id="fixed-nav-top">
<div id="top-main">
</div>
<div id="user-area">
</div>
</nav>
<nav id="nav-sided">
<div id="logo">
<div class="main-logo">:)</div>
</div>
other stuffs
</nav>
You don't need calc or anything fancy, it's simple as this. Of course you can make the sidebar be above the navbar if you'd like to, here it is below it.
Note that you can use box-sizing: border-box to make your life much easier.
* {
box-sizing: border-box;
}
.body {
padding-left: 200px;
padding-top: 50px;
}
.sidebar {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 200px;
padding-top: 50px;
background: red;
}
.left {
float: left;
}
.right {
float: right;
}
.navbar {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 50px;
padding-left: 200px;
background: black;
color: white;
}
<div class="body">
<div class="sidebar">Sidebar</div>
<div class="navbar">
<div class="left">Left</div>
<div class="right">Right</div>
</div>
<div class="main">Blablabla</div>
</div>
style:
div{
position:absolute;
left:230px;
right:0px;
}
example: JSFiddle
or:
div{
margin-left:230px;
}
example: JSFiddle
A web app has the following structure but the scroll goes off the page. Any ideas what is going wrong?
http://jsfiddle.net/kYEES/
HTML
<div class="wrapper">
<div class="container">
<div class="fixed-height">
<p>Fixed height div</p>
</div>
<div class="scrolling-height">
<p>Scrolling div</p>
</div>
</div>
</div>
CSS
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
height: 100%;
width: 100%;
}
.container {
background: lightgray;
height: 100%;
overflow: hidden;
padding: 10px;
position: relative;
}
.fixed-height {
background-color: yellow;
height: 40px;
padding: 5px 10px;
}
.scrolling-height {
background-color: green;
bottom: 0;
height: 100%;
overflow-y: scroll;
margin-bottom: 20px;
padding: 5px 10px;
position: absolute;
top: 40px;
}
Something like this: http://jsfiddle.net/DhWm5/3/
I gave your container a position: relative and your scrollable div an absolute position:
.container {
background: lightgray;
height: 100%;
padding: 10px;
position:relative;
}
.scrolling-height {
background-color: green;
margin-bottom: 50px;
overflow-y: scroll;
padding: 5px 10px;
position:absolute;
top: 50px; bottom: 0;
}
The top: 50px is to allow for the fixed height div and its padding;