Div color background error - html

the issue I am having is that when I change my browser size to tablet and mobile my quotes and testimonials named Jerry and Michelle go outside of the color background which makes me think that they aren't nested correctly. However, I looked at it and I believe it should work but somehow it isn't. The easiest way to see this since I just isolated this code and my whole site isn't pushing it out of the background colored box, is if you make the code snippet full-sized and put the browser to the smallest width. You will see the quotes outside of the colored box. If anyone could spot the issue and let me know it would be greatly appreciated! Thank you!
#colorbk{
background-color: #1DA0A3;
}
.container {
display: flex;
background-color: #1DA0A3;
flex-flow: row wrap;
max-width:1700px;
margin: 0 auto;
}
#qwrapper {
display: flex;
height: 100%;
width: 100%;
align-items:center;
justify-content:center;
margin:10px;
background-color:#1DA0A3;
}
.row {
flex: 0 auto;
height: 100px;
margin:0;
}
#lighticon{
padding-bottom:30px;
}
#jerry{
width:400px;
}
#michelle{
width:400px;
}
.italic{
font-style:italic;
}
.right{
float:right;
}
#media (max-width: 800px) {
#qwrapper {
flex-direction: column;
align-items: center;
}
}
#media screen and (max-width:480px) {
#qwrapper {
flex-wrap: wrap;
}
.row {
}
}
#media only screen and (min-width: 760px) {
#qwrapper{
justify-content: space-around;
margin:10px;
}
}
<div id="colorbk">
<div class="container">
<div id="qwrapper">
<h3 id="michelle" class="row" ><div class="italic">"She always thinks of her clients."</div>
<br>
<div class="right" id="connect">-Michelle Houle Conn. FSE</div>
</h3>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png" class="row" alt="" id="lighticon"/>
<h3 id="jerry" class="row"><div class="italic">"Very smart, creative person, problem solver."</div>
<br>
<div class="right">-Jerry Nygard C2P</div>
</h3>
</div>
</div>
</div>

You can simply solve the issue by removing width:400px from inner texts:
#jerry{
/*width:400px;*/
}
#michelle{
/*width:400px;*/
}
as in following snippet:
#colorbk{
background-color: #1DA0A3;
}
.container {
display: flex;
background-color: #1DA0A3;
flex-flow: row wrap;
max-width:1700px;
margin: 0 auto;
}
#qwrapper {
display: flex;
height: 100%;
width: 100%;
align-items:center;
justify-content:center;
margin:10px;
background-color:#1DA0A3;
}
.row {
flex: 0 auto;
height: 100px;
margin:0;
}
#lighticon{
padding-bottom:30px;
}
#jerry{
/*width:400px;*/
}
#michelle{
/*width:400px;*/
}
.italic{
font-style:italic;
}
.right{
float:right;
}
#media (max-width: 800px) {
#qwrapper {
flex-direction: column;
align-items: center;
}
}
#media screen and (max-width:480px) {
#qwrapper {
flex-wrap: wrap;
}
.row {
}
}
#media only screen and (min-width: 760px) {
#qwrapper{
justify-content: space-around;
margin:10px;
}
}
<div id="colorbk">
<div class="container">
<div id="qwrapper">
<h3 id="michelle" class="row" ><div class="italic">"She always thinks of her clients."</div>
<br>
<div class="right" id="connect">-Michelle Houle Conn. FSE</div>
</h3>
<img src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png" class="row" alt="" id="lighticon"/>
<h3 id="jerry" class="row"><div class="italic">"Very smart, creative person, problem solver."</div>
<br>
<div class="right">-Jerry Nygard C2P</div>
</h3>
</div>
</div>
</div>
Edit:
for your jsFiddle, i modify it as following:
jsfiddle.net/81d8trag/2
remove height:100px from .row class. also as the last icon has set its size with that row class, i add width:100px to it in #lighticon css:
.row {
flex: 0 auto;
/*height: 100px;*/
margin:0;
}
#lighticon{
width:100px;
padding-bottom:30px;
}

that's because you are fixing the width of
#jerry {
width: 400px;
}
#michelle {
width: 400px;
}
to 400px, so no matter how large or small your screen size is, it is fixed to 400px. if you want to make it responsive you have to use %.

Related

Arrange Flex-Items

Let's say I have a Flex-Box #X in which i want to arrange 4 Flex-Items #Y1 ... #Y4 as follows:
For an output medium smaller than 60em the flex-items should be positioned like this:
I know what i have to do for the HTML part, but what do i have to do for the css part?
You mean like this? The example works with media query and flex-direction: column-reverse;.
.flex {
display: flex;
background: gray;
justify-content: space-between;
gap:10px;
flex-wrap: wrap;
padding:10px;
max-width: 900px;
}
.item {
margin: 0 auto;
width:100%;
max-width:400px;
background-color: lightgreen;
height:100px;
}
#media only screen and (max-width: 800px) {
.flex {
flex-direction: column-reverse;
}
}
<div class="flex">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>

Flip two horizontal tiles to vertical on mobile using CSS

