How to remove resizing content when overflow when is hover? - html

I have problem with overflow in on my website. When mouse is not over the left menu, it look OK, but when I move mouse over the menu and :hover is active, content (menu is a content) is a little smaller. I don't want this effect when :hover is active, menu is a little smaller.
Effect that I want is like on Youtube. If you are logged into your account, and if you pressed menu icon next to Youtube logo, you will get scroll menu. When mouse is not over the menu, nothing happens. But when you move your mouse over the menu, overflow is visible and this not change content size.
In brief:
I have this:
when overflow is active, content is smaller
What I want is this:
when overflow is active, content is NOT smaller
How can I do it ?
Thanks :)

My understanding, though it maybe flawed is that you have to already have the space that the scroll bar will populate there. You didn't give us any code so I had to fabricate it, but this is what I came up with
https://jsfiddle.net/link2twenty/bxz60j4r/
HTML:
<div class="sidebar">
<div class="container">
<div class="profile">
<img src="http://moss-side.yoursquaremile.co.uk/img/default-profile-pic.png" />
</div>
<div class="card">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-person-128.png" />
<span>Test card data</span>
</div>
<div class="spacer">
<hr>
</div>
<div class="card">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-person-128.png" />
<span>Test card data</span>
</div>
<hr>
<div class="card">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-person-128.png" />
<span>Test card data</span>
</div>
<hr>
<div class="card">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-person-128.png" />
<span>Test card data</span>
</div>
<hr>
<div class="card">
<img src="https://cdn4.iconfinder.com/data/icons/ionicons/512/icon-person-128.png" />
<span>Test card data</span>
</div>
</div>
</div>
CSS:
.sidebar {
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 400px;
overflow: hidden;
padding-right: 17px;
}
.sidebar:hover {
padding-right: 20px;
overflow-y: auto;
}
.sidebar .container {
width: 400px;
background: #8cc34b;
margin-bottom: -25px;
}
.card {
opacity: .7;
width: 100%;
height: 120px;
background: #8cc34b;
}
.card span {
position: relative;
float: right;
padding-right: 50px;
top: 50%;
}
hr {
margin-left: 120px;
margin-right: 20px;
border-color: darkgreen;
opacity: .7;
}

You can try the following:
.scrollable {
border: 1px solid black;
width: 100px; /* specify the width you like here */
overfow: hidden;
}
.scrollable:hover {
overfow-y: scroll;
}
nav {
border: 1px solid grey;
width: 80px; /* specify the width which is calculated as widthOfScrollable - widthOfScrollbar */
}
.item1, .item2 {
height: 10px;
width: 100%;
}
.item1 { background: red }
.item2 { background: blue }
<div class="scrollable">
<nav>
<li class="item1"></li>
<li class="item2"></li>
</nav>
</div>
Borders and colors are used to show the blocks.
Here you preserve some space for the scrollbar on the right side. Problem here is to preserve exactly the scrollbar size for the current user / browser / OS. They all could have differences in scrollbar width value, so there are two ways for you to go:
Use this function from here Getting scroll bar width using JavaScript to calculate the proper size of the scrollbar
Make the scrollbar margin big enough to cover any case on any operating system

Related

Combine overflow-y: scroll with overflow-x: visible

I have a div, that has flyout divs positioned absolute to the right. Its all working correctly but I need to add a max height to my main div. Since it will overflow, I add overflow-y scroll, but it messes everything up. It prevents my flyout divs from going outside of the main div, and places them inside with a horizontal scrollbar.
I've mocked up an example:
.menu {
height: 200px;
max-height: 200px;
width: 200px;
background-color: red;
margin-bottom: 50px;
}
.menu.overflow {
overflow-y: scroll;
background-color: purple;
height: 150px;
max-height: 150px;
}
.menu-item {
height: 30px;
width: 100%;
background-color: blue;
position: relative;
margin-bottom: 10px;
cursor: pointer;
}
.menu-item-flyout {
display: none;
width: 200px;
height: 100px;
position: absolute;
left: 100%;
background-color: green;
top: 0;
}
.menu-item:hover .menu-item-flyout {
display: block;
}
<!-- no overflow y scroll -->
working correctly:
<div class="menu">
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
</div>
<!-- overflow y scroll -->
This is not working. I want to add overflow y
scroll to menu but it prevents the flyout
<div class="menu overflow">
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
<div class="menu-item">
<div class="menu-item-flyout"></div>
</div>
</div>
Unfortunately you can't mix overflow values. Per MDN on overflow-x:
If overflow-y is hidden, scroll or auto and this property is visible
(default) it will implicitly compute to auto.
auto, in this case, forces a scroll bar. There is no way to get around this: you cannot have a box overflow in only one direction.
As a general principal, menus based on hover are difficult to navigate as they are, but are treacherous from an accessibility standpoint. Adding scroll bars to the mix is a recipe for disaster. I'd recommend approaching the problem from another angle.

Align a button at the bottom of a grid

