I've got a navbar that looks briliant in all browsers except on Safari - it's stretched at full screen height (but not width).
In all browser it looks like this: https://imgur.com/KB1sBlM
And in Safari...well: https://imgur.com/g1L6wxe
My first assumptions and suspicions are position:sticky, linear-gradient and box-shadow but it's only my suspicions.
Not even sure whether it is a CSS problem. I use also react-scroller there, so my that's the issue?
Here is my SCSS code:
Navbar general:
.thematic-area-nav {
position: sticky;
position: -webkit-sticky;
width: 70vw;
top: 0;
left: 0;
z-index: 2;
font-size: 1.3vw;
-webkit-box-shadow: 0 0 25px 1px #000000;
box-shadow: 0 0 25px 1px #000000;
border-radius: 0 0 5px 5px;
background: -webkit-gradient(
linear,
left top,
left bottom,
from($color-background-primary),
color-stop(50%, rgb(237, 237, 237)),
to($color-background-primary)
);
background: -webkit-linear-gradient(
top,
$color-background-primary 0%,
rgb(237, 237, 237) 50%,
$color-background-primary 100%
);
background: -o-linear-gradient(
top,
$color-background-primary 0%,
rgb(237, 237, 237) 50%,
$color-background-primary 100%
);
background: linear-gradient(
to bottom,
$color-background-primary 0%,
rgb(237, 237, 237) 50%,
$color-background-primary 100%
);
color: black;
padding: 10px;
& > * {
color: black;
}
& > ul {
list-style: none;
display: -ms-grid;
display: grid;
-ms-grid-columns: 25% auto;
grid-template-columns: 25% auto;
}
}
Logo:
.thematic-area-nav__logo {
-ms-grid-column: 1;
-ms-grid-column-span: 1;
grid-column: 1/2;
-ms-flex-item-align: center;
-ms-grid-row-align: center;
align-self: center;
width: 100%;
height: 150%;
}
Buttons:
.thematic-area-nav__areas {
-ms-grid-column: 2;
-ms-grid-column-span: 1;
grid-column: 2/3;
display: -ms-grid;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(12vw, 16vw));
grid-gap: 0.5em;
& > button {
border-top: none;
border-bottom: none;
border-right: 1px solid rgb(218, 218, 218);
border-left: 1px solid rgb(218, 218, 218);
border-radius: 5px;
-webkit-box-shadow: 1px 1px 1px;
box-shadow: 1px 1px 1px;
background-color: $color-background-primary;
font-size: 1vw;
&:hover {
color: black;
-webkit-box-shadow: inset 1px 1px 1px;
box-shadow: inset 1px 1px 1px;
font-weight: bold;
}
&:focus {
outline: none;
-webkit-box-shadow: inset 1px 1px 1px;
box-shadow: inset 1px 1px 1px;
font-weight: bold;
}
}
}
.thematic-area-nav__singleThematicArea {
& a {
text-decoration: none;
color: black;
}
& > * {
text-decoration: none;
cursor: pointer;
color: black;
}
}
Is that a CSS problem indeed?
I looked into the html/scss code from jsbin, did some cleanup and managed to achieve something I think is close to what you had in mind.
Some notes:
Avoid using vw and vh for font sizes unless there is a really good reason not to do so.
If specifying width/height in % always figure out how the browser calculates those (ask yourself "percentage of what?").
Use https://validator.w3.org/ - it helps.
Avoid mixing camelCase and-this__thingy.
Keep your code tidy.
HTML
<div class="thematic-area-nav">
<div class="thematic-area-nav__logo-wrapper">
<img class="thematic-area-nav__logo" src="https://picsum.photos/200/90" alt="Logo Coaching People">
</div>
<ul class="thematic-area-nav__areas">
<li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 1">Obszar tematyczny 1</a></li>
<li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 2">Obszar tematyczny 2</a></li>
<li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 3">Obszar tematyczny 3</a></li>
<li class="thematic-area-nav__singleThematicArea"><a class="Obszar tematyczny 4">Obszar tematyczny 4</a></li>
</ul>
</div>
SCSS
.thematic-area-nav {
position: sticky;
padding: 5px;
border-radius: 0;
margin: 0 0 20px;
top: 0;
right: 0;
left: 0;
z-index: 2;
font-size: 16px;
box-shadow: 0 0 25px 1px #000000;
border-radius: 0 0 5px 5px;
background: -webkit-gradient(
linear,
left top,
left bottom,
from($color-background-primary),
color-stop(50%, rgb(237, 237, 237)),
to($color-background-primary)
);
color: black;
padding: 10px;
display: flex;
flex-direction: row;
justify-content: space-between;
#media (max-width: 420px) {
display: block;
}
}
.thematic-area-nav__logo-wrapper {
#media (max-width: 420px) {
text-align: center;
margin-bottom: .6em;
}
}
.thematic-area-nav__areas {
list-style: none;
margin: 0;
padding: 0 0 0 8px;
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-around;
flex: 1;
}
.thematic-area-nav__singleThematicArea {
padding: .6em 1em;
margin-bottom: .6em;
text-decoration: none;
color: black;
border-top: none;
border-bottom: none;
border-right: 1px solid rgb(218, 218, 218);
border-left: 1px solid rgb(218, 218, 218);
border-radius: 5px;
box-shadow: 1px 1px 1px;
background-color: $color-background-primary;
&:hover {
color: black;
box-shadow: inset 1px 1px 1px;
}
&:focus {
outline: none;
box-shadow: inset 1px 1px 1px;
}
}
It’s quite unlikely that react code is causing the problem. Could you copy the html that is created by your react application, the css code and create a test case with just those? It would be good to establish if the problem appears when your JS is not “enabled”. How do you feel about sharing a link to your repo?
Some side notes: putting a link inside a button does not seem right. It will most definitely fail any accessibility evaluation, also class="Obszar tematyczny 3” value doesn’t seem right, ul element should only have li as children, placing anything else inside it is, well, WRONG.
There is also quite a lot of flex box weirdness in your styles. By reading it I’m not really able to grasp your intentions. I think that you’re not fully familiar with flexbox properties that belong to flex container and those that belong to its children.
In addition to that, you could stop using * selector. Just stop. World will be a better place if you do.
Related
I am playing with CSS pseudo elements. As soon as the menu button gets hovered it receives a small orange underline. This element should stay as soon as the dropdown-container is visible. Is there a light weight solution to achieve such behaviors?
In case pseudo elements aren´t the best solution for my need, I am open minded for different solutions.
https://jsfiddle.net/j3g49fwd/
$(".dropdown-btn").click(function() {
this.classList.toggle("increase")
$(".dropdown-container").toggle()
})
.wrapper {
position: relative;
top: 5vh;
margin: 40px 30px 30px 30px;
height: fit-content;
background: white;
border-radius: 10px;
box-shadow: -10px -10px 10px rgba(255, 255, 255, 0.5),
15px 15px 15px rgba(70, 70, 70, 0.12);
padding: 1vw;
}
.dropdown-btn {
display: flex;
justify-content: center;
padding: 10px 0px 10px 20px;
text-decoration: none;
display: block;
border: 1px solid transparent;
background: none;
height: fit-content;
min-height: 5vh;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
transition: all 0.3s ease-in-out;
}
.dropdown-btn:after {
content: "";
display: block;
margin: 3px 0 0 0;
width: 0;
height: 1px;
background: rgb(242, 123, 57);
transition: all 0.4s;
}
.dropdown-btn:hover::after {
width: 100%;
}
.dropdown-container {
display: none;
padding: 10px 20px 10px 20px;
margin: 0 0 2vh 0;
}
.increase {
font-size: 20px !important;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class="wrapper">
<button class="dropdown-btn">I am a menu button
<label class="menu-title" id="flow-menu-title"></label>
<i class="fa-solid fa-gear col-1 dropdown-icon"></i>
</button>
<div class="dropdown-container">
Hello Stackoverflow
</div>
</div>
</body>
</html>
if I understand you correctly, you should be able to edit the CSS just like this:
.dropdown-btn.increase::after,.dropdown-btn:hover::after {
width: 100%;
}
https://jsfiddle.net/bkefg9dt/
Here's what i want to accomplish:
As you can see, there's a small border at the bottom, i've tried to add border-bottom: 1px solid #c1ad6f but it results to:
Border is not fully filled cause of radius.
.btn {
background: #d5c289;
border-bottom: 6px solid #c1ad6f;
font-weight: 500;
font-size: 1.125rem;
padding: 1.25rem;
border-radius: 4px;
}
<a class="btn" href="#form" role="button">Enroll</a>
You may consider box-shadow instead of border to achieve this in a better way:
.box {
display: inline-block;
margin: 10px;
height: 100px;
width: 200px;
background: #d5c289;
box-sizing:border-box;
border-radius: 0 0 20px 20px;
}
.shadow {
box-shadow: 0 -10px 0 0 #c1ad6f inset;
animation: anime 2s infinite linear alternate;
}
.border {
border-bottom: 10px solid #c1ad6f;
animation: anime-alt 2s infinite linear alternate;
}
#keyframes anime {
from {box-shadow: 0 -1px 0 0 #c1ad6f inset;}
to {box-shadow: 0 -30px 0 0 #c1ad6f inset;}}
#keyframes anime-alt {
from {border-bottom: 1px solid #c1ad6f;}
to {border-bottom: 30px solid #c1ad6f;}}
<div class="box shadow">
Good one with box-shadow
</div>
<div class="box border">
Not good with border
</div>
This is simple trick to make border rounded using box-shadow. it will
exactly giving the output what you want.
.btn-bordered {
background: #17aa56;
color: #fff;
border-radius: 15px;
box-shadow: 0 10px #119e4d;
padding: 25px 60px 25px 90px;
}
.btn-block {
border: none;
font-family: inherit;
font-size: inherit;
color: inherit;
background: #ddd;
cursor: pointer;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
text-transform: Capitialize;
letter-spacing: 1px;
font-weight: 700;
position: relative;
overflow:hidden;
}
<button class="btn-bordered btn-block" type="button">Bottom Rounded Button</button>
#AlexanderKim, you could increase border-bottom. like this: border-bottom: 5px solid #c1ad6f;. I made this fiddle: jsfiddle.net/bektkdnz but increased padding so it was easier to see
I'm creating a submenu for my website but it needs some little fixes.
First, I can't make the z-index work, is displayed under the content div, in the live example I removed all z-index, and righ now, I really have no idea how this works :(
Second, in the submenu from second option, the box is more large than the first one. I'm trying to fix it but I don't see where the problem is.
/* Sub-menu */
#main-nav ul {
list-style: none;
margin: 0;
padding: 0;
display: none;
position: absolute;
/* rounded corner */
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
#main-nav ul li {
float: none;
display: block;
/* box shadow */
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 1px 1px rgba(0, 0, 0, .4);
-moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 1px 1px rgba(0, 0, 0, .4);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3), 0 1px 1px rgba(0, 0, 0, .4);
/* rounded corner */
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
}
#main-nav ul li:last-child {
box-shadow: none;
}
#main-nav ul a {
color: #fff;
background: #474747;
display: block;
white-space: nowrap;
}
#main-nav ul a:hover {
/* gradient */
background: #6a6a6a url(images/nav-bar-bg.png) repeat-x;
background: -webkit-gradient(linear, left top, left bottom, from(#b9b9b9), to(#6a6a6a));
background: -moz-linear-gradient(top, #b9b9b9, #6a6a6a);
background: linear-gradient(-90deg, #b9b9b9, #6a6a6a);
background-image: linear-gradient(-90deg, #cdcdcd, #797979);
}
#main-nav ul li:first-child a {
/* rounded corner */
-webkit-border-radius: 8px 8px 0 0;
-moz-border-radius: 8px 8px 0 0;
border-radius: 8px 8px 0 0;
}
#main-nav ul li:last-child a {
/* rounded corner */
-webkit-border-radius: 0 0 8px 8px;
-moz-border-radius: 0 0 8px 8px;
border-radius: 0 0 8px 8px;
}
#main-nav ul li:first-child a:after {
content:'';
position: absolute;
left: 30px;
top: -8px;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 8px solid #444;
}
#menu ul li:first-child a:hover:after {
border-bottom-color: #fafafa;
}
#main-nav:after {
visibility: hidden;
display: block;
font-size: 0;
content:" ";
clear: both;
height: 0;
}
Here's a live example: http://jsfiddle.net/y59kjsLn/1/
Thanks in advance!
Edit: add more css
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
.clearfix { display: block; zoom: 1; }
Chan this cause the z-index problem?
Edit2: Add the html code
Hmmm maybe has something to do with...
<div id="content">
<article class="post clearfix">
<?php
if(array_key_exists($matches[1], $includes)) {
$content = include($includes[$matches[1]]);
} else header("Location: /home");
?>
</article>
</div>
This is just behind the menu.
#content CSS code:
#content {
opacity: 0.8;
background: #fff;
margin: 30px 0 30px;
padding: 20px 35px;
width: 600px;
float: left;
/* rounded corner */
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
/* box shadow */
-webkit-box-shadow: 0 1px 3px rgba(0,0,0,.4);
-moz-box-shadow: 0 1px 3px rgba(0,0,0,.4);
box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
#content .error {
color: red;
text-align: center;
}
#content .note {
font-size: 80%;
text-align: center;
}
#content p {
margin-top: 30px;
}
h2.post-title {
margin-top: 15px;
background: #888;
border-radius: 5px;
padding: 0px 5px ;
border-top: 1px solid #889;
border-bottom: 1px solid #889;
text-align: center;
}
h2.post-title a {
color: #FFFFFF;
font-size: 0.9em;
text-shadow: 1px 1px 2px #333333;
}
.post {
margin-bottom: 20px;
}
.post-title {
margin: 0 0 5px;
padding: 0;
font: bold 26px/120% Arial, Helvetica, sans-serif;
}
.post-title a {
text-decoration: none;
color: #000;
}
.post-meta {
margin: 0 0 10px;
font-size: 90%;
}
figure.post-imagen img {
float: left;
margin: 5px;
max-width: 260px;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
.clearfix { display: inline-block; }
.clearfix { display: block; zoom: 1; }
Js Fiddle
removed the margin which was affecting the sub menu
#main-nav li:first-child {
margin-left: 10px;
}
edit
Remove and Add
#content
opacity: 0.8; /* removed */
background: rgba(255, 255, 255, 0.55); /* added */
}
I am facing a small problem in time to align my divs inside a <li>. I would like to vertically align my div (which has a picture inside), in a way that no matter the height of my <li>, it will always be in the middle. NO USE WITH MARGIN-TOP PERCENTAGE (%). Already used the display table but did not work for my case.
Here the picture of how I would like to stay:
How is increased when the height of my <li>.
The image is not in the middle of <li>. ^
If anyone can help me, this here my file fiddle. Remember without using margin :). In my case I am temporarily using the file fiddle.
http://jsfiddle.net/Igaojsfiddle/T6KrE/37/
#frdImgProfile {
width: 50px;
height: 50px;
border: 1px solid #aaa;
background: #ffe;
position:absolute;
margin-top:3px;
margin-left:4px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
}
Thank you!
Well... We'll go for parts:
First: You don't have to abuse with the id attributes.
Second: In your CSS code, you have a lot of rules that reference to same id. This is not a good practice. It supposed that the id is unique.
Third: I've seen that you have a div called: div#avatarUser. I guess that you created this for setting special style. Well you don't need to do this. With parent:first-child or parent:nth-child(1) you can set specific styles for the first element:
E.g.:
<ul>
<li></li> <!-- I want to set specific styles for this element. The first element -->
<li></li>
<li></li>
</ul>
So, for do that just in my CSS file, I'll put:
ul > li:nth-child(1) { /* Your CSS code */ }
Well, now we deep in your problem.
I changed a little your HTML code, because I think it's more organized and clean code:
<div class="frdList">
<ul class="contactList">
<li>Friends :)</li>
<li class="p-flexbox flex-hsc">
<img src="http://w2.vanillicon.com/2c85954e3b080d9926c53b530ca40317_50.png" />
</li>
<li class="p-flexbox flex-hsc">
<img src="http://w6.vanillicon.com/6cd18e7a56ebd6fb1f3f607823b7d5fe_50.png" />
</li>
<li class="p-flexbox flex-hsc">
<img src="http://wc.vanillicon.com/cd7c7d1f9a0c56ff3b8296527a98564f_50.png" />
</li>
<li class="p-flexbox flex-hsc">
<img src="http://vanillicon.com/0fff488a9952086c6785f260e2c127ad_50.png" />
</li>
</ul>
</div>
And also changed the CSS file:
/* Reset CSS */
body, div {
margin: 0;
padding: 0;
}
li { list-style: none; }
/* #font-faces imports */
#font-face {
font-family:'Amatic SC';
font-style: normal;
font-weight: 400;
src: local('Amatic SC Regular'), local('AmaticSC-Regular'), url(http://themes.googleusercontent.com/static/fonts/amaticsc/v3/DPPfSFKxRTXvae2bKDzp5D8E0i7KZn-EPnyo3HZu7kw.woff) format('woff');
}
/* Basic styles */
.frdList {
height:500px;
width:500px;
}
.contactList > li:nth-child(1) {
font-weight: bold;
font-family: 'Amatic SC', cursive;
font-size: 45px;
text-align: center;
color: #fff;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4);
background-image: -webkit-linear-gradient(#2da1ec, #0191d9);
background-image: -moz-linear-gradient(#2da1ec, #0191d9);
background-image: -ms-linear-gradient(#2da1ec, #0191d9);
background-image: linear-gradient(#2da1ec, #0191d9);
border: 1px solid #0082c3;
border-bottom: 1px solid #077be0;
position: relative;
height:55px;
}
.contactList > li:nth-child(1):hover {
background-image: -webkit-linear-gradient(#2eacff, #0191d9);
background-image: -moz-linear-gradient(#2eacff, #0191d9);
background-image: -ms-linear-gradient(#2eacff, #0191d9);
background-image: linear-gradient(#2eacff, #0191d9);
}
.contactList > li:nth-child(1):after {
content: url("http://images1.wikia.nocookie.net/knd/images/3/3a/PR2.gif");
text-align: center;
width: 68px;
height: 65px;
background: #8dfd07;
display: inline-block;
position: absolute;
top: -10px;
left: 15px;
border-radius: 5px;
border: solid 1px #aaa;
}
.contactList > li:nth-child(1):before {
content: "";
position: absolute;
border-radius: 6px;
width: 78px;
height: 75px;
background-color: white;
line-height: 70px;
/* Well see */
text-align: center;
border: solid 1px #aaa;
top: -15px;
left: 10px;
}
.contactList > li {
font-weight: bold;
color: #fff;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 2px -2px gray;
background-image: -webkit-linear-gradient(#ededed, #eff0f2);
background-image: -moz-linear-gradient(#ededed, #eff0f2);
background-image: -ms-linear-gradient(#ededed, #eff0f2);
background-image: linear-gradient(#ededed, #eff0f2);
border-left: 10px solid green;
border-right: 1px solid #999999;
height:120px;
}
.p-flexbox {
/* Flexbox: Init setup */
display: -webkit-box;
display: -moz-box;
display: box;
}
.flex-hsc {
/* Flexbox: Principal setup */
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
box-orient: horizontal;
-webkit-box-pack: start;
-moz-box-pack: start;
box-pack: start;
-webkit-box-align: center;
-moz-box-align: center;
box-align: center;
}
To center the images I used Flexible Box Model or Flexbox.
But I think... Why to complicate? If you know the height of the container of the image, use line-height
In the development area exists a principle called KIS. It means:
Keep It Simple.
If you have the solution (and a good solution), use it! This will avoid headaches.
Here's a DEMO.
Try to change the height of the li elements in the demo and you will see that the images will always be center.
Cheers,
Leonardo
If you won't use margin, try with line-height on li and .frdImgProfile
Change #frdImgProfile to .frdImgProfile and on your html change id=frdImgProfile to class=frdImgProfile,
Remove margin-top on .frdImgProfile
Add line-height: 120px; to #contactList > li
Add display: inline-block; vertical-align: middle;line-height: normal; to .frdImgProfile
#contactList > li {
font-weight: bold;
color: #fff;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 2px -2px gray;
background-image: -webkit-linear-gradient(#ededed, #eff0f2);
background-image: -moz-linear-gradient(#ededed, #eff0f2);
background-image: -ms-linear-gradient(#ededed, #eff0f2);
background-image: linear-gradient(#ededed, #eff0f2);
border-left:10px solid green;
border-right:1px solid #999999;
height:120px;
line-height: 120px;
}
.frdImgProfile {
width: 50px;
height: 50px;
border: 1px solid #aaa;
background: #ffe;
margin-left:4px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
display: inline-block;
vertical-align: middle;
line-height: normal;
}
demo on cssdeck
Hope this help
can add .. add you complete classes. ++
#contactList > li {
position:relative;
}
#frdImgProfile {
width: 50px;
height: 50px;
position:absolute;
margin-top:-25px;
top:50%;
}
I asked a question of creating a speech bubble in CSS and change the layout of the bubble based on the size of the screen in this thread. I got some hint by using the flexbox to determine the bubble arrow direction and layout. I used the CSS class to change the arrow orientation as shown in the thread. And int the following script, I use the natural item order to automatically layout the bubble. I assume the main tag only contains an image tag and a div (for speech bubble).
If the image tag is in front of div, we layout the image logo on the left and followed by a speech bubble on the right with an arrow pointing to the left.
If the image tag is behind the div, we layout the image logo on the right and with a speech bubble inserted in front of it with an arrow pointing to the right.
But in the case when the screen size is less than 600px, to avoid a slim speech bubble, I will rearrange the image and bubble vertically and with image shown on the top always. Here is the code
.speech {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
flex-direction: row;
}
.speech img:first-child{
order: 0;
margin: 10px;
border: 3px solid #00CCFF;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 30px;
}
.speech img:last-child{
order: 0;
margin: 10px;
border: 3px solid #00FF99;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-left: 30px;
}
.sp {
background: #efefef;
-webkit-border-radius: 4px;
border-radius: 4px;
font-size: 1.2rem;
line-height: 1.3;
max-width: 95%;
padding: 15px;
position: relative;
left:0px;
top: 20px;
filter: drop-shadow(6px 4px 0px rgba(0, 0, 0, 0.2));
border: 1px solid black;
}
div.sp:last-child::after {
border-left: 11px solid transparent;
border-right: 11px solid #efefef;
border-top: 11px solid #efefef;
border-bottom: 11px solid transparent;
content: "";
position: absolute;
left: -20px;
top: 8px;
filter: drop-shadow(-2px -1px 0px black);
order: 0;
}
div.sp:first-child::after {
content: "";
position: absolute;
border-left: 11px solid #efefef;
border-right: 11px solid transparent;
border-top: 11px solid #efefef;
border-bottom: 11px solid transparent;
right: -20px;
top: 8px;
filter: drop-shadow(2px -1px 0px black);
order: 0;
}
#media only screen and (max-width: 600px) {
.speech {
display: flex;
flex-wrap: nonwrap;
flex-direction: column;
background: #00cc00;
}
.speech img:first-child{
margin: 10px;
border: 3px solid green;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 30px;
order: -1;
}
div.sp:last-child::after {
content: '';
position: absolute;
top:-19px;
left: 11px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 0px solid transparent;
border-top: 0px solid transparent;
border-bottom: 20px solid #efefef;
filter: drop-shadow(1px -2px 0px black);
order: 0;
}
.speech:nth-of-type(2n) {
align-items: flex-end;
}
div.sp:first-child::after {
content: '';
position: absolute;
top:-29px;
left: 84%;;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 0px solid transparent;
border-top: 0px solid transparent;
border-bottom: 20px solid red;
filter: drop-shadow(1px -2px 0px black);
order: 0;
}
.speech img:last-child{
margin: 10px;
border: 3px solid blue;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 0px;
right: 0px;
order: -1;
}
}
<main class="speech">
<img src="https://www.quackit.com/pix/samples/6m.jpg" alt="Sample photo">
<div class="sp">this is my example 1 <div>additional line</div></div>
</main>
</br></br></br>
<main class="speech">
<div class="sp">this is my example 2 <div>additionl line</div></div>
<img src="https://www.quackit.com/pix/samples/6m.jpg" alt="Sample photo">
</main>
Assuming all items on the flexbox container is of order ZERO. I use the natural order to determine the orientation of the bubble arrow, there you will see first-child and last-child to do the work. But when the screen size shrunk, I add order: -1; to move the image as the first item. But with that, I encounter two issues
1) I assume the second example should have the image aligned to the right and with a bubble below it. However, no matter how I align it, they always align to the left. (This issue is partially fixed after applying Brett's comment .speech:nth-of-type(2n) { align-items: flex-end; }, but the items in the case of flex-direction: row; still won't align all the way to the right)
2) In the second example, I assume the bubble should have the arrow moved to the top-right corner but it is still on the right side. And this issue seems to be caused by the order (I can tell it does not use the code within the #media after I change the order). (This issue is fixed about removing the html comment)
Please run the code, make it full screen and shrink the screen size to see the effect.
.speech {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
flex-direction: row;
}
.speech img:first-child{
order: 0;
margin: 10px;
border: 3px solid #00CCFF;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 30px;
}
.speech img:last-child{
order: 0;
margin: 10px;
border: 3px solid #00FF99;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-left: 30px;
}
.sp {
background: #efefef;
-webkit-border-radius: 4px;
border-radius: 4px;
font-size: 1.2rem;
line-height: 1.3;
max-width: 95%;
padding: 15px;
position: relative;
left:0px;
top: 20px;
filter: drop-shadow(6px 4px 0px rgba(0, 0, 0, 0.2));
border: 1px solid black;
}
div.sp:last-child::after {
border-left: 11px solid transparent;
border-right: 11px solid #efefef;
border-top: 11px solid #efefef;
border-bottom: 11px solid transparent;
content: "";
position: absolute;
left: -20px;
top: 8px;
filter: drop-shadow(-2px -1px 0px black);
order: 0;
}
div.sp:first-child::after {
content: "";
position: absolute;
border-left: 11px solid #efefef;
border-right: 11px solid transparent;
border-top: 11px solid #efefef;
border-bottom: 11px solid transparent;
right: -20px;
top: 8px;
filter: drop-shadow(2px -1px 0px black);
order: 0;
}
#media only screen and (max-width: 600px) {
.speech {
display: flex;
flex-wrap: nonwrap;
flex-direction: column;
background: #00cc00;
}
.speech:nth-of-type(2n) {
align-items: flex-end;
}
<!-- LOGO SPEECH -->
.speech img:first-child{
margin: 10px;
border: 3px solid green;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 30px;
order: -1;
}
div.sp:last-child::after {
content: '';
position: absolute;
top:-19px;
left: 11px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 0px solid transparent;
border-top: 0px solid transparent;
border-bottom: 20px solid #efefef;
filter: drop-shadow(1px -2px 0px black);
order: 0;
}
<!-- SPEECH LOGO -->
div.sp:first-child::after {
content: '';
position: absolute;
top:-29px;
left: 84%;;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 0px solid transparent;
border-top: 0px solid transparent;
border-bottom: 20px solid red;
filter: drop-shadow(1px -2px 0px black);
order: 0;
}
.speech img:last-child{
margin: 10px;
border: 3px solid blue;
box-shadow: 3px 3px 8px 0px rgba(0,0,0,0.3);
max-width: 25vw;
margin-right: 0px;
right: 0px;
order: -1;
}
}
<main class="speech">
<img src="https://www.quackit.com/pix/samples/6m.jpg" alt="Sample photo">
<div class="sp">this is my example 1 <div>additional line</div></div>
</main>
</br></br></br>
<main class="speech">
<div class="sp">this is my example 2 <div>additionl line</div></div>
<img src="https://www.quackit.com/pix/samples/6m.jpg" alt="Sample photo">
</main>
I added .speech:nth-of-type(2n) { align-items: flex-end; } to your media query.
This will make every even numbered speech element move to the end. When you change the flex direction to column, align and justify flip roles. You might need to tweak some styles, but I believe this answers your question.