I have an unordered list which is inside a div tag and initially the list is empty. When items are added on to it, it will expand and I want it to be scroll-able once it the length of the list exceeds that of the web page, i.e I do not want the web page to scroll, I want only the unordered list to scroll. However currently, the scroll bar for my unordered list is not appearing.
My html code is:
<div style="width: 25%; float: right; " class="online_users">
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-comment"></span> Online Users
<ul id="ListOfOnlineUsers" style="overflow: auto;height:100%; word-wrap: break-word;" class="list-group">
</ul>
</div>
</div>
</div>
My CSS code is
html{
height: 100%
}
{
margin: 0;
padding: 0;
}
body {
padding: 50px;
font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
height: 100%;
}
a {
color: #00B7FF;
}
.chat
{
list-style: none;
margin: 0;
padding: 0;
}
.chat li
{
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 1px dotted #B3A9A9;
}
.chat li.left .chat-body
{
/*margin-left: 60px;*/
}
.chat li.right .chat-body
{
/*()margin-right: 60px;*/
}
.chat li .chat-body p
{
margin: 0;
color: #777777;
word-wrap: break-word;
}
.panel .slidedown .glyphicon, .chat .glyphicon
{
/*margin-right: 5px;*/
}
.panel-body
{
overflow-y: scroll;
top: 1em;
left: 1em;
height: 250px;
}
::-webkit-scrollbar-track
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
background-color: #F5F5F5;
}
::-webkit-scrollbar
{
width: 12px;
background-color: #F5F5F5;
}
::-webkit-scrollbar-thumb
{
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
background-color: #555;
}
/* CSS used here will be applied after bootstrap.css */
body, html {
height: 100%;
background-repeat: no-repeat;
background-image: linear-gradient(rgb(154, 145, 162), rgb(12, 97, 33));
}
.card-container.card {
width: 350px;
padding: 40px 40px;
}
.card {
background-color: #F7F7F7;
/* just in case there no content*/
padding: 20px 25px 30px;
margin: 0 auto 25px;
margin-top: 50px;
/* shadows and rounded borders */
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
-moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
}
.btn {
font-weight: 700;
height: 36px;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
cursor: default;
}
.form-signin input[type=text],
.form-signin button {
width: 100%;
display: block;
margin-bottom: 10px;
z-index: 1;
position: relative;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.btn.btn-signin:hover,
.btn.btn-signin:active,
.btn.btn-signin:focus {
background-color: rgb(12, 97, 33);
}
Set the list's max-height to the height of its parent (or whatever you need it to be) and then set its overflow property to auto.
Here's a quick example:
div{
border:1px solid #000;
font-family:arial;
height:100px;
width:200px;
}
ul{
list-style:none;
max-height:100px;
margin:0;
overflow:auto;
padding:0;
text-indent:10px;
}
li{
line-height:25px;
}
li:nth-child(even){
background:#ccc;
}
<div>
<ul>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
<li>text</li>
</ul>
</div>
Try to add a wrapper and set max-height to the wrapper
Html
<div class="listWrapper">
<ul>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
<li>content</li>
</ul>
</div>
Css
ul, li {
list-style:none;
padding:0;
margin:0;
}
.listWrapper {
max-height:100px;
overflow-y:auto;
}
Fiddle Demo
You can change the height of the ul to max-height: 100vh, that way the ul will always have the size of the viewport.
For browser support check this : http://caniuse.com/#search=vh
In case you want it inside a div that doesn't have the viewport height, follow #Shaggy answer.
With height set to 100% your container will not display scrollbars.
https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
.panel {
width: 200px;
}
.list-group {
overflow: auto;
height: 200px;
}
<div class="online_users">
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-comment"></span> Online Users
<ul id="ListOfOnlineUsers" class="list-group">
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
<li>some item</li>
</ul>
</div>
</div>
</div>
You have the right CSS properties defined for class .panel-body but you do not use it in your HTML yet. Move the <ul> into a separate div with the class .panel-body. That should do the trick:
<div style="width: 25%; float: right; " class="online_users">
<div class="panel panel-primary">
<div class="panel-heading">
<span class="glyphicon glyphicon-comment"></span> Online Users
</div>
<div class="panel-body">
<ul id="ListOfOnlineUsers" style="height:100%; word-wrap: break-word;" class="list-group">
</ul>
</div>
</div>
</div>
Edit: You should drop the overflow: auto from the <ul> or you get double scroll bars
Edit2: Yet another optimization: set margin: 0 for the <ul> and change the the .panel-body to overflow: auto, so the div's scroll bar is only visible if needed. See my fiddle
No need for the outer div (NOTE this is for horizontal scrollbars. Just change max-width to max-height and overflow-x to overflow-y
ul, li {
list-style:none;
padding:0;
margin:0;
white-space:nowrap;
max-width:300px;
}
ul{overflow-x:scroll;}
CodePen Live Example
Just set the height of your <ul and give it an overflow: scroll;.
That should do it.
Try this >>>
<div class = "list"></div>
and the css property >>>
/* Hide scrollbar for Chrome, Safari and Opera */
.list::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
.list {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
Related
I feel like I should be able to figure this out but I really can't...
I basically have a div that is contains another set of divs/elements. I want the first div within this container to have a background color to effectively give the parent div a colored top bar/portion. The closest I can get is using display: flex; to give it full height coloring, but I can't get it the way I want. Any help is appreciated.
.container {
border: 1px solid grey;
border-radius: 4px;
padding: 0px 10px 10px 10px;
}
.content {
height: 400px;
}
.sp-h3 {
display: flex;
background-color: #008ed0;
color: white;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</P>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>
You could set padding to the child elements, instead of setting it to the whole .container.
.container {
border: 1px solid grey;
border-radius: 4px;
}
.content {
height: 400px;
padding: 0px 10px 10px 10px;
}
.sp-h3 {
display: flex;
background-color: #008ed0;
color: white;
padding: 0px 10px 10px 10px;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</P>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>
You can consider a simple gradient coloration on the container so you won't have the issue related to padding:
.container {
border: 1px solid grey;
border-radius: 4px;
padding: 0px 10px 10px 10px;
background:
linear-gradient(to bottom,#008ed0 60px,transparent 0);
}
.content {
height: 400px;
}
.sp-h3 {
display: flex;
color: white;
}
* {
box-sizing: border-box;
}
.container::before,
.container::after {
content: "";
clear: both;
}
<div class="container">
<div class="sp-h3">
<h3>Bob McBob</h3>
</div>
<div class="content">
<p>Just for something</p>
<ul>
<li>The number 1</li>
<li>The number 2</li>
<li>The number 3</li>
<li>The number 4</li>
</ul>
</div>
</div>
I am trying to make a 'fancy' navigation, with multiple ul/li. I think my problem is in the CSS with the child selector (>). If you run the code snippet provide you'll notice when you hover over li.first (item one) you can visibly see the div.hover-container although li:first>ul>li has the css with overflow: hidden; along with this div.hover-container is within li.one (example one) so why does it display when I hover over li.>one (other examples).
I am just confused and would love some input on this after staring and testing possible solutions for an hour.
EDIT: I apologize for how messy it looks in the snippet.
/* ================== Example ================ */
.example>ul {
display: flex;
position: relative;
height: 50px;
width: 800px;
margin: 50px auto;
list-style-type: none;
background-color: #5A827E;
}
.example>ul>li {
display: block;
height: 100%;
width: 33.3%;
border-right: 2px solid rgba(0, 0, 0, 0.5);
position: relative;
overflow: hidden;
color: white;
font-weight: bold;
text-align: center;
line-height: 50px;
font-style: italic;
}
.example>ul>li:hover {
overflow: visible;
background-color: #415E5B;
}
.first>ul {
display: block;
position: absolute;
top: 50px;
height: 400px;
width: 100.5%;
list-style-type: none;
background-color: #415E5B;
}
.first>ul>li {
display: block;
color: white;
line-height: 40px;
text-align: center;
height: 10%;
width: 100%;
border-top: 1px dotted rgba(255, 255, 255, 0.5);
font-weight: 400;
font-style: normal;
overflow: hidden;
}
.first>ul>li:hover {
background-color: white;
color: blue;
}
.hover-container {
display: flex;
justify-content: flex-start;
flex-flow: column wrap;
position: absolute;
left: 265px;
top: 0;
height: 400px;
width: 535px;
border: 3px solid gold;
}
.list-container {
display: block;
height: auto;
width: 30%;
border: 3px solid #F2D7E2;
}
.list-container h2 {
text-align: left;
color: darkgray;
font-weight: bold;
}
.list-container ul {
list-style-type: none;
text-align: left;
}
/* ------------------ Example END ---------------- */
<div class="example">
<ul>
<!-- first navigation container -->
<li class="first"> Item One
<ul>
<!-- dropdown -->
<li class="one"> Example 1
<!-- dropdown item -->
<div class="hover-container">
<!-- sidebar -->
<div class="list-container">
<!-- sidebar content box-->
<h2>Content Header One</h2>
<ul>
<li>Content One</li>
<li>Content Two</li>
<li>Content Three</li>
</ul>
</div>
<!-- sidebar content box END -->
<div class="list-container">
<!-- sidebar content box-->
<h2>Content Header One</h2>
<ul>
<li>Content One</li>
<li>Content Two</li>
<li>Content Three</li>
</ul>
</div>
<!-- sidebar content box END -->
</div>
<!-- sidebar END-->
</li>
<!-- dropdown item END -->
<li>Example 2</li>
<li>Example 3</li>
<li>Example 4</li>
<li>Example 5</li>
<li>Example 6</li>
<li>Example 7</li>
<li>Example 8</li>
<li>Example 9</li>
<li>Example 10</li>
</ul>
<!-- END of dropdown -->
</li>
<!-- main list item END -->
<li class="second">Item Two</li>
<li class="third">Item Three</li>
</ul>
</div>
If you want the hover-container div to be shown only when the first li(Example 1) is hovered, you need to replace the .hover-container you have added with the below CSS:
.first>ul>li:first-child:hover .hover-container{
display: flex;
justify-content: flex-start;
flex-flow: column wrap;
position: absolute;
left: 265px;
top: 0;
height: 400px;
width: 535px;
border: 3px solid gold;
}
Your child selectors seem okay. I think the problem is with your positioning. The .hover-container element has "position: absolute", meaning it's placed relative to its first positioned ancestor (see https://www.w3schools.com/css/css_positioning.asp). You want to determine if it's overflowing the .first>ul>li element above it, so that element needs a "position: relative."
Adding these rules should give the behavior you're looking for:
.first>ul>li {
position: relative;
...
}
.first>ul>li:hover {
overflow: visible;
...
}
The following CSS property rule defined on .hover-container set its position to absolute with respect to .example>ul>li which is the nearest ancestor that is a containing block (read about how the browser determines a containing block.)
.hover-container {
/*...*/
position: absolute;
/*...*/
}
The fix for this is to form a containing block with the li that is closest ancestor to .hover-container by setting its position to relative.
.first>ul>li {
/*...*/
position: relative;
/*...*/
}
Another fix for this is to set the overflow property to hidden for the closest containing block that is an ancestor to .hover-container.
.first>ul {
/*...*/
overflow: hidden;
/*...*/
}
I'm building a simple pricing table and would like to place a "most popular" circle in it like in this mockup image I have created.
This is how I've created the pricing table.
.columns {
float: left;
width: 30%;
padding: 8px;
}
.table {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
}
.table .header {
background-color: #333;
color: #fff;
}
.table li {
padding: 20px;
text-align: center;
}
.table .top {
background-color: #eee;
}
<div class="columns">
<ul class="table">
<li class="header">First Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns">
<ul class="table">
<li class="header">Second Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns">
<ul class="table">
<li class="header">Third Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
I then found a way to create a circle with "most popular" in it (not sure if this is the best way to do it though), like this. I reversed the colors so it can be seen on a white background.
.dot {
height: 55px;
width: 70px;
background-color: #fff;
border-radius: 50%;
border: 3px solid #eee;
display: inline-block;
padding-top: 15px;
}
<div style="text-align:center">
<span class="dot">Most<br>Popular</span>
</div>
I'm just not sure how to bring these concepts together to create something like in the mockup shot where the circle sits on an angle off to the side of the price like that and have it cut off on the edges.
You can take your .dot class and make it a pseudo element instead, meaning you wouldn't have to add it to your HTML.
With the code below, if you add the class most-popular to a top element, it will show the "Most Popular" badge. You may need to take a few minutes and style it to get it to match your image perfectly, but the difficult part should be out of the way.
Changes:
To position the "most popular" to the left, I've set it to position: absolute;, and its parent to display: relative;. Using the top and left properties, I've positioned it to the left of its parent and vertically-centered.
I've put overflow: hidden; on the parent so that anything outside of its boundaries will be hidden.
Applied transform: rotate(-15deg) to the badge to give it a slight rotation.
.columns {
float: left;
width: 30%;
padding: 8px;
}
.table {
list-style-type: none;
border: 1px solid #eee;
margin: 0;
padding: 0;
}
.table .header {
background-color: #333;
color: #fff;
}
.table li {
padding: 20px;
text-align: center;
}
.table .top {
background-color: #eee;
position: relative;
overflow: hidden;
}
.most-popular::after {
content: 'Most Popular';
display: block;
height: 55px;
width: 70px;
border-radius: 50%;
border: 3px solid #fff;
padding-top: 15px;
position: absolute;
transform: rotate(-20deg);
left: -5px;
top: -5px;
}
<div class="columns">
<ul class="table">
<li class="header">First Product</li>
<li class="top">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy</li>
</ul>
</div>
<div class="columns ">
<ul class="table ">
<li class="header ">Second Product</li>
<li class="top ">$100.00</li>
<li>First feature</li>
<li>Second feature</li>
<li>Buy
</li>
</ul>
</div>
<div class="columns ">
<ul class="table ">
<li class="header ">Third Product</li>
<li class="top most-popular">$100.00
</li>
<li>First feature</li>
<li>Second feature</li>
<li>
Buy
</li>
</ul>
</div>
I am building a menu and i'm trying to center the menu based on if the menu link is wider than the menu or menu is wider than the menu link.
At the moment if I add more text to the menu link it wraps onto a new line. So I need to make my menu scalable that If I add more less content to the menu link or the menu itself it will scale accordingly.
HTML
<div class="menu-wrap">
<div class="menu">
this is a long menu link that wraps<i class="fa fa-chevron-down pl-1" aria-hidden="true"></i>
</div>
<div class="sau-menu">
<ul>
<li>This is a menu </li>
<li>This is a menu item</li>
<li>This is a menu item</li>
<li>This is a menu item</li>
<li>This is a menu item</li>
</ul>
</div>
</div>
CSS
.menu-wrap{
position: absolute;
}
.menu{
position: absolute;
z-index:3;
display: inline-block;
margin: 0 auto;
text-align: center;
width:100%;
}
.sau-menu {
z-index:33;
position: relative;
top:40px;
background: #fff;
border: 1px solid #8e8e8e;
color:#8e8e8e;
display:inline-block;
padding:20px;
margin: 0 auto 0 auto;
width:100%;
}
.sau-menu ul{
list-style: none;
padding:0;
margin:0;
font-size:0.9rem;
}
.sau-menu:after, .sau-menu:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.sau-menu:after {
border-bottom-color: #fff;
border-width: 13px;
margin-left: -13px;
}
.sau-menu:before {
border-bottom-color: #8e8e8e;
border-width: 14px;
margin-left: -14px;
}
https://jsfiddle.net/stevenSAUaa/5sfqp41d/
The .sau-menu padding: 20px makes the the box wider than .menu-wrap.
Therefore add box-sizing: border-box to .sau-menu.
JSFiddle
I have been using my free time to improve my HTML knowledge during my holiday.
During the time I was designing a CSS Menu. I face some problem and don't know how to solve them.
I tried to search from Google. Because of my poor English, I was unable to find a solution, so I seek help here.
Problem:
I tried to design a CSS Menu with Expandable sub-menu.
Why doesn't the sub-menu's parent list change?
As you can see from the screenshot. The Product menu is different with others.
Is there any solution?
ScreenShot
Due to my reputation I can't provide a screenshot, so I'll provide a link:
http://i151.photobucket.com/albums/s155/HongJaiz/CSSMenu.jpg
CSS3 Coding
body{
position: relative;
height: 100%;
background: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#fff));
}
.navbox {
position: relative;
float: left;
}
ul#expList {
list-style: none;
display: block;
width: 200px;
position: relative;
padding: 60px 0 60px 0;
background: url(shad2.png) no-repeat;
-webkit-background-size: 50% 100%;
}
li#expList {
list-style: none;
display: block;
width: 200px;
position: relative;
padding: 60px 0 60px 0;
background: url(shad2.png) no-repeat;
-webkit-background-size: 50% 100%;
}
ul li {
list-style: none;
}
li {
margin: 5px 0 0 0;
}
ul#expList li a {
-webkit-transition: all 0.3s ease-out;
background: #cbcbcb url(border.png) no-repeat;
color: #174867;
padding: 7px 15px 7px 15px;
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
width: 100px;
display: block;
text-decoration: none;
-webkit-box-shadow: 2px 2px 4px #888;
}
ul#expList li a:hover {
background: #ebebeb url(border.png) no-repeat;
color: #67a5cd;
padding: 7px 15px 7px 30px;
}
HTML Coding
<ul id="expList">
<li class="home">Home</li>
<li class="freebies">Product
<ul>
<li>List 1</li>
<li>List 2</li>
<li>List 3</li>
</ul>
</li>
<li class="about">Register</li>
<li class="about">About Us</li>
</ul>
just coz you have given style to <a></a> of <li></li> and in case of parent of submenu i.e Product you haven't wrapped it in <a></a> tag, doing so will solve your problem
<ul id="expList">
<li class="home">Home</li>
<li class="freebies"><a>Product</a>
<ul>
<li>List 1</li>
<li>List 2</li>
<li>List 3</li>
</ul>
</li>
<li class="about">Register</li>
<li class="about">About Us</li>
</ul>