Bootstrap Divider Alignment Issues (mobile only) - css

I have the following styled divider. The result on desktop when in responsive mode displays correctly. However when viewing on an actual mobile device it is breaking and left align instead of center.
I can't sort out where I went wrong in CSS, I think it is incorrect use of the margin. Since it is rendering correctly on the desktop debugger - I can't figure it out.
HTML:
<div class="divider my-3"><span class="bg-primary p-3 text-white border-radius-3">Test</span></div>
CSS:
.divider {
color: #8f9397;
width: 100%;
margin: 0 auto;
overflow: hidden;
text-align: center;
line-height: 0em;
}
.divider:before {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
content: "";
display: inline-block;
height: 0em;
margin: 0 0 0 -100%;
vertical-align: middle;
width: 50%;
}
.divider:after {
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
content: "";
display: inline-block;
height: 0;
vertical-align: middle;
width: 50%;
margin: 0 -100% 0 0;
}
Result on Desktop (Responsive Mode):
Result on Mobile:

For me, the best way to do it like this:
.line {
height: 2px;
top: calc(50% - 1px);
}
.content {
width: max-content;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="divider text-center position-relative my-4">
<span class="line position-absolute start-0 end-0 bg-dark"></span>
<div class="content position-relative bg-white px-3 mx-auto">
<span class="bg-primary p-3 text-white border-radius-3">Test</span>
</div>
</div>

Related

flex-shrink does not update item width

Update: I think there is no easy solution to this if I have to use flexbox. I'll just use "flex-shrink: 0" and use media queries to adjust the design. Anyway, thanks for your help.
I have got a horizontal list (display: flex) with multiple elements. When I reduce the window size the list elements start to shrink. Unfortunately, the width of the elements nearly stays the same. The li-elements take up too much space. I want the li-element's size to fit the content. If I add "flex-shrink: 0" to the li-element the width is right, but I need this word-wrap.
How to fix this?
With flex-shrink: 0
With flex-shrink: 1
#categories ul {
border-top: 1px solid lightgrey;
display: flex;
margin: 0 0 -1px 0;
padding: 7px 0 0 0;
}
#categories li {
padding: 0 0 7px 0;
margin-right: 15px;
list-style-type: none;
}
<nav id="categories">
<ul>
<li><a href="#">
Thanks & regards,
Mark
Remember that the flex-shrink property sets the flex-shrink of a flex container item. So the items will shrink to fit the container if they are larger than the container's size. In your case, I think that setting flex-shrink to 2 would make the word-wrap as you requested. Check this code snippet. I hope it helps!
function myFunction(val) {
document.getElementById("example-element").style.flexShrink = val;
}
* {
font-family: arial;
}
.buttons-section {
display: flex;
justify-content: space-evenly;
width: 70%;
}
.example-container {
background-color: #eee;
border: .2em solid;
padding: .75em;
border-radius: 10px;
width: 70%;
margin-left: 20px;
max-height: 300px;
display: flex;
}
.example-container>div {
margin: 10px;
}
.first-solution>div {
background-color: rgba(0, 255, 0, 0.2);
border: 3px solid green;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 300px;
}
p {
margin-left: 20px;
}
small {}
.second-solution {
flex: 1 1 0;
justify-content: space-evenly;
}
.second-solution>div {
background-color: rgba(255, 0, 0, 0.2);
border: 3px solid red;
text-align: center;
}
.third-solution {
flex-wrap: wrap;
}
.third-solution>div {
background-color: rgba(0, 0, 255, 0.2);
border: 3px solid blue;
flex-basis: 100px;
text-align: center;
}
<section class="buttons-section">
<div>
<pre><code>flex-shrink: 0;</code></pre>
<button type="button" onclick="myFunction(0)" aria-hidden="true">Apply
</button>
</div>
<div>
<pre><code>flex-shrink: 1;</code></pre>
<button type="button" onclick="myFunction(1)" aria-hidden="true">Apply
</button>
</div>
<div>
<pre><code>flex-shrink: 2;</code></pre>
<button type="button" onclick="myFunction(2)" aria-hidden="true">Apply
</button>
</div>
</section>
<br>
<div>
<section>
<div class="example-container first-solution">
<div id="example-element">I shrink</div>
<div id="example-element">Item Two</div>
<div id="example-element">Item Three</div>
</div>
</section>
</div>
<p>Added more examples after the first comment. Feel free to resize the screen to see the behaviouršŸ˜‰</p>
<p>All elements same size, container with flex: 1 1 0;<br>
<small>Added <b>justify-content: space-evenly;</b> which helps to distribute the extra free space </small>
</p>
<div>
<section>
<div class="example-container second-solution">
<div>Item one</div>
<div>Item Two</div>
<div>Item Three</div>
</div>
</section>
</div>
<p>Suggestion: using flex-wrap: wrap; on the container so the items will always fit the container</p>
<div>
<section>
<div class="example-container third-solution">
<div>Item one</div>
<div>Item Two</div>
<div>Item Three</div>
</div>
</section>
</div>
Can you paste your code here so we can see more info about your problem. Also did you try with flex-grow property?