I am new to responsive styling and couldnt find a solution to my problem elsewhere:
I have two horizontally aligned tiles on Desktop viewport. One is a div that contains text, the other is an image.
My code for this:
.tile-image{
width: 70%;
}
.tile-text{
width: 30%;
background-color: #d9b886;
color: white !important;
font-size: 2vh;
display: table;
word-wrap: break-word;
white-space: normal;
}
.tile-text-inner{
display: table-cell;
vertical-align: middle;
padding: 20px;
}
.container{
display: flex;
flex-direction: row;
}
<div class="container">
<div class="tile-text">
<div class="tile-text-inner">
TEXT
</div>
</div>
<div class="tile-image">
<img src="https://test-shop.tt-gmbh.de/media/a9/b8/4c/1638172501/13811-AdobeStock_294559939_New-Africa.jpg">
</div>
</div>
On mobile viewport I want to display both tiles vertically with the image on top and the text tile below. Like in the image below:
How can I achieve this?
You can use media queries
#media screen and (max-width: 600px) {
.container {
flex-direction: column-reverse;
}
.tile-text{width: 100vw}
}
.tile-image{
width: 70%;
}
.tile-text{
width: 30%;
background-color: #d9b886;
color: white !important;
font-size: 2vh;
display: table;
word-wrap: break-word;
white-space: normal;
}
.tile-text-inner{
display: table-cell;
vertical-align: middle;
padding: 20px;
}
.container{
display: flex;
flex-direction: row;
}
#media screen and (max-width: 600px) {
.container {
flex-direction: column-reverse;
}
.tile-text{width: 100vw}
}
<div class="container">
<div class="tile-text">
<div class="tile-text-inner">
TEXT
</div>
</div>
<div class="tile-image">
<img src="https://test-shop.tt-gmbh.de/media/a9/b8/4c/1638172501/13811-AdobeStock_294559939_New-Africa.jpg">
</div>
</div>
In comments they were saying truth you have to use flex-direction: column but it won't work because what you had written css isn't responsive friendly code so I re-created new one, use media-queries for responsive, and please avoid using a lot div wrapping it makes lots of complexity
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
position: relative;
width: 100%;
height: 100vh;
}
.container img {
width: 100%;
height: 100%;
position: absolute;
}
.container .tile-text{
display: flex;
justify-content: center;
align-items: center;
width: 30%;
z-index: 9;
height: 100%;
background: #d9b886;
}
.container .tile-text .tile-text-inner{
color: #FFF;
}
#media screen and (max-width: 761px){
.container{
flex-direction: column-reverse;
}
.container .tile-text{
width: 100%;
height: 30%;
}
}
<div class="container">
<div class="tile-text">
<div class="tile-text-inner">
Marry Christmas
</div>
</div>
<img src="https://test-shop.tt-gmbh.de/media/a9/b8/4c/1638172501/13811-AdobeStock_294559939_New-Africa.jpg">
</div>

div not positioning on mobile correctly

My div class info-container doesn't seem to be positioned proper on mobile. Code seems ok, so not sure what the problem is. I want the class info-container underneath the logo in mobile only. However the code isn't seem to be making effect.
I am fairly new to html/css
.topSection {
display: flex;
justify-content: space-between;
}
.info-container {
display: flex;
flex-direction: column;
}
.info {
display: flex;
align-items: center;
}
.info img {
margin-right: 8px;
}
#media only screen and (max-width: 600px) {
.info-container {
position: relative;
top:12px;
left:5px;
}
}
<div class="topSection">
<div class="logo">
<a href="http://www.elegantcurtainsandblinds.co.uk/index.php"><img
src="http://www.elegantcurtainsandblinds.co.uk/images/eg_logo_new.png"
alt="Logo"></a>
</div>
<div class="info-container">
<div class="info">
<img src="http://elegantcurtainsandblinds.co.uk/images/mobile.png" height="30px" width="30px;" />
<a style="text-decoration:none;color:#2B8C1A;" href="tel:01924724848">Call Us: 01924 724848</a>
</div><br>
<div class="info">
<img src="http://elegantcurtainsandblinds.co.uk/images/images.png" height="30px" width="30px;">
<p style="color:#2B8C1A">Visit Our Showroom</p>
</div><br>
<div class="info">
<img src="http://elegantcurtainsandblinds.co.uk/images/video.png" height="30px" width="30px; target="_blank"">
<p style="color:#2B8C1A">Watch Our Video</p>
</div>
</div>
</div>
Add in media query this css
#media only screen and (max-width: 600px){
.topSection {
display: unset;
}
}
Add display:block; to parent class on mobile
http://prntscr.com/kdq5tq
It was not showing properly because of flex property, try adding below css.
#media only screen and (max-width: 600px) {
.topSection {
display:block;
}
}
#media only screen and (max-width: 600px) {
.info-container {
position: relative;
top:12px;
left:5px;
}
.topSection {
display: flex;
justify-content: space-between;
flex-direction: column;
}
}
Please check this code it working .
add below css code for mobile layout
#media only screen and (max-width: 600px){
.topSection {
display: block;
justify-content: space-between;
clear: both;
overflow: hidden;
}
.info-container {
position: relative;
top: -28px;
left: 0;
display: inline-block;
width: 100%;
float: left;
clear: both;
}
.info {
float: left;
width: 33%;
}
}

