I will try to create a slider(move to left or right), but when I set outer Container(.wrapper) width over 100vw and set the height to 100vh with every child div, It will overflow on vertical, how can I avoid it?
Open the detailed description of the picture
body{
padding : 0;
margin:0;
}
.wrapper {
width : 200vw;
}
.section {
width : 100vw;
height : 100vh;
position:relative;
float:left;
}
.section1 {
background-color : red;
}
.section2{
background-color : yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
if you want to edit with online editor, you can try it
and I don't know why if When I only have one child div(.section), the height doesn't vertical overflow(move up and down)
body{
padding : 0;
margin:0;
}
.wrapper {
width : 100vw;
}
.section {
width : 100vw;
height : 100vh;
position:relative;
float:left;
}
.section1 {
background-color : red;
}
/*
.section2 {
background-color : yellow;
}
*/
<div class="wrapper">
<div class="section section1">1</div>
<!--<div class="section section1">1</div>-->
</div>
Although your question says you're looking to hide the horizontal scrollbar (left and right), your image indicates that you're actually looking to hide the vertical scrollbar (up and down).
You're looking to add overflow-y: hidden to body in order to hide the vertical scrollbar:
body {
padding: 0;
margin: 0;
overflow-y: hidden;
}
.wrapper {
width: 200vw;
}
.section {
width: 100vw;
height: 100vh;
position: relative;
float: left;
}
.section1 {
background-color: red;
}
.section2 {
background-color: yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
Alternatively, if you are indeed looking to hide the horizontal scrollbar, this can be done with overflow-x: hidden, though note that your content won't actually be too tall to escape the bounds vertically with the horizontal scrollbar removed. Setting a height of 110vh demonstrates this working:
body {
padding: 0;
margin: 0;
overflow-x: hidden;
}
.wrapper {
width: 200vw;
}
.section {
width: 100vw;
height: 110vh;
position: relative;
float: left;
}
.section1 {
background-color: red;
}
.section2 {
background-color: yellow;
}
<div class="wrapper">
<div class="section section1">1</div>
<div class="section section2">2</div>
</div>
Hope this helps! :)
Related
I got a little problem when i want to put an overflow: scroll on an element. That element is going outside his parent and i want to just make it scroll.
I remade the problem on codepen so you can check it.
I would like to keep the entire page to not scroll. Just the element i want would be able to be scrolled.
Sorry for my english.
* {
border: 1px solid black;
}
html {
height: 100vh;
margin: 0;
padding: 5px;
}
body {
height: 100%;
margin: 0;
}
img {
width: 150px;
display: block;
margin: auto;
margin-top: 50px;
}
.website {
width: 960px;
margin: auto;
}
input {
width: 100%;
}
.yes {
height: 150px;
}
.container_scroll {
overflow: scroll; /* not working*/
}
<img src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/5f4bd7a6-f763-4518-9b81-bdfd40ce3fc9/d26yer1-421bb5b8-9fc2-4d5a-b2d1-1e1f81b26b82.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzVmNGJkN2E2LWY3NjMtNDUxOC05YjgxLWJkZmQ0MGNlM2ZjOVwvZDI2eWVyMS00MjFiYjViOC05ZmMyLTRkNWEtYjJkMS0xZTFmODFiMjZiODIucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.p5vfqGmq9kIylfG3glHGa20CAPUtoWlAxKEGpIvGOi8">
<div class="website">
<section>
<h2>title</h2>
<input type="text" placeholder="my_text">
<div class="container_scroll">
<div class="yes"></div>
<div class="yes"></div>
<div class="yes"></div>
</div>
</section>
</div>
Assuming you're trying to scroll on the y-axis (up and down, not left to right), it's not scrolling because you don't have a height set on the parent. You only have height set on the children for a total of 150px a piece, or 450px overall. Also - if you want to make sure you ONLY scroll up and down, you'll want to specify that you want to only scroll on that axis, and not the other - as seen below.
If you tried changing the overflow property to auto instead of scroll (a good way to check if it will have any overflow because scrollbars ONLY appear if needed) - you see that a scrollbar doesn't appear - so there is no overflow currently.
If you want to have a scroll, you'll need to set the height to less than the overall height of the children (450px).
* {
border: 1px solid black;
}
html {
height: 100vh;
margin: 0;
padding: 5px;
}
body {
height: 100%;
margin: 0;
}
img {
width: 150px;
display: block;
margin: auto;
margin-top: 50px;
}
.website {
width: 960px;
margin: auto;
}
input {
width: 100%;
}
.yes {
height: 150px;
}
.container_scroll {
overflow-x: hidden; /* Hide horizontal scrollbar */
overflow-y: scroll; /* Add vertical scrollbar */
height: 300px;
}
<img src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/5f4bd7a6-f763-4518-9b81-bdfd40ce3fc9/d26yer1-421bb5b8-9fc2-4d5a-b2d1-1e1f81b26b82.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzVmNGJkN2E2LWY3NjMtNDUxOC05YjgxLWJkZmQ0MGNlM2ZjOVwvZDI2eWVyMS00MjFiYjViOC05ZmMyLTRkNWEtYjJkMS0xZTFmODFiMjZiODIucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.p5vfqGmq9kIylfG3glHGa20CAPUtoWlAxKEGpIvGOi8">
<div class="website">
<section>
<h2>title</h2>
<input type="text" placeholder="my_text">
<div class="container_scroll">
<div class="yes"></div>
<div class="yes"></div>
<div class="yes"></div>
</div>
</section>
</div>
I am trying to get a topbar to expand on Hover to show hidden text which could be social media icons, nav links etc.
However I am unsure of how to hide the text as it is appearing on and over the div below.
This is my (simple) code
html
<div class = "top"> This is the top
<div class = "invisible">can you see me</div>
</div>
<div class = "container">
<div class = "left">left</div>
<div class = "right">right</div>
</div>
This is my css
.top {
width : 100%;
background : blue;
padding-bottom : 25px;
position : relative;
}
.invisible {
position : absolute;
overflow: hidden;
top : 90%;
}
.top:hover {
padding-bottom : 150px;
background : yellow;
}
.container {
display : flex;
}
.left {
width : 50%;
background : red;
}
.right {
width : 50%;
background : green;
}
As you can see the Can you see me is appearing over the "left" text before hovering
You need to move overflow: hidden; to the parent element (.top) because it is the child, .invisible that is overflowing outside of .top.
.top {
width: 100%;
background: blue;
padding-bottom: 25px;
position: relative;
overflow: hidden;
}
.invisible {
position: absolute;
top: 90%;
}
.top:hover {
padding-bottom: 150px;
background: yellow;
}
.container {
display: flex;
}
.left {
width: 50%;
background: red;
}
.right {
width: 50%;
background: green;
}
<div class="top"> This is the top
<div class="invisible">can you see me</div>
</div>
<div class="container">
<div class="left">left</div>
<div class="right">right</div>
</div>
Basically I have this layout
<div id="container">
<div id="header"></div>
<div id="content"></div>
<div id="footer">
<img src="" alt=""/>
</div>
</div>
And this CSS
#container {
height: 100%;
}
#header {
height: 8%;
}
#footer img {
width: 100%;
height: auto;
}
As you can see, the image in the footer has set width and relative height, which means the height of the footer will be whatever the height of the image will be depending on the screen width.
I need to stretch the content to the remaining height so the combined height of header, content and footer equals the height of the screen (no vertical scrolling).
I can easily do it with flexbox but I'm developing an app using Meteor.js and it will run in an environment, where flexbox might not be supported (older Android versions).
What you're looking for is known as "sticky footer".
WITHOUT FLEXBOX
This version is based on this answer
STANDARD DEMO
html, body {
height: 100%;
margin:0;
}
#container{
display: table;
height: 100%;
width: 100%;
background: yellow;
}
#content{
display: table-row;
/* height is dynamic, and will expand... */
height: 100%;
/* ...as content is added (won't scroll) */
background: turquoise;
}
#header {
height: 8%;
}
h1{
margin:0;
padding:0;
}
#footer img {
width: 100%;
height: auto;
}
#footer{
color:lightgrey;
display: table-row;
}
WITH FLEXBOX
This version is based on this article
FLEXBOX DEMO
html, body, #container {
height: 100%;
}
#container{
display: flex;
min-height: 100vh;
flex-direction: column;
}
#content{
flex: 1;
background:tomato;
}
#header {
height: 8%;
}
h1{
margin:0;
padding:0;
}
#footer img {
width: 100%;
height: auto;
}
#footer{
color:lightgrey;
}
You could use CSS tables to accomplish this. Make #container display:table and the sub-divs display:table-row. Then if header and footer have a height, the content height will adjust accordingly. In this case, the height of #header is explicitly 8% and the height of #footer is determined by the height of the image.
html, body, #container {
height: 100%;
padding: 0;
margin: 0;
}
#header, #content, #footer {
display: table-row;
}
#container {
display: table;
width: 100%;
}
#header {
height: 8%;
background-color: blue;
}
#content {
background-color: yellow;
}
#footer {
background-color: green;
}
#footer img {
width: 100%;
}
Here's an example on jsfiddle. Try adjusting the width and height of the result window.
Here is the situation, I have this html:
<div id='main'>
<div id='menu'>
Menu Items Here
</div>
<div id='cont'>
Content Here
<div id='footer'>Some Footer</div>
</div>
</div>
CSS here:
html, body {
height: 100%;
width : 100%;
margin: 0;
padding: 0;
}
#main{
overflow : auto;
background-color: yellow;
width : 100%;
min-height : 100%;
}
#menu {
background-color: red;
float : left;
width : 300px;
}
#cont {
margin-left : 300px;
float : right;
background-color: orange;
width : 100px;
min-height : 100%;
height: auto !important; /*min-height hack*/
height: 100%; /*min-height hack*/
}
What I want to do basically is #cont div must have a min height of 100% (if I have small content) but will extend if have longer content.
Any help would be appreciated.
Note: The width size is just temporary for now.
Thanks!
This may work:
#main{
height : 100%;
}
#cont {
min-height : 100%;
/* Without the hacks */
}
Try this http://jsfiddle.net/W6tvW/2/
<div id='main'>
<div id='menu'>
Menu Items Here
</div>
<div id='cont'>
Content Here
<div id='footer'>Some Footer</div>
</div>
</div>
html, body {
height: 100%;
width : 100%;
margin: 0;
padding: 0;
}
#main{
overflow : auto;
background-color: yellow;
min-height : 100%;
position: relative;
}
#menu {
background-color: red;
float : left;
width : 300px;
}
#cont {
margin-left : 300px;
background-color: orange;
min-height : 100%;
position: absolute;
right: 0;
}
If you want the footer to stay at the bottom:
#footer {
position: absolute;
bottom: 0;
}
you are using min-height:100% which means 'make the minimum height of this box be the height of it'
you would be better using a pixel value (e.g., make #menu and #cont min-height:400px;)
if you want to make them both the height of the tallest one, then you'll need some jquery:
if (jQuery('#menu').height() < jQuery('#cont').height()) {
// the cont is bigger than the menu
jQuery('#menu').css("height", jQuery('#cont').height());
}
I'm creating a site where the basic design consists of a few blocks on top of each other, something like this:
The first three divs are of set height and width, and the main area is also of a fixed width, with the whole thing centered horizontally on the screen. I want the main area to extend to the bottom of the screen, whatever the screen size and proportions, and to use a scroll bar within it if the contents extends beyond the bottom of the screen.
The problem I have found is that to use a scroll bar it seems you need an absolute height, so I haven't been able to find any method for fitting it and being able to scroll through the contents at the same time.
Any ideas?
Here's one way of doing this. I know there might be too many divs that are just for the look of the page, making it not 100% semantic. Anyway, here you go:
http://jsfiddle.net/vSt3Z/
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">Three</div>
<div class="content">
<div class="inner">
<div class="scroller">
Content
</div>
</div>
</div>
And the CSS:
.one, .two, .three {
height: 40px;
margin: 0;
padding: 0;
}
.content {
background: yellowgreen;
position: absolute;
top: 0;
left: 0;
z-index: -1;
padding-top: 120px;
width: 100%;
height: 100%;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-o-box-sizing: border-box;
}
.content .inner {
height: 100%;
overflow-y: scroll;
}
.content .inner .scroller {
height: 1200px;
}
Please ignore this:
* {
margin: 0;
padding: 0;
}
it's there just to remove an annoying default padding from jsfiddle
Use calc with min-height:
HTML:
<div class="first block"></div>
<div class="second block"></div>
<div class="third block"></div>
<div class="main"></div>
CSS:
html,body{
height:100%;
width:100%;
padding:0;
margin:0;
}
.block{
width:100%;
height:100px;
}
.first{
background:red;
}
.second{
background:blue;
}
.third{
background:yellow;
}
.main{
min-height: calc(100% - 300px);
width:100%;
background:green;
}
JSFiddle
caniuse calc
In my opinion this is the simplest method:
DEMO: http://jsfiddle.net/ZPU5Z/
This does not put a scroll bar on the main #content section only but on the whole document. Unless you have a really compelling reason to do otherwise I suggest keeping things simple (and therefore highly compatible too!).
HTML
<div id="fixed-header">
<div id="header">Header</div>
<div id="bar1">Bar 1</div>
<div id="bar2">Bar 2</div>
</div>
<div id="content">
Main area
</div>
CSS
* {
margin: 0;
padding: 0;
border: 0;
color: white;
}
body {
background-color: blue;
}
#fixed-header {
position: fixed;
top: 0;
width: 100%;
}
#header {
background-color: black;
text-transform: uppercase;
height: 50px;
}
#bar1 {
height: 25px;
background-color: red;
}
#bar2 {
height: 25px;
background-color: green;
}
#content {
padding-top: 100px; /* header + bar1 + bar2 */
}