How to position inside flex-box? - css

I am using flex box and want to align button to the bottom.
I am using position absolute and bottom: 0, but browser is ignoring it.
<ul class="box">
<li><div>this has <br> more <br> <button>one</button></div></li>
<li><div>this has <br> more <br> content <br> <button>one</button></div></li>
<li>d<div><button>one</button></div></li>
</ul>
ul {
/* basic styling */
width: 100%;
height: 100px;
border: 1px solid #555;
/* flexbox setup */
display: -webkit-box;
-webkit-box-orient: horizontal;
display: -moz-box;
-moz-box-orient: horizontal;
display: box;
box-orient: horizontal;
}
.box > li {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
margin: 0 1px;
padding-bottom: 20px;
border-bottom: 20px solid red;
position: relative;
}
button {
position: absolute;
bottom: 0;
}
/* our colors */
.box > li:nth-child(1){ background : #FCC; }
.box > li:nth-child(2){ background : #CFC; }
.box > li:nth-child(3){ background : #CCF; }
I can use float and not use flex-box, but I want to see if there is a solution for this using flex-box.
demo here:
http://jsfiddle.net/NJAAa/

Working WebKit version: http://jsfiddle.net/LLtmE/
In short: you need to put your text context in a separate div; make each li a flexbox and set box-orient to vertical. And remove all that absolute/relative positioning - it's no longer necessary.

The reason is the flex container has no specific width or height,since its flexible with its contents.
To ensure my statement, try with left or top, it will react for your data. If you try with right or bottom, you cant see the reaction. Since the flex container box original width / height is very less.

Check this on codepen. I hope this help and that is not late:)
ul {
margin: 0;
padding: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
width: 80%;
margin: 10% auto;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
color: #b2b2b2;
box-shadow: 2px 2px 3px #666666;
}
ul > li {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
-ms-flex-preferred-size: 33.33%;
flex-basis: 33.33%;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
text-align: center;
}
ul > li > button {
margin: 20px;
padding: 5px 15px;
cursor: pointer;
}
ul > li > button:hover {
color: whitesmoke;
background-color: maroon;
}
/* our colors */
ul > li:nth-child(1) {
background: #000000;
}
ul > li:nth-child(2) {
background: #191919;
}
ul > li:nth-child(3) {
background: #323232;
}
And this can be helpfull....

Related

<li> tag with flex, custom bullet icon and bold text

Everything seems to be working but as soon as I create bold text either with <strong> or <span> inside the <li> tag - it ignores the space that should have been between words because I'm using flex.
I have tried every possible justify-content on the <li> tag and didn't come up with a solution to this.
HTML:
<div class="bullets">
<ul>
<li><strong>100X</strong> More Powerful</li>
<li>Say <strong>No</strong> To Plastic</li>
<li>Fits <strong>99.9%</strong> On The Market</li>
<li>Saves Approximately <strong>8 Hours A Year</strong></li>
<li>Durable Like <strong>$3,000</strong> Worth</li>
</ul>
</div>
CSS:
.bullets {
display: flex;
flex-flow: column wrap;
font-size: 18px;
ul {
list-style: none;
li {
display: flex;
align-items: center;
padding-left: 16px;
}
li:not(:first-of-type) {
margin-top: 15px;
}
li:before {
content: "";
background-image: url('https://cdn.shopify.com/s/files/1/0493/4605/2261/files/checkmark.svg?v=1600908500');
background-size: 24px 21px;
margin-left: -16px;
width: 24px;
height: 21px;
margin-right: 10px;
}
}
}
https://jsfiddle.net/z2r6j4ts/
You may use a gap
.bullets {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-flow: column wrap;
font-size: 18px;
}
.bullets ul {
list-style: none;
}
.bullets ul li {
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
padding-left: 16px;
gap: 0.25em;
}
.bullets ul li:not(:first-of-type) {
margin-top: 15px;
}
.bullets ul li:before {
content: "";
background-image: url("https://cdn.shopify.com/s/files/1/0493/4605/2261/files/checkmark.svg?v=1600908500");
background-size: 24px 21px;
margin-left: -16px;
width: 24px;
height: 21px;
margin-right: 10px;
}
<div class="bullets">
<ul>
<li><strong>100X</strong> More Powerful</li>
<li>Say <strong>No</strong> To Plastic</li>
<li>Fits <strong>99.9%</strong> On The Market</li>
<li>Saves Approximately <strong>8 Hours A Year</strong></li>
<li>Durable Like <strong>$3,000</strong> Worth</li>
</ul>
</div>
edit
examples from below comments :
flex-wrap/white-space
.bullets {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-flow: column wrap;
font-size: 18px;
}
.bullets ul {
list-style: none;
}
.bullets ul li {
display: -webkit-box;
display: flex;
flex-wrap: wrap;
-webkit-box-align: center;
align-items: center;
padding-left: 16px;
gap: 0.25em;
white-space: nowrap;
}
.bullets ul li:not(:first-of-type) {
margin-top: 15px;
}
.bullets ul li:before {
content: "";
background-image: url("https://cdn.shopify.com/s/files/1/0493/4605/2261/files/checkmark.svg?v=1600908500");
background-size: 24px 21px;
margin-left: -16px;
width: 24px;
height: 21px;
margin-right: 10px;
}
<div class="bullets">
<ul>
<li><strong>100X</strong> More Powerful</li>
<li>Say <strong>No</strong> To Plastic</li>
<li>Fits <strong>99.9%</strong> On The Market</li>
<li>Saves Approximately <strong>8 Hours A Year </strong>8 Hours A Year 8 Hours A Year 8 Hours A Year</li>
<li>Durable Like <strong>$3,000</strong> Worth</li>
</ul>
</div>
flex-wrap only
.bullets {
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-flow: column wrap;
font-size: 18px;
}
.bullets ul {
list-style: none;
}
.bullets ul li {
display: -webkit-box;
display: flex;
flex-wrap: wrap;
-webkit-box-align: center;
align-items: center;
padding-left: 16px;
gap: 0.25em;
}
.bullets ul li:not(:first-of-type) {
margin-top: 15px;
}
.bullets ul li:before {
content: "";
background-image: url("https://cdn.shopify.com/s/files/1/0493/4605/2261/files/checkmark.svg?v=1600908500");
background-size: 24px 21px;
margin-left: -16px;
width: 24px;
height: 21px;
margin-right: 10px;
}
<div class="bullets">
<ul>
<li><strong>100X</strong> More Powerful</li>
<li>Say <strong>No</strong> To Plastic</li>
<li>Fits <strong>99.9%</strong> On The Market</li>
<li>Saves Approximately <strong>8 Hours A Year </strong>8 Hours A Year 8 Hours A Year 8 Hours A Year</li>
<li>Durable Like <strong>$3,000</strong> Worth</li>
</ul>
</div>
Add these line to your CSS code:
li > strong{ margin: 0 2px; }
You can add the following code to make spacing work:
li {
strong {
margin: 0 .25rem;
}
}

How can I expand the empty margins on flex items?

The dark gray area is clickable but the blue margin has no action. How can I expand the rest of the smaller sized items to fill in the space?
div.scrollmenu {
display:flex;
justify-content: flex-start;
align-items: center;
background-color: #333;
overflow: auto;
flex-wrap: nowrap;
}
div.scrollmenu a {
display: flex;
color: white;
text-align: left;
padding: 14px;
text-decoration: none;
margin: auto;
min-width: 25%;
max-width: 25%;
}
Add the align-items: stretch; property to your div.scrollmenu and tweak your code a bit.
div.scrollmenu {
display:flex;
/* align-items: stretch; */ /* redundant */
background-color: #333;
flex-wrap: nowrap;
}
div.scrollmenu a {
display: flex;
align-items: center;
/* uncomment this if you want them to be centered horizontally */
/*justify-content: center;*/
padding: 1 14px;
color: white;
text-align: left;
text-decoration: none;
flex: 1;
}
Hope this helps.
EDIT You don't even need align-items: stretch because I believe that's the default property since the result is the same even if you leave it out.

How to get an ASP.NET MVC Navigation Bar to be horizontal instead of vertical?

In my MVC5 page, the navigation bar options are not side-by-side, but vertically collapsed:
Is the setting for this in the index page or in bootstrap.css? Here is a section of my bootstrap.css in case that helps:
.navbar-nav {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
padding-left: 0;
margin-bottom: 0;
list-style: none;
}
.navbar-nav .nav-link {
padding-right: 0;
padding-left: 0;
}
.navbar-nav .dropdown-menu {
position: static;
float: none;
}
.navbar-text {
display: inline-block;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
.navbar-collapse {
-ms-flex-preferred-size: 100%;
flex-basis: 100%;
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
The problem is not from the bootstrap library. The navbar which is seen when you create a new project is the default navbar. If you want to change it to a left navbar, bootstrap has different navbar classes which it exposes you to you. For instance you can change the class attribute to
class="navbar navbar-left"
Or visit BootStrap Documentation

Position sticky strange rendering

I have simple navigation bar with position:sticky that displays not clear when scrolled and everything seems to work fine then it is in the top.
As you can see from the images above there seems to be some render problem. Here is the css:
body{
/*For demo purpose*/
height:300vh;
}
* {
font-family: RobotoThin;
margin: 0;
padding: 0;
overflow-x: hidden;
outline: none;
-webkit-transition: 1s;
transition: 1s;
box-sizing: border-box;
background-repeat: no-repeat;
transition: 0.5s !important;
scroll-behavior: smooth;
}
div.window {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
padding: calc(2vh + 2vw);
height: 100vh;
width: 95vw;
position: absolute;
right: 0;
top: 0;
display: none;
white-space: nowrap;
display: flex;
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
background-color: #ecf0f1;
margin-left: 5vw;
}
#help{
display:block;
transition:0s !important;
}
div#help{
height:200vh;
white-space: normal;
}
div#help a{
color:red;
text-decoration: none;
}
div#nav {
top: 0;
position: sticky;
display: flex;
justify-content: space-between;
color: black;
background-color: white;
padding-top: 1vmax;
padding-bottom: 1vmax;
font-size: 1.2vmax;
flex-wrap: wrap;
border-radius: 10em;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
div#nav>a {
color: black;
}
div#nav>*:hover {
color: gold;
letter-spacing: 0.3vw;
}
div#nav> :first-child {
margin-left: 1vw;
}
div#nav> :last-child {
margin-right: 1vw;
}
<body>
<div class='windows' id='help'>
<div id='nav'> <a>General important info</a> <a>Desktop</a> <a>Math calculators</a> <a>Notes</a> <a>Battery</a> <a>Quotes</a> <a>Settings</a> <a>Passwords and Data</a> </div>
</div>
</body>
Don't mind the color. I use a plugin so you will see everything in white, not in black.
Strangely I couldn't get the example to work properly and I can not represent the issue. Hopefully you can take a look at my code and tell what may cause this problem.
After much fiddling, the culprit is:
overflow-x: hidden;
body {
/*For demo purpose*/
height: 300vh;
}
* {
font-family: RobotoThin;
margin: 0;
padding: 0;
/* overflow-x: hidden; <-- The problem */
outline: none;
-webkit-transition: 1s;
transition: 1s;
box-sizing: border-box;
background-repeat: no-repeat;
transition: 0.5s !important;
scroll-behavior: smooth;
}
div.window {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
padding: calc(2vh + 2vw);
height: 100vh;
width: 95vw;
position: absolute;
right: 0;
top: 0;
display: none;
white-space: nowrap;
display: flex;
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
background-color: #ecf0f1;
margin-left: 5vw;
}
#help {
display: block;
transition: 0s !important;
}
div#help {
height: 200vh;
white-space: normal;
}
div#help a {
color: red;
text-decoration: none;
}
div#nav {
top: 0;
position: sticky;
display: flex;
justify-content: space-between;
color: black;
background-color: white;
padding-top: 1vmax;
padding-bottom: 1vmax;
font-size: 1.2vmax;
flex-wrap: wrap;
border-radius: 10em;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
div#nav>a {
color: black;
}
div#nav>*:hover {
color: gold;
letter-spacing: 0.3vw;
}
div#nav> :first-child {
margin-left: 1vw;
}
div#nav> :last-child {
margin-right: 1vw;
}
<body>
<div class='windows' id='help'>
<div id='nav'> <a>General important info</a> <a>Desktop</a> <a>Math calculators</a> <a>Notes</a> <a>Battery</a> <a>Quotes</a> <a>Settings</a> <a>Passwords and Data</a> </div>
</div>
</body>

How to remove the text-decoration underline on a flex child when the parent is the anchor?

I am trying to remove the text-decoration of a flex child when the parent is the anchor. I've tried all of the following code, and it is not working at all. I've created a jsFiddle, and on that the underline shows all the time and not on hover. In my WordPress installation, it only shows on hover. I'm really not sure what to do! Any help is appreciated!
Thank you ahead of time!!!!
.fleximagebox_link:hover, a.fleximagebox_link:hover, a .fleximagebox_link:hover,
.fleximagebox_link a:hover, .fleximagebox_link:hover a,
a .fleximagebox_link p:hover, .image_background:hover, .image_background:hover a,
a .image_background:hover, .image_background.fleximagebox_link a:hover,
a .image_background.fleximagebox_link:hover {
text-decoration: none!important;
}
Here is the jsFiddle that explains what I'm talking about: https://jsfiddle.net/Clare12345/th60mde3/2/
This will get rid of the underline in your fiddle .flexbox_images a { text-decoration: none; }
As to why it's on your website, all we can do is guess if you don't include the code or a link to your site. But you might try changing that line to .flexbox_images a, .flexbox_images a:hover { text-decoration: none !important; }
.flexbox_images a {
text-decoration: none;
}
.main_box {
background: white;
height: 400px;
width: 100%;
margin: 0 auto;
padding: 0px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
overflow: hidden;
}
.main_box .flexbox_images {
color: white;
width: 100%;
padding: 0px;
overflow: auto;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.flexbox_images a {
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
width: 100%;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.image_background {
height: 250px;
margin: 0 auto;
-webkit-box-flex: 1;
-moz-box-flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
flex: 1;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
max-width: 101%;
}
.image_background_left {
background-repeat: no-repeat;
background-size: contain;
background-image: url(http://pipsum.com/350x240.jpg);
justify-content: flex-end;
margin-right: -1px;
}
.image_background_right {
background-repeat: no-repeat;
background-size: contain;
background-image: url(http://pipsum.com/350x240.jpg);
justify-content: flex-start;
margin-left: -1px;
}
.fleximagebox_link {
font-size: 28pt;
background: rgba(255, 255, 255, 0.85);
color: #000!important;
text-transform: uppercase;
font-weight: 900;
letter-spacing: 1.5px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
width: 130px;
}
.image_background_left .fleximagebox_link {
justify-content: flex-end;
padding-left: 35px;
}
.image_background_right .fleximagebox_link {
justify-content: flex-start;
padding-right: 35px;
}
.image_background_right .fleximagebox_link p {
font-size: 28pt!important;
color: #000!important;
text-transform: uppercase;
font-weight: 900;
letter-spacing: 1.5px;
margin-bottom: 0px;
}
.main_black_bar {
width: 3px;
background: #000;
height: 50px;
margin-top: 15px;
margin-bottom: 15px;
margin-left: -1px;
}
.image_background_left .main_black_bar {
margin-left: 35px;
}
.image_background_right .main_black_bar {
margin-right: 35px;
}
<div class="main_box">
<div class="flexbox_images">
<a href="">
<div class="image_background image_background_left">
<div class="fleximagebox_link">Buy
<div class="main_black_bar"> </div>
</div>
</div>
</a>
<a href="">
<div class="image_background image_background_right">
<div class="fleximagebox_link">
<div class="main_black_bar"> </div>Sell</div>
</div>
</a>
</div>
</div>

Resources