Using Flexbox/Grid in CSS, making images stack on mobile

I'm trying to master the grid layout in CSS3. I want to write some HTML/CSS that enable the my 3x1 grid to stack when viewed on mobile. For now, the squares just keep shrinking until they're small. I've been able to work with mobile CSS before, but working with grids are new to me. Can anyone offer some pointers or suggestions?
Here's my code:
HTML:
<div class="container">
<div class="grid">
<div class="cell">
<img src="https://www.easycalculation.com/area/images/big-square.gif">
</div>
<div class="cell">
<img src="https://www.easycalculation.com/area/images/big-square.gif">
</div>
<div class="cell">
<img src="https://www.easycalculation.com/area/images/big-square.gif">
</div>
</div>
CSS:
.container {
width: 100%;
margin: 0 auto;
}
.grid {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.cell {
flex: 0 0 32%;
margin-bottom: 5px;
}
img {
max-width: 100%;
height: auto;
}
body {
background-color: #dedede;
}
Here's a CodePen link as well: https://codepen.io/anfperez/pen/QrEBLZ
Try this CSS:
(codepen https://codepen.io/bonniemellott/pen/ELypzm)
.container {
width: 100%;
margin: 0 auto;
}
.grid {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.cell {
//removed flex attribute
margin-bottom: 5px;
}
img {
max-width: 100%;
height: auto;
}
body {
background-color: #dedede;
}
Add this to your css
You will have to use media query for stacking the boxes.
The way u can do this is by setting the flex-direction:column on smaller devices
#media (max-width: 768px) { /*You can decrese this number if you want only on small devices*/
.grid {
flex-direction: column;
}
}
Here is the updated codepen link

Div's stack on top of each other, just not in right order

I have a couple divs, placed side by side and using a media query to stack them, which they do stack but I need the yellow one to be on top and the blue below it. So opposite of what you see when the script is ran and not sure on how to do it.
#wrapper {
width:1000px;
}
#mydivLeft {
background:blue;
height:250px;
width:50%;
float:left;
}
#mydivRight {
background:yellow;
height:250px;
width:50%;
float:right;
}
#media only screen and (max-width:768px){
#wrapper {
width:100%;
}
#mydivRight, #mydivLeft {
display:block;
float:none;
width:100%;
}
}
<body>
<div id="wrapper">
<div id="mydivLeft">
</div>
<div id="mydivRight">
</div>
</div>
</body>
you can use flexbox using order to reverse the order of how the elements are stacked
#wrapper {
width: 1000px;
max-width: 100%;
display: flex;
flex-wrap: wrap;
height: 250px;
}
#wrapper div {
flex: 1;
}
#mydivLeft {
background: blue;
}
#mydivRight {
background: yellow;
}
#media only screen and (max-width: 768px) {
#wrapper div {
flex: 0 100%
}
#mydivRight {
order: -1
}
}
<body>
<div id="wrapper">
<div id="mydivLeft">
</div>
<div id="mydivRight">
</div>
</div>
</body>
You can use flexbox layout. By default the flex-direction is row, in the media queries change it to column-reverse.
#wrapper {
max-width: 1000px;
display: flex;
}
#mydivLeft, #mydivRight {
flex: 1;
height: 250px;
}
#mydivLeft {
background: blue;
}
#mydivRight {
background: yellow;
}
#media only screen and (max-width: 768px) {
#wrapper {
flex-direction: column-reverse;
}
}
<div id="wrapper">
<div id="mydivLeft"></div>
<div id="mydivRight"></div>
</div>
You can just reverse the order of the divs in the HTML to be whatever order you want them to be.
#wrapper {
width:1000px;
}
#mydivLeft {
background:blue;
height:250px;
width:50%;
float:left;
}
#mydivRight {
background:yellow;
height:250px;
width:50%;
float:right;
}
#media only screen and (max-width:768px){
#wrapper {
width:100%;
}
#mydivRight, #mydivLeft {
display:block;
float:none;
width:100%;
}
}
<div id="wrapper">
<div id="mydivRight">
</div>
<div id="mydivLeft">
</div>
</div>
Alternatively, a more complicated solution is to use flexbox, and use the order property or flex-direction: column-reverse; to re-order the flex children.
#wrapper {
width: 1000px;
display: flex;
}
#wrapper > div {
width: 50%;
height: 250px;
}
#mydivLeft {
background: blue;
}
#mydivRight {
background: yellow;
}
#media only screen and (max-width:768px) {
#wrapper {
width: auto;
flex-direction: column-reverse;
}
#wrapper > div {
width: auto;
}
}
<div id="wrapper">
<div id="mydivLeft">
</div>
<div id="mydivRight">
</div>
</div>