Image overlay doesn't fit

I've a problem with image overlay.
Code is here: https://codepen.io/r-smal/pen/BOBdmX
<section class="team">
<h2 class="team__title">team</h2>
<div class="team__wrapper container__team ">
<div>
<div class="team__card ">
<div class="team__overlay"></div>
<img class="team__img" src="https://i.imgur.com/vWIuUtd.jpg" alt="mako">
</div>
<h3 class="team__description">lorem</h3>
<p class="team__span">ipsum</p>
</div>
<div>
<div class="team__card ">
<div class="team__overlay"></div>
<img class="team__img" src="https://i.imgur.com/vWIuUtd.jpg" alt="mako">
</div>
<h3 class="team__description">lorem</h3>
<p class="team__span">ipsum</p>
</div>
<div>
<div class="team__card ">
<div class="team__overlay"></div>
<img class="team__img" src="https://i.imgur.com/vWIuUtd.jpg" alt="mako">
</div>
<h3 class="team__description">lorem</h3>
<p class="team__span">ipsum</p>
</div>
</section>
.container__team {
max-width: 1700px;
margin: 0 auto;
}
.team {
&__title {
margin: 100px;
text-align: center;
font-size: 30px;
text-transform: uppercase;
position: relative;
&::after{
content: "";
position: absolute;
width: 85px;
border-bottom: solid 3px #5dc6e8;
left: 48.5%;
top: 50px;
}
}
&__wrapper {
display: grid;
grid-template-columns: 33.33% auto auto;
text-align: center
}
&__description {
margin: 50px 0 20px;
text-align: center;
font-size: 35px;
}
&__span{
font-size: 35px;
text-align: center;
}
&__card {
position: relative;
}
&__overlay {
position: absolute;
background: rgba(0,0,0,0.6);
width: 100%;
height: 100%;
display: none;
}
&__img{
}
}
.team__card:hover .team__overlay{
display: block;
transition: 0.3s;
}
As you can see on codepen overlay on top of image is bigger than my image and I can't figure out why. I made it 'fit" but I have to use static margins so in resoult in mobile version it doesn't look right.
And one last question how do I position ::after element center under my text that will stay here even in mobile?Without using static margin like in my code.

flexbox css centering and layout not working horizontally

I am trying to center the content of a navbar for mobile devices.
It should have 3 divs, the far left div should be the 3 bars for menu expansion (hamburger), the middle div should contain the logo, and the far right div should contain 3 inputs.
The problem is it is centering horizontally based on the left edge of the far right div. [= LOGO input input input] but it looks like this
[= LOGO input input input] if I take out all but 2 inputs
[= LOGO [input] it works perfectly but with 3 inputs it does not.
I have tried everything can anyone give me a clue as to why this won't work?
thanks
#media screen and (max-width: 1023px) and (min-width: 300px) {
#hidden-nav {
justify-content: space-between;
height: 8vh;
background-color: rgb(101, 0, 0);
display: flex;
padding: 8px;
min-width: 80px;
position: fixed;
width: 100%;
z-index: 10002;
}
}
#hidden-nav input {
max-width: 15vw;
}
body {
}
#hidden-nav:first-child {
/* padding-left: 2em;
border: 20px solid blue;*/
}
.bar {
width: 25px;
height: 2px;
background-color: white;
margin: 6px 0;
}
#container-for-right-hidden-nav {
border: 2px solid blue;
display: flex;
}
<div id="hidden-nav" style="border-bottom: 1px solid white; align-items:">
<div class="" onclick="toggleSidebar()">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
<div style=""> <img height="35" width="50" src="https://seohackercdn-seohacker.netdna-ssl.com/wp-content/uploads/2011/07/Link-Searching.jpg?x68951" alt="logo" /> </div>
<img height="35" width="50" src="https://seohackercdn-seohacker.netdna-ssl.com/wp-content/uploads/2011/07/Link-Searching.jpg?x68951" alt="logo" />
</div>
<div id="container-for-right-hidden-nav">
<a href="/">
<input type="button" style="background-color: dodgerBlue;" value="floorplans">
</a>
<a href="/">
<input type="button" style="background-color: green;" value="apply">
</a>
<a href="/">
<input type="button" style="background-color: #003059;" value="contact">
</a>
</div>
Try justify Content center and align-items center.
Hope it Helps.
#hidden-nav {
display: flex;
justify-content: center;
align-items:center;
height: 8vh;
background-color: rgb(101, 0, 0);
padding: 8px;
min-width: 80px;
position: fixed;
width: 100%;
z-index: 10002; }
}

Could browser like tabs made with flex box or css only?

Need tabs to shrink while the main container doesn't fit all items by width.
Here is expected behavior:
http://adamschwartz.co/chrome-tabs/
But could it be done on pure css, flexbox may be?
Solution was pretty simple. Just display: flex; for container, and overflow: hidden; for tab items.
Don't know why my question was downvoted. :(
html {
font-family: sans-serif;
}
.container {
display: flex;
border: 1px solid silver;
padding: 10px 10px 0;
width: 400px;
margin: 0 auto 10px;
}
.tab {
overflow: hidden;
text-overflow: ellipsis;
height: 20px;
border: 1px solid silver;
border-top-right-radius: 8px;
border-top-left-radius: 8px;
padding: 10px;
margin-right: 8px;
border-bottom: none;
}
.tab:last-child {
margin-right: 0;
}
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
</div>
<div class="container">
<div class="tab">Google</div>
<div class="tab">Apple</div>
<div class="tab">Facebook</div>
<div class="tab">Chrome</div>
<div class="tab">Flexbox</div>
<div class="tab">Stackoverflow</div>
</div>

Trying to arrange images using css

Here is the code I am using so far. I have 6 images that I am trying to arrange and make responsive as well.
Idea is like this
image -blank space - image
image -----blank space -----image
image -blank space - image
When I squeeze the page they do not end up stacked uniformly on top of each other. The spaces need to go away so all I have is 6 images on top of each other. CSS below followed by html
.row:after {
content: "";
clear: both;
display: table;
}
/** North Scottsdale */
.nsdl {
float: left;
margin: 0 175px;
padding: 0 0px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
/** break1 */
.break1 {
float: left;
margin: 0px;
padding: 0px;
width: 95px;
height: 200px;
border: 3px solid white;
}
/** Scottsdale */
.sdl {
float: left;
margin: 0px;
padding: 10px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
/** Tempe */
.tmpe {
float: left;
margin: 0 35px;
padding: 10 10px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
/** break2 */
.break2 {
float: left;
margin: 10px;
padding: 10px;
width: 475px;
height: 200px;
border: 3px solid white;
}
/** Downtown */
.dtown {
float: left;
margin: 10px;
padding: 10px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
/** West Side */
.wside {
float: left;
margin: 0 175px;
padding: 0 0px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
/** break1 */
.break3 {
float: left;
margin: 0px;
padding: 0px;
width: 95px;
height: 200px;
border: 3px solid white;
}
/** UPTOWN */
.utown {
float: left;
margin: 0 120px;
padding: 10 10px;
width: 300px;
height: 200px;
border: 3px solid white;
background-image: url("/images/dphotos/test2a.png");
}
<div class="w3-container">
<div class="row">
<div class="left">
<div class="nsdl" style="text-align: center;">
<h2>Ā NORTH SCOTTSDALE</h2>
</div>
</div>
<div class="center">Ā </div>
<div class="right">
<div class="sdl" style="text-align: center;">
<h2>SCOTTSDALE</h2>
</div>
</div>
</div>
<div class="row">
<div class="left">
<div class="tmpe" style="text-align: center;">
<h2>TEMPE</h2>
</div>
</div>
<div class="center">Ā </div>
<div class="right">
<div class="dtown" style="text-align: center;">
<h2>DOWNTOWN</h2>
</div>
</div>
<div class="left">
<div class="wside" style="text-align: center;">
<h2>WEST SIDE</h2>
</div>
</div>
<div class="center">Ā </div>
<div class="right">
<div class="utown" style="text-align: center;">
<h2>UPTOWN</h2>
</div>
</div>
</div>
</div>
I would suggest looking at a number of frameworks like Bootstrap, Skeleton and Zurb Foundation and use their CSS grid components. Look into how they control the size of various page regions with media queries using a mobile first approach.
You can definitely roll your own solution too. Here's an example.
<div class="img-group">
<div class="img-holder">
<img src="http://placehold.it/300x300?text=1">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=2">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=3">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=4">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=5">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=6">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=7">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=8">
</div>
<div class="img-holder">
<img src="http://placehold.it/300x300?text=9">
</div>
</div>
.img-group img {
display: block;
max-width: 100%;
}
.img-holder {
float: left;
width: 50%;
}
#media ( min-width: 448px ) {
.img-holder {
width: 33.333%;
padding: 0.75%;
}
}
#media ( min-width: 779px ) {
.img-holder {
box-sizing: border-box;
width: 25%;
padding: 2%;
}
}
Demo JSFiddle.
First you make your images responsive. The simplest version of doing so is setting them to display: block; and max-width: 100%;. Setting the max width means they'll try to take up their parent element's width as long as they don't exceed their own intrinsic width. For example, if the parent element is 700px wide and the image is 600px wide, it won't stretch to fit the 700px of space. It will stop at 600px.
Now you place your images in container elements that you'll control with media queries. Use percentage widths (i.e. width: 25%; ) so they stay nice and fluid.
You might be wondering what box-sizing: border-box; does. It says that padding should be included as a part of your width definition. Normally if you have width: 25%; padding: 1%; the total width of your element would be 27% as 1% + 25% + 1% = 27%.

Resources