I am trying to assign the button : called 'go to form' right at the bottom of the grid i have done in CSS.
I have messed around with the relative position but this seems not to want to work. Any ideas guys ?
.item {
border: 1px rgb(160,160,255) solid;
}
img {
border-radius: 2px;
border: 1px solid #ddd;
height : 100px;
width : 80%;
}
p {
font-size: 18px;
}
h1 {
font-size: 14px;
}
</style>
<div class="grid-container">
<div class="item">
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​
<p> Sheep Dipper </p>
</div>
<div class="item">​<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​​
<p> Laptop Request​ </p>
<h4> Use this form to request a new laptop</h4>
<button>Go to Form</button> </div>
<div class="item">​
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​
<p> New User Request </p>
</div>
<div class="item">
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​ ​​
<p> Permissions Management </p>
</div>
<div class="item">​​​
<img src="/sites/TeamSite/SiteAssets/placeholder.jpg" alt="Paris"/>​ ​<br/>​<br/>​<br/>​​<br/>​<br/></div>
</div>
try this one :
.grid-container{
position: relative;
}
.youBtnClass {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
Try this. Position absolute will place the button with respect to its immediate parent, and bottom attribute makes sure it starts at the very bottom of the parent.
You may add top margin in case your button lacks a gap on top of it.
.grid-container{
position: relative;
}
.youBtnClass {
position: absolute;
bottom: 0;
margin: 0 auto;
}

CSS: Sidebar won't appear inside parent element

I'm trying to add two sidebars to both edges of the middle element. The left one works without an issue, however, the right one won't. Instead, it appears below its parent element (as seen in the picture) unless I position it as absolute, then however, it goes over the navbar.
Relevant css:
/* The parent element */
main {
margin: 0;
position: relative;
left: 22%;
right: 22%;
width: 56%;
height: 50vh;
background-color: #c5c5c5;
}
/* The correctly shown sidebar */
.sidenav {
margin: 0;
height: 100%;
width: 160px;
top: 7%;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 7%;
}
/* The wrongly shown sidebar */
.bar-right{
float: right;
margin: 0;
width: 200px;
height: 100%;
background-color: #111;
overflow-x: hidden;
padding-top: 7%;
}
HTML:
<main>
<div class="topbar">
[top bar stuff]
</div>
<div class="sidenav">
[usernamestuff]
Link1
Link2
Link3
</div>
<div class="bar-right">
<p>text for test</p>
</div>
</main>
Both sidebars are effectively identical so I don't understand why they behave so differently. How do I get them both to their appropriate edges of the main element?
I would recommend you to use Bootstrap. This will help you to achieve what you looking for so easy, by this code:
<div class="container">
<div class="row">
<div class="col-sm-3">
// First sidebar
</div>
<div class="col-offset-6 col-sm-3">
// Second sidebar
</div>
</div>
</div>

How to implement an white box over an image correct in asp.net

I'm trying to make an booking box with an white background over an image on my front page. So far I have managed to put an box on top with the following code:
Code:
<div class="row">
<div class="col-sm-12 contentpage">
<div class="frontimage">
<img src="~/images/index.jpg" />
<div class="col-sm-4">
<div class="bookingbox">
</div>
</div>
</div>
</div>
</div>
Css:
.bookingbox {
background-color: white;
position: absolute;
height: 100px;
margin-top: -580px;
margin-left: 10px;
}
#media (min-width: 1200px) {
.bookingbox {
display: none;
}
}
The problem now is that when you going from, lets say 1600px to 1200px the white box moves, can't make it to be static inside the image.
All my images are set with the following css the they become responsive:
img {
max-width: 100%;
}
What should I change? any ideer?
Update:
The box fitting perfectly now.. but now the image is off the aligniment with the rest of the page.
Left side is good, but right side has become bigger somehow?
The answer here, you should use z-index to do this.
.bookingbox {
background-color: red;
position: absolute;
height: 100px;
width: 100px;
z-index: 2;
position: absolute;
top: 0;
}
.frontimage {
z-index: 1;
position: absolute;
}
#media (min-width: 1200px) {
.bookingbox {
display: none;
}
}
<div class="row">
<div class="col-sm-12 contentpage">
<div class="frontimage">
<img src="https://www.wonderplugin.com/wp-content/plugins/wonderplugin-lightbox/images/demo-image0.jpg" />
<div class="col-sm-4">
<div class="bookingbox">
</div>
</div>
</div>
</div>
</div>

position of layers when resizing browser

when I'm resizing my browser-window the blue buttons go below the logo on the left, on the same line as the text "Welkom Bart" although they are two different layers. I want the text "Welkom Bart" to lower as well, so they are not on the same line. What do I need to add to my css?
html e.g.
<div id="mainmenu">
<div id="logo"><img ... /></div>
<div id="usermenu">Buttons</div>
</div>
<div id="maintitle">
<h2>Welkom Bart</h2>
<hr />
</div>
css
#mainmenu {
height: 100px;
position: relative;
}
#logo {
float: left;
width: 200px;
margin-right: 20px;
}
#usermenu {
float: right;
}
#maintitle {
margin-bottom: 20px;
}
#maintitle hr {
color: #56c2e1;
display: block;
height: 1px;
border: 0;
border-top: 1px solid #56c2e1;
margin: 10px 0;
}
Add clear:both to #maintitle =)
Add overflow:hidden to #mainmenu. This will cause its height to include all floated elements, such as your #usermenu element, allowing flow to continue underneath it.
Use this
<div id="maintitle" style="width:100%">
<h2>Welkom Bart</h2>
<hr />