I am trying to make my app responsive. The original css looks like this :
.footer-container {
width: 100%;
min-height: 260px;
height: auto;
background: black;
color: white;
display: flex;
justify-content: center;
flex-wrap: wrap;
position: absolute;
}
The output is this :
But when the screen width reaches 1020px i want them to be underneath eachother.
I tried making the display:flex display:block :
#media only screen and (max-width: 1020px) {
.footer-container {
width: 100%;
min-height: 260px;
height: auto;
background: black;
color: white;
display: block;
text-align: center;
justify-content: center;
position: absolute;
}
}
But that turns out like :
I also tried flex-direction: row but that didn't work either, it practically didnt change a single thing.
Using basic HTML below a solution using a media query. Mobile first and when the screen size exceeds 1024 pixels the media query kicks in.
.footer-container {
width: 100%;
display: flex;
flex-wrap: wrap;
}
.contact,
.subscribe,
.follow {
width: 100%;
display: flex;
justify-content: center;
}
#media (min-width: 1024px) {
.footer-container {
flex-wrap: no-wrap;
justify-content: center;
}
.contact,
.subscribe,
.follow {
width: auto;
}
}
<div class="footer-container">
<div class="contact">Contact us</div>
<div class="subscribe">Subscribe</div>
<div class="follow">Follow us</div>
</div>
Related
I have a simple layout with image on Left and Title of blog on right with light grey background for large screen or were width is minimum 800px. for smaller screens it should show image on top and Title below image. It is working fine except two thing
It show extra space under image which is shown as yellow background in this case.
I want Title Item to be same height as Image element with light grey background, in this case which is represented as red.
.flex-container {
display: flex;
align-items: stretch;
flex-direction: row;
border: 1px solid blue;
height: 100%;
}
.flex-container>div {
background-color: yellow;
color: #555;
width: 50%;
height: 100%;
margin: 0px;
text-align: center;
align-self: center;
font-size: 30px;
}
.title-wrapper {
background-color: #f00 !important;
}
.imgx {
width: 100%;
}
#media (max-width: 800px) {
.flex-container {
flex-direction: column;
}
.flex-container>div {
width: 100%;
margin: 0px;
}
.imgx {
width: 100%;
}
}
<div class="flex-container">
<div class="image-wrapper"><img class="imgx" src="https://dummyimage.com/600x400/000/add413&text=IMAGE"></div>
<div class="title-wrapper">This is the title</div>
</div>
To avoid the gap under the image, 2 classical options :
reset vertical-align: to top or bottom
or reset display to block.
To center content inside the second box, make it also a grid or flex box
Possible fix :
.flex-container {
display: flex;
flex-direction: row;
border: 1px solid blue;
height: 100%;
}
.flex-container>div {
background-color: yellow;
color: #555;
width: 50%;
text-align: center;
font-size: 30px;
}
.flex-container .title-wrapper {
background-color: #f00;
display:flex;
align-items:center;
justify-content:center;
margin:0;
}
.imgx {
width: 100%;
display:block;
}
#media (max-width: 800px) {
.flex-container {
display:grid;/* or block*/
}
.flex-container>div ,
.imgx {
width: 100%;
}
}
<div class="flex-container">
<div class="image-wrapper"><img class="imgx" src="https://dummyimage.com/600x400/000/add413&text=IMAGE"></div>
<div class="title-wrapper">This is the title</div>
</div>
To get rid of the space beneath the image, the image needs to be display: block, then to make the title full height and still aligned centre, you need to remove the height and then make the title itself flex and use align and justify on it (see comments in css below):
.flex-container {
display: flex;
align-items: stretch;
flex-direction: row;
border: 1px solid blue;
height: 100%;
}
.flex-container>div {
background-color: yellow;
/* remove height from here */
color: #555;
width: 50%;
margin: 0px;
font-size: 30px;
}
.title-wrapper {
background-color: #f00 !important;
/* add the following to here */
display: flex;
justify-content: center;
align-items: center;
}
.imgx {
width: 100%;
display: block; /* add this */
}
#media (max-width: 800px) {
.flex-container {
flex-direction: column;
}
.flex-container>div {
width: 100%;
margin: 0px;
}
.imgx {
width: 100%;
}
}
<div class="flex-container">
<div class="image-wrapper"><img class="imgx" src="https://dummyimage.com/600x400/000/add413&text=IMAGE"></div>
<div class="title-wrapper">This is the title</div>
</div>
you have to remove height and align-self in .flex-container > div
.flex-container > div {
background-color: yellow;
color: #555;
width: 50%;
margin: 0px;
text-align: center;
font-size: 30px;
}
are you sure to use align-self or did you mean align-items and justify-content?
Okay so, for a school assignment I have to make these blocks responsive and changing rows when on a certain screen width, above 1024px they have to be 2 rows going horizontally, and below 1024px 2 rows going vertically, always spelling out 'LOI'. Now when at 660px, the blocks dont get smaller, they fall out of the screen. Is there a way to make them gradually get smaller when the screen width is at say 660px? Thanks in advance!
main {
max-width: 1024px;
margin: auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
max-height: 1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
#media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 5em;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
<main>
<h2 id="letterblokjes">Letterblokjes</h2>
<div class="blokken">
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
</div>
</main>
You can try using a dynamic calculated max-width instead of a static 300px width.
#media only screen and (max-width: 800px) {
.letter {
max-width: calc(100%/2 - 10px); /* -10 px accounts for margin: 5px; */
}
}
See it working here:
main {
max-width: 1024px;
margin: auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
max-height: 1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
#media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 5em;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
#media only screen and (max-width: 800px) {
.letter {
max-width: calc(100%/2 - 10px); /* -10 px accounts for margin: 5px; */
}
}
<main>
<h2 id="letterblokjes">Letterblokjes</h2>
<div class="blokken">
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
<div class="letter">L</div>
<div class="letter">O</div>
<div class="letter">I</div>
</div>
</main>
You can use another #media to set your width to a percentage when you're at 660px:
main {
max-width: 1024px;
margin: auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
max-height: 1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 5em;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
#media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
#media screen and (max-width: 660px){
.letter{
width : 48%;
}
}
EDIT :
now your blocks are square and getting smaller with less space
main {
max-width: 1024px;
margin : auto;
}
.blokken {
display: flex;
flex-wrap: wrap;
flex-direction: column;
height:1200px;
align-content: center;
max-width: 100%;
justify-content: center;
}
.letter {
width: 300px;
height: 300px;
margin: 5px;
background-color: #eee;
border: 5px solid black;
font-family: sans-serif;
font-size: 100px;
color: black;
display: flex;
justify-content: center;
align-items: center;
border-radius: 25%;
overflow: hidden;
}
#media screen and (min-width: 1024px) {
.blokken {
flex-direction: row;
}
}
#media screen and (max-width: 660px){
.blokken{
height : 160vw;
}
.letter{
width : 40vw;
height : 40vw;
}
}
I changed the letter proportion to vw as it's responsive, allowing them to stay square on any small screen
I also changed the height of blokken for the letter to always stay packed by putting the unit to vw on under 660px wide screen
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>
I have a carousel on a web page that I have absolute positioning on of top:420px and left:640px. I would like for it to collapse and become vertical when the screen size changes. I put the media query in display:flex flex-direction: column. The slider doesn't move from its absolute position. Is there a way I can make it responsive and collapse to a column when screen size is smaller.
.main {
background: transparent;
border-radius: 10px;
max-width: 50%;
width: auto;
text-align: center;
position: absolute;
top: 420px;
left: 640px;
}
#media screen and (max-width: 600px) {
.main {
max-width: 100%;
width: auto;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
}
.main div img {
max-width: 100%;
width: auto;
}
display:flex and flex-direction: column only affects the inner arrangement of your div. In order to change your div's position, you'll have to change the top and left values. For example:
.main {
background: transparent;
border-radius: 10px;
max-width: 50%;
width: auto;
text-align: center;
position: absolute;
top: 420px;
left: 640px;
display: flex;
}
#media screen and (max-width: 600px) {
.main {
max-width: 100%;
width: auto;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
top: 100px;
left: 100px;
}
}
.main div img {
max-width: 100%;
width: auto;
}
<div class="main">
<div>First div</div>
<div>Second div</div>
</div>
how can I make this container responsive so the text and the img automatically become block elements. I tried it out with flex direction but for someway it doesnt work. Can someone correct my code if necessary and suggest me a media query rule for the responsive design
<div class="top">
<h1>Welcome</h1>
<div class="portrait">
<img src="https://pixy.org/images/placeholder.png" alt="">
<h2>XXXXXXXXXX</h2>
</div>
</div>
.top h1{
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: black;
height: 20vw;
margin-top: 0;
font-size: 5vw;
color: white;
text-shadow: 5px 5px rgb(142, 135, 136);
}
.top img {
width: 20vw;
}
thanks in advance
I think this is what you are after. display: flex; is very powerful property and useful when it comes to take up rest of the space and centering.
Modification
here is a demo, I would not suggest this approach with using max-width as it's not "mobile-first". But if this is what you want for this project then ok.
.container {
display: flex;
flex-direction: row;
background-color: deepskyblue;
}
#img {
width: 140px;
height: 140px;
}
#text {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: deeppink;
min-height: 100px;
}
#media screen and (max-width: 700px) {
.container {
flex-direction: column;
}
#img {
width: 100%;
height: auto;
}
}
.container {
display: flex;
background-color: deepskyblue;
}
#img {
width: 140px;
height: 140px;
}
#text {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
background-color: deeppink;
}
<div class="container">
<img id="img" src="https://www.archlinux.org/static/vector_tux.864e6cdcc23e.png" />
<div id="text">text on the left, next to the img</div>
</div>
Ok, well so here it is if I understood well what you are trying to accomplish. Correct me or update your question if I am wrong!
#img{
width: 200px;
height: 150px;
float: left;
}
#text{
overflow: hidden;
}
<div class="container">
<img id="img" src="https://www.archlinux.org/static/vector_tux.864e6cdcc23e.png"/>
<div id="text">text on the left, next to the img</div>
</div>