Unexpected height while using flexbox model - css

I'm trying to make a side menu and i want to use flexbox model. But i have a problem that i haven't solved.
In my menu there are some list element (like dashboard, componenets, ...). This list elements are in <a> tag. When you look with inspector tool the height of <a> tag is normal but containing <li> tags height is strangely long. There is some padding in <li> but not that much. There is no reaseon for the <li> is long like this.
The reason that i use flexbox model in <a> is there is some other element is <a> to be positioned in my original project. But i didn't put them in this example.
The height of <a>: https://postimg.org/image/7cqo2pazf/
The height of <li>: https://postimg.org/image/kgw8feaqz/
Why do you think this strangely long height of <li> is happened?
.left-menu {
position: fixed;
top: 0px;
bottom: 0px;
left: 0px;
width: 220px;
background-color: #eee;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
}
.left-menu .menu-container>ul {
margin: 0px;
padding: 0px;
}
.left-menu .menu-container>ul>li {
padding: 2px 8px;
}
.left-menu .menu-container>ul>li>a {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
position: relative;
padding: 6px 8px;
text-decoration: none;
font-size: .875em;
border-radius: 4px;
font-weight: bold;
color: #111;
}
.left-menu .menu-container>ul>li>a:hover {
background: rgba(212, 212, 212, 0.5);
}
<div class="left-menu">
<div class="menu-container">
<ul>
<li>Dashboard</li>
<li>Components</li>
<li>Forms</li>
<li>Tables</li>
</ul>
</div>
</div>

Simply add display:block to your list.
.left-menu .menu-container>ul>li {
padding: 2px 8px;
display: block;
}
Have a look at this snippet
.left-menu {
position: fixed;
top: 0px;
bottom: 0px;
left: 0px;
width: 220px;
background-color: #eee;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
}
.left-menu .menu-container>ul {
margin: 0px;
padding: 0px;
}
.left-menu .menu-container>ul>li {
padding: 2px 8px;
display:block;
}
.left-menu .menu-container>ul>li>a {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
position: relative;
padding: 6px 8px;
text-decoration: none;
font-size: .875em;
border-radius: 4px;
font-weight: bold;
color: #111;
}
.left-menu .menu-container>ul>li>a:hover {
background: rgba(212, 212, 212, 0.5);
}
<div class="left-menu">
<div class="menu-container">
<ul>
<li>Dashboard</li>
<li>Components</li>
<li>Forms</li>
<li>Tables</li>
</ul>
</div>
</div>

Related

Dropdown menu show behind div - z-index, overflow, position not working

I need some help with a dropdown menu that's hiding behind a div. I tried setting the z-index to higher value, set the li to position:relative, checked for overflow in css (none). I see these as common causes for this issue, but nothing works for me.
Please note that z-index, positive and negative, were added whilst trying to find a solution. It makes no difference.
NOTE: dropdown is hiding behind "text-on-banner", yet showing in front of "main-banner".
Thanks for looking at this.
HTML:
<div class="wrapper">
<div class="header">
<ul class="PrimaryNav with-indicator">
<li class="Nav-item">
A
<li class="Nav-item">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">B</a>
<ul class="dropdown-menu">
<li class="Nav-subitem">B.1</li>
<li class="Nav-subitem">B.2</li>
<li class="Nav-subitem">B.3</li>
</ul>
<li class="Nav-item">
C
</ul>
</div>
</div>
<div class="section-wrapper">
<div class="main-banner">
<div class="text-on-banner">
<h2><strong>SOME TEXT HERE</strong></h2>
</div>
</div>
</div>
CSS:
.wrapper {
width: 100%;
}
.header {
width: 100%;
background: #26282c;
color: #f5f5f5;
text-align: center;
}
.PrimaryNav {
list-style: none;
margin: 7px auto;
max-width: 1220px;
padding: 0;
width: 100%;
font-family: 'Open Sans', sans-serif;
font-size: 130%;
font-weight: 600;
}
.with-indicator {
position: relative;
z-index: 0;
}
.Nav-item {
background: #26282c;
display: block;
float: left;
margin: 0;
padding: 0;
width: 14.28%;
text-align: center;
}
.Nav-item a {
color: #c2c5ca;
display: block;
padding-top: 20px;
padding-bottom: 20px;
text-decoration: none;
}
.Nav-subitem {
background: #26282c;
display: inline-block;
width: 100%;
text-align: center;
position: relative;
z-index: 999999;
}
.section-wrapper {
max-width: 1250px;
margin: auto;
padding: 20px 0 0 0;
}
.main-banner {
text-align: center;
font-weight: 700;
font-family: 'Titillium Web', sans-serif;
font-size: 36px;
line-height: 40px;
padding: 10px 2px 1px 2px;
color: #26282c;
box-shadow:
inset 0 0 0 1px rgba(232, 45, 0, 0.1),
inset 0 0 5px rgba(232, 45, 0, 0.2),
inset -285px 0 35px white;
border-radius: 10px;
background: #fff url(banner00.jpg) no-repeat center left;
z-index: -1;
}
.text-on-banner {
font-weight: 1000;
width: 95%;
max-width: 95%;
background-color:white;
opacity:0.6;
border-radius: 10px;
z-index: -1;
}
.text-highlight {
color: #e82d00;
font-weight: 800;
}
After spending 2-3 hours on this, I just realize that it was the .with-indicator ul which had to have z-index > 0. All working as expected now.
Hope this helps somebody else though. Thanks for looking.

Hyperlink combined with pseudo code

In the code below, how can I have the same font color for the hyperlinks as for the other text? It now seems to morph with the color as defined in the pseudo code.
ul {
list-style: none;
margin: 0;
padding: 0;
}
a, a:link, a:visited, a:active {
text-decoration: none;
color: #484693;
}
nav {
color: #484693;
font-weight: bold;
width: calc(100% - 5vw);
display: flex;
align-items: center;
}
nav>ul {
display: flex;
align-items: center;
width: 100%;
justify-content: space-around;
}
nav>ul>li {
margin-right: 2em;
}
nav>ul>li.header-button {
position: relative;
padding: 1em;
}
nav>ul>li.header-button::before {
content: '';
width: 100%;
height: 70%;
background: rgba(255, 25, 255, 0.4);
border: thin solid rgba(255, 25, 255, 0.4);
border-radius: 20px;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
}
<nav>
<div class="header-logo">
<img src="http://via.placeholder.com/50x50" alt="" />
</div>
<ul>
<li>Option1</li>
<li>Option2</li>
<li class="header-button">Option3</li>
<li class="header-button">Option4</li>
</ul>
</nav>
The issue you are having is the pseudo element you are using to create the background is coming on top of the anchor tag, since you have given absolute position to the pseudo element. You can overcome that by assigning position relative to the anchor tag and assign a z-index to it.
WORKING DEMO:
ul {
list-style: none;
margin: 0;
padding: 0;
}
a, a:link, a:visited, a:active {
text-decoration: none;
color: #484693;
}
nav {
color: #484693;
font-weight: bold;
width: calc(100% - 5vw);
display: flex;
align-items: center;
}
nav>ul {
display: flex;
align-items: center;
width: 100%;
justify-content: space-around;
}
nav>ul>li {
margin-right: 2em;
}
nav>ul>li.header-button {
position: relative;
padding: 1em;
}
nav>ul>li.header-button::before {
content: '';
width: 100%;
height: 70%;
background: rgba(255, 25, 255, 0.4);
border: thin solid rgba(255, 25, 255, 0.4);
border-radius: 20px;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
}
nav>ul>li a {
position: relative;
z-index: 1;
}
<nav>
<div class="header-logo">
<img src="http://via.placeholder.com/50x50" alt="" />
</div>
<ul>
<li>Option1</li>
<li>Option2</li>
<li class="header-button">Option3</li>
<li class="header-button">Option4</li>
</ul>
</nav>
Just add this to your css, so your element would be under your text.
nav>ul>li.header-button::before {
z-index: -1;
}
Your :before is overdone and its semitransparent „back“ground overlaps the actual link color (since it's positioned absolute...).
You don't need that. You could fix by z-index, but better do that background directly and way more natural on your links. (Which you want to be clickable, right?). And probably you want to have an inner span for your non-links, to ensure same padding and space:
<nav>
<div class="header-logo">
<img src="http://via.placeholder.com/50x50" alt="" />
</div>
<ul>
<li><span>Option1</span></li>
<li><span>Option2</span></li>
<li class="header-button">Option3</li>
<li class="header-button">Option4</li>
</ul>
</nav>
css:
ul {
list-style: none;
margin: 0;
padding: 0;
}
a, a:link, a:visited, a:active {
text-decoration: none;
color: #484693;
}
nav {
color: #484693;
font-weight: bold;
width: calc(100% - 5vw);
display: flex;
align-items: center;
}
nav ul {
display: flex;
align-items: center;
width: 100%;
justify-content: space-around;
}
nav ul li {
margin-right: 2em;
}
nav ul li a, nav ul li span {
padding: 10px;
}
nav ul li a {
background: rgba(255, 25, 255, 0.4);
border: thin solid rgba(255, 25, 255, 0.4);
border-radius: 20px;
}
nav ul li.header-button {
position: relative;
padding: 1em;
}
Looks like this:
Btw, almost certainly you will be better of with display:table for your <ul>, display: table-cell for your li. Using flex is most certainly overdone...

Scrolling on overflow when making a list of N items

I have a prompt-box div that has a max-height of 80% of the screen.
Inside of it, I have a ul which holds a bunch of li elements depending on how many the user adds.
How do I configure this so that once that prompt-box hits a certain size, new items can be added to the list but the contents just scroll instead of overflowing like this?
Thanks!
Edit: Adding html & css
<div className='prompt-box'>
<p className='title'>What's in your future?</p>
<ul className='options-holder'>
{
this.state.items.map(item => (
<li key={item.id} className='option'>
<div className='circle' />
<p className='item-text'>{ item.text }</p>
</li>
))
}
<li key={0} className='option form'>
<div className='circle' />
<form className='new-item-form' onSubmit={this.handleSubmit}>
<input className='new-item-input' placeholder='Type something and press return...' onChange={this.handleChange} value={this.state.text} />
</form>
</li>
</ul>
<button className='confirm-button'>Continue</button>
</div>
.prompt-box {
#include absolute-center;
background: #1E1E1E;
width: 35%;
margin: 0 auto;
border-radius: 7px;
border: 1px solid rgba(255, 255, 255, 0.1);
color: #ccc;
font-family: 'Circular Book';
max-height: 80%;
overflow-y: auto;
}
.prompt-box .title {
text-align: center;
font-size: 30px;
margin-top: 30px;
margin-bottom: 25px;
}
.prompt-box .options-holder {
list-style: none;
border-radius: 3px; // not currently working
padding: 0;
width: 95%;
margin: 12px auto;
}
.prompt-box .option {
background: #303030;
padding: 18px;
border-bottom: 1px solid rgba(196, 196, 196, 0.1);
}
.prompt-box .option.form {
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
}
.prompt-box .item-text {
color: white;
font-size: 24px;
margin: 0;
display: inline-block;
padding: 0 18px;
}
.prompt-box .new-item-form .new-item-input {
background: transparent;
border-style: none;
font-size: 24px;
padding-left: 18px;
color: white;
width: 80%;
&:focus { outline: none; }
}
.prompt-box .confirm-button {
width: 95%;
margin: 22px auto 18px auto;
}
You haven't shown us any HTML/CSS code for us to reproduce and test a fix for the issue, but adding something like this should work, to allow that container to scroll vertically when its height is exceeded:
.prompt-box {
overflow-y: auto;
}
Try a overflow: scroll; style rule on your div.prompt-box. (You're already giving it a max height, so the extra contents should have a vertical scroll bar).
I threw a max-height and an overflow-y: scroll on the ul and it did the trick.

Margins work fine on chrome but not on firefox

I'm learning basic CSS currently, I'm trying to create a little mockup product page that uses a grid system with 4 columns. It looks and works fine on chrome, but on Firefox it breaks like such. Here's how it looks like on Firefox:
I can't seem to figure out how to fix it, I've tried changing the margins/padding from various locations but to no avail, it's still messing up on Firefox.
Here's my CSS:
html {
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
background: #232526; /* fallback for old browsers */
background: -webkit-linear-gradient(to left, #232526 , #414345); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to left, #232526 , #414345); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
}
* {
box-sizing: border-box;
}
.menu {
background-color: #17534b;
position: absolute;
width: 99.23%;
height: 8vh;
}
ul.nav {
width: 100%;
}
ul.nav li {
list-style: none outside none;
display: inline-block;
width: 19%;
text-align: center;
}
ul.nav li a {
display: block;
text-align: center;
padding: 1.5em;
color: #ffffff;
letter-spacing: 1px;
font-size: 15px;
text-transform: uppercase;
text-decoration: none;
}
ul.nav li a:hover {
background-color: #000000;
color: white;
}
ul.nav li.li-ultimate{
text-transform: uppercase;
color: #eef2ff;
font-size: 25px;
}
section {
width: 100%;
padding: 0 7%;
display: table;
margin: 0;
max-width: none;
height: 100vh;
}
.welcome {
height: 100vh;
background-color: #ffffff;
}
.content {
display: table-cell;
vertical-align: middle;
}
.welcome h1{
font-size: 3em;
display: block;
color: black;
font-weight: 300;
}
.welcome h2 {
font-size: 1.5em;
display: block;
color: black;
font-weight: 200;
}
.productsheader {
color: #ffffff;
}
.productsheader h1{
text-align: center;
color: #ffffff;
font-size: 3em;
}
.products{
height:100vh;
}
ul.rig {
padding: 5%;
list-style: none;
font-size: 0px;
margin-left: -2.5%;
}
ul.rig li {
display: inline-block;
padding: 10px;
margin: 0 0 2.5% 2.5%;
background: #ffffff;
border: 1px solid #ddd;
font-size: 16px;
vertical-align: top;
box-shadow: 0 0 5px #ddd;
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
ul.rig li img {
max-width: 100%;
height: auto;
margin: 0 0 10px;
}
ul.rig li h3 {
margin: 0 0 5px;
text-align: center;
}
ul.rig li p {
font-size: .9em;
line-height: 1.5em;
color: #999;
text-align: center;
}
ul.rig.columns-4 li {
width: 22.5%;
}
Along with the relevant HTML:
<section class="products">
<div class="content">
<div class="productsheader">
<h1>
Our Proudly Presented Products
</h1>
</div>
<ul class="rig columns-4">
<li>
<img src="images/1.jpg"/>
<h3>Is-it-even-a-cup Cup - $100</h3>
<p>Life's true questions.</p>
</li>
<li>
<img src="images/2.jpg"/>
<h3>Flute Looking Cup - $150</h3>
<p>Looks like a flute.</p>
</li>
<li>
<img src="images/3.jpg"/>
<h3>Uterus Looking Cup - $350</h3>
<p>Modelled after a woman's uterus. Probably.</p>
</li>
<li>
<img src="images/4.jpg"/>
<h3>Artistic Cup - $1</h3>
<p>Artsy...ish...</p>
</li>
<li>
<img src="images/5.jpeg"/>
<h3>Ancient Cup - $500</h3>
<p>Or at least we think its old. Sure does look it.</p>
</li>
<li>
<img src="images/6.jpg"/>
<h3>Chinese Poetic Cup - $250</h3>
<p>The cup feels empty when you drink, but you're empty when you don't.</p>
</li>
<li>
<img src="images/7.jpg"/>
<h3>Dragonfly Cup - $25</h3>
<p>Pretty little dragonfly...On a cup.</p>
</li>
<li>
<img src="images/8.png"/>
<h3>FIFA World Cup Brazil - $50</h3>
<p>Technically a cup...</p>
</li>
</ul>
</div>
</section>
Are there any tips to also prevent this from happening in the future when I work on another css project?
ul.rig {
padding: 5%;
list-style: none;
font-size: 0px;
margin-left: -2.5%;
width: 960px; // choose your width like 960px
margin: auto; // auto work with display : block for centering
display: block; // block work with margin : auto for centering
}

div container sizing issues

Earlier I asked a question about horizontal positioning of div containers, now I've got follow up and related questions:
(1) As you can see in the HTML code below, I've got a "column_bottom" container (for links) placed to the left of a "content_bottom" container (for the page's main content).
As I type more content into the "content_bottom" container so that its height exceeds that of the left "column_bottom" container, the entire "content_bottom" container shifts to BELOW the "column_bottom" container. What can I do so that the left "column_bottom" container's height dynamically match the height of the right "content_bottom" container (and they stay horizontally next to each other)?
(2) As you can see in the CSS style sheet below, I tried to manually set the widths of the "column_top" and "column_bottom" to match in em units by trial and error. Would there be any issues with this method across different browsers on different systems? What can I do to ensure that "column_top" and "column_bottom" widths always match?
Thanks for your help.
Here's the HTML:
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>this is the site's title</title>
<link rel="stylesheet" href="penonek.css" type="text/css">
</head>
<body>
<div class="wrapper">
<div class="column_top">site<br>
</div>
<div class="content_top"> title<br>
</div>
<div class="column_bottom">
<ul>
<li>home</li>
<li><a href="#">link 1<br>
</a></li>
<li><a href="#">link 2<br>
</a></li>
<li><a href="#">link 3<br>
</a></li>
</ul>
</div>
<div class="content_bottom">main content here<br>
</div>
</div>
</body>
</html>
Here is the CSS:
body {
margin: 0;
padding: 0;
font-family: Arial,Helvetica,sans-serif;
text-align: center;
color: #cccccc;
background-color: black;
font-size: 1em;
}
.wrapper {
margin: auto;
min-width: 60em;
max-width: 60em;
font-family: Arial,Helvetica,sans-serif;
width: 60em;
color: #cccccc;
}
.column_top {
border-width: 0 0 0.25em;
border-bottom: 0.25em solid black;
width: 3.2em;
min-width: 3.2em;
float: left;
padding-top: 2em;
text-align: right;
color: #333333;
max-height: 1em;
background-color: #f4f4f4;
font-size: 3em;
min-height: 1em;
max-width: 3.2em;
height: 1em;
font-weight: bold;
padding-bottom: 0.2em;
}
.content_top {
border-width: 0 0 0.25em;
border-bottom: 0.25em solid #f4f4f4;
padding-top: 2em;
font-size: 3em;
min-height: 1em;
text-align: left;
max-height: 1em;
height: 1em;
font-weight: bold;
padding-bottom: 0.2em;
}
.column_bottom {
width: 9.28em;
text-align: right;
padding-top: 3em;
color: #333333;
border-bottom-width: 0;
background-color: #f4f4f4;
border-right-width: 0;
padding-right: 0.3em;
float: left;
border-left-width: 0;
min-width: 9.28em;
max-width: 9.28em;
}
.content_bottom {
padding: 3em 5em 5em;
border-collapse: separate;
text-align: left;
float: left;
}
.column_bottom ul {
margin: 0;
padding: 0;
text-decoration: none;
color: #333333;
list-style-type: none;
font-weight: inherit;
}
.column_bottom a:hover {
background-color: #999999;
}
.column_bottom a {
text-decoration: none;
font-weight: inherit;
color: #333333;
}
Add a wrapper for .content_bottom with this css:
.content_bottom_wrapper {
width: 100%;
margin-left: -9.58em;
float: right;
}
And add this to content-bottom:
margin-left: 9.58em;
9.58em = width of .column_bottom + padding-right on .column_bottom
http://jsfiddle.net/p93fM/
Here:
Live Demo
I added this to .content_bottom in CSS
width:640px;
You can adjust the margins as you wish.

Resources