I have a div. And this div contains a very long list. This list becomes scrollable automatically.
This div is then inside another div, which fills out the entire screen.
Scrolling works fine, but it only works when the mouse is over the inner div, the one that actually contains all the data.
But I want scrolling to work, also when the mouse is over the parent div, the one that fills out the entire screen.
How do I do that?
You can see the sample here:
https://openage.org/fs/jsl_forritun/?page=hlutir
It doesn't scroll when the mouse is over the darker part. /:
you have two divs that contains your content body
id= "nhreyfing"
give him this style padding: 0 20vw; background: black
or what so ever padding you wanna give him
id= "content"
give him your rgb(213, 191, 134) background
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #2B2832;
}
.main {
margin: 0 auto;
padding: 40px;
width: 700px;
height: 100vh;
overflow-y: auto;
background: #D5BF86;
}
.main ul {
margin: 0;
padding: 0;
}
.main ul li {
list-style: none;
}
.main ul li:nth-child(n+2) {
margin: 10px 0 0;
}
.main ul li a {
padding: 10px;
display: flex;
color: #000;
background: #C6B076;
text-decoration: none;
}
<div class="main">
<ul>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
<li>
Link
</li>
</ul>
</div>
Do the following:
remove CSS properties from
BODY element {height:100%}
remove {max-width: 800px} and add CSS to id="initial_screen_base" element:
div#initial_screen_base {
max-width: 100vw;
padding: 0px 20vw;
background-color: rgb(43, 40, 50);
}
if you want it to me maxed always to 800px (for smaller devices it will be full width), make it like this:
div#initial_screen_base {
background-color: rgb(43, 40, 50);
max-width: 100vw;
padding: 0;
padding-right: calc((100% - 800px)/2);
padding-left: calc((100% - 800px)/2);
}
for your id="node":
div#node {
background-color: rgb(213, 191, 134);
}
You should remove you inline CSS and put them in a style TAG inside your HEAD. That way you will fave more clear code for yourself to edit.
Related
I am trying to create a horizontal navbar and I am trying to put the items in one line and horizontal.
I have to create an unordered list and create some items in it and have a link for each text:
body {
padding: 0px;
margin: 0;
}
ul {
background-color: rgb(94, 94, 94);
}
li {
float: left;
}
a {
display: block;
}
<ul>
<li><a> Home </a></li>
<li><a> About </a></li>
</ul>
then I should set the float for <li> to left and give a block display to <a> tags.
But when I do this some CSS in <ul> does not work such as background-color, can u help me with it?
You can use flexbox for this:
ul {
list-style-type: none;
display: flex;
}
li {
padding: 5px;
}
<ul>
<li><a> Home </a></li>
<li><a> About </a></li>
</ul>
without using flex or grid.
when you set the <li> to inline-block you do 3 things:
remove the dot before the list
put everything in a 1 line (inline)
if there isn't enough space, it will be block to like columns
now there isn't anymore the bug of background not displayed
don't make <a> to block if is nested in another element that isn't... a child can style the parent
but if you style the parent then all child will be
body {
margin: 0;
}
/* parent */
ul {
background-color: rgb(94, 94, 94);
}
/* childs */
li {
display: inline-block;
}
<ul>
<!-- home -->
<li>
Home
</li>
<!-- about -->
<li>
About
</li>
</ul>
I have been tasked with styling a website, where I have encountered a hurdle regarding the horizontal alignment of elements inside list items.
I have replicated the structure of the menu in question with this JSFiddle.
I want to know how I can keep the position of the green divs (as shown from the start) when I expand the menu, using the button in the fiddle. I need them to keep horizontal alignment with the first <a> element in their respective <li> element, when the submenus are displayed.
you can do it like this for example:
<html>
<script>
function clickFunction(){
var elements = document.getElementsByClassName("submenu");
for(var i = 0; i < elements.length; i++){
elements[i].classList.toggle("display-sublist");
}
}
</script>
<style>
ul{
list-style-type: none;
margin: 0px;
padding: 0px;
}
ul li{
width: 100%;
background-color: blue;
}
.submenu{
display: none;
}
.display-sublist{
display: block;
}
ul li a{
width: 95%;
background-color: red;
}
.main-test {
display: inline-block;
float: left;
width: 90%;
}
.cancel-test{
display: inline-block;
background-color: green;
float: right;
width: 10%;
}
.expand-button{
clear: both;
display: block;
}
</style>
<body>
<ul>
<li>
<a class="main-test" href="#">Something</a>
<a class="cancel-test">x</div>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
<a class="main-test"href="#">Something</a>
<a class="cancel-test">x</a>
<ul class="submenu">
<li>
Sub-Something
</li>
<li>
Sub-Something
</li>
</ul>
</li>
<li>
Something
</li>
<li>
Something
</li>
</ul>
<button onclick="clickFunction()" class="expand-button">Expand</button>
</body>
</html>
I have a standard navigation menu with sub menus on some items. I want the sub menus to have a min-width and a max-width. For example, the sub items are at least 150px wide and can grow up to 250px wide before breaking on multiple lines. However, since the sub menus are absolutely positioned inside of a relatively positioned element, the sub items will not expand to the full max-width before breaking on multiple lines:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul,
li {
list-style: none;
}
nav > ul {
font-size: 0;
}
nav > ul > li {
position: relative;
display: inline-block;
font-size: 1rem;
}
nav > ul > li > a {
display: block;
padding: 1em;
background-color: black;
color: white;
}
.sub-menu {
position: absolute;
left: 0;
top: 100%;
}
.sub-menu a {
display: block;
padding: 1em;
color: white;
background-color: red;
min-width: 150px;
max-width: 250px;
}
<nav>
<ul>
<li>
<a>Line Item 1</a>
<ul class="sub-menu">
<li>
<a>Sub Item 1</a>
</li>
<li>
<a>Sub Item 2</a>
</li>
<li>
<a>Sub Item 3</a>
</li>
<li>
<a>Sub Item 4</a>
</li>
</ul>
</li>
<li>
<a>Line Item 2</a>
</li>
<li>
<a>Line Item 3</a>
<ul class="sub-menu">
<li>
<a>Sub Item 1</a>
</li>
<li>
<a>Sub Item 2</a>
</li>
<li>
<a>Long Sub Item 3 forcing sub menu to expand</a>
</li>
<li>
<a>Sub Item 4</a>
</li>
</ul>
</li>
<li>
<a>Line Item 4</a>
</li>
</ul>
</nav>
Setting a large explicit width, like 1000px, on the a elements forced them to expand, but I want to keep the first sub-menu from expanding past the min-width of 150px.
How can I keep the first sub menu at 150px and get the second to expand to 250px?
Try adding width: max-content to .sub-menu. This should allow it to expand.
so to dynamically alter the width of the list items depending on the text content length and keep the requirements of min-width:150px; and max-width:250px; The following works:
1) remove min-width: 150px; & max-width: 250px; from .sub-menu a
2) add this:
.sub-menu {
width:max-content;
width:-webkit-max-content;
width:-moz-max-content;
max-width:250px;
min-width:150px;
}
However, max-content is not supported on IE, EDGE or Opera Mini. So it depends on how important that aspect is to you. Keep in mind its likely it will be supported in the future in those browsers.
As you mentioned the child elements do not want to be larger than the parent due to the existing css, so if you keep the absolute positioning, you will need to alter the parents size dynamically as well.
1) remove min-width: 150px; & max-width: 250px; from .sub-menu a [same as before]
2) add
ul li {
width:100%;
max-width:250px;
min-width:150px;
}
Working example [has both solutions in it, but you will need to comment out/uncomment bits where indicated] = https://codepen.io/FEARtheMoose/pen/GXJzaV
Hope this helps.
I've been having this issue in different places where I have a ul list and Im trying to add it on top of a div (image, or a background) but the list does not appear on top. I wonder if it gets sent in the back..i even added z-index
JSFiddle
CSS
.toolbar p{ text-align: right; padding: 10px 180px 0 0; color: #fff; font-size: 26px; z-index: 1; }
.toolbar { width: auto; height: 50px; background-color: #cc1e2c; z-index: 1;}
.social-icons { z-index: 2;}
HTML
<div class="col_full toolbar">
<p>CALL NOW: +1 555.555.1234</p>
<ul class="social-icons">
<li> </li>
<li> </li>
<li> </li>
</ul>
</div>
The reason you aren't seeing anything is because you posted links, without any content. If you added words, the list would appear:
<div class="col_full toolbar">
<p>CALL NOW: +1 555.555.1234</p>
<ul class="social-icons">
<li> Twitter </li>
<li> Instagram</li>
<li> Facebook</li>
</ul>
</div>
On this example I made the height bigger so you could see that the links are in fact on top.
If you want to see the images, you need to use the image tag like so:
<li> <img src="path/to/your/twitter_image.jpg"/> </li>
JSFiddle
I have a weird problem where my links work fine on one page or fail to do so on another. Here is my code for the non-working page:
<div id="wrapper">
<a href="frontPage.html"><header>
<img src="img/MOBILAX-LOGO.png" height="100" alt="logo">
<h1>MOBI & LAX</h1>
<p>CELLULAR REPAIR CENTER</p>
</header></a>
<nav>
<ul>
<li>
ABOUT US
</li>
<li>
SERVICES
</li>
<li>
IPHONE REPAIR
</li>
<li>
BLOG
</li>
<li>
CONTACTS
</li>
</ul>
</nav>
And the code for the working page:
<div id="wrapper">
<a href="frontPage.html"><header>
<img src="img/MOBILAX-LOGO.png" height="100" alt="logo">
<h1>MOBI & LAX</h1>
<p>CELLULAR REPAIR CENTER</p>
</header></a>
<nav>
<ul>
<li>
<a class="activeLink" href="side2.html">ABOUT US</a>
</li>
<li>
SERVICES
</li>
<li>
IPHONE REPAIR
</li>
<li>
BLOG
</li>
<li>
CONTACTS
</li>
</ul>
</nav>
I am able to see the links fine, but they are not clickable.
Here is the CSS for the nav, ul and wrapper:
nav {
background-color: #2a2a2a;
width: 50%;
height: 200px;
float: left;
}
nav ul {
list-style: none;
height: 200px;
}
nav ul li {
float: left;
margin-top: 86px;
margin-left: 25px;
}
nav a {
text-decoration: none;
color: white;
font-weight: bold;
}
nav a:hover {
color: #f25e44;
}
.activeLink {
color: #f25e44;
}
#wrapper {
width: 1400px;
/*border: 1px solid black;*/
margin-left: auto;
margin-right: auto;
box-shadow: 10px 5px 5px 10px #888888;
}
EDIT: I figured out the issue. I had a div overlapping my ul.
FIDDLE
The # would normally reference an anchor on your page and scroll there. Since you are just using the # it links to itself, so the page wouldn't reload, and would stay in the same place.
Your CSS also specifies not to decorate (underline) the hyperlinks, giving the impression that the link does nothing.
Edit: http://jsfiddle.net/2L3hL7w6/
I've added some CSS to highlight in red if a link has been visited - you'll see if you click on one of your links on the page it changes to red, showing the link does in fact work.
nav a:visited {
color: #ff0000;
}
All the links are the same in your example code. So when you once clicked one link....nothing more will happen since you are already there.