Want DIVs stacked on desktop but next to each other on mobile - html

Im trying to keep an image with a description underneath it on desktop and then for mobile want the image to the left and description to the right... more for keeping everything above the fold as much as possible.
I want on desktop the DIVs to be:
A A A
B B B
But on mobile:
A B
A B
A B
I have them in parents to try and keep them together within there but doesn't seem to be working.
<style>
.pathOption_row {
display: inline-block;
position: relative;
width: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
}
.pathOption_block {
display: inline-block;
position: relative;
width: 30%;
height: 300px;
text-align: center;
margin: 0 auto;
vertical-align: middle;
}
.pathOption_img {
display: inline-block;
position: relative;
width: 100%;
height: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
#media only screen and (max-width: 768px) {
.pathOption_block{
width:70%;
position: relative;
text-align: center;
}
.pathOption_image {
float: left;
display: inline-block;
position: absolute;
text-align: center;
margin: 0 auto;
vertical-align: middle;
.pathOption_text {
float: right;
}
.pathOption_img {
display: inline-block;
float: left;
position: relative;
width: 50%;
height: 100%;
text-align: center;
margin: 0 auto;
vertical-align: middle;
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
</style>
<div class="pathOption_row">
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
<div class="pathOption_block">
<div class="pathOption_image">
<a class="pathOption_link" href="X">
<img class="pathOption_img" src="http://tug.ctan.org/macros/latex/contrib/mwe/example-image-a.png" alt="" />
</a><!--/.po_link-->
</div><!--/.pathOption_image-->
<div class="pathOption_text">
B
</div><!--/.pathOption_text-->
</div><!--/.pathOption_block-->
</div><!--/.pathOption_row-->

Here's a working fiddle: https://jsfiddle.net/zsvfLy7q/5/
Basically you want to wrap the As and Bs vertically and then stack them inline on mobile.
.wrapper {
display: flex;
flex-direction: column;
}
#media (min-width:800px) {
.wrapper {
flex-direction: row;
}
}
#media (max-width:800px) {
.block {
display: flex;
}
}
I was using flexbox since it's preferred way nowadays, but the same can be achieved with floats, the idea is the same.

Related

How to make an horizontal scrollbar responsively fit to the div width?

I have an horizontal scrollbar class="filter_list" into a wrapper div class="wrapper". I want this scrollbar to be always 100% of the wrapper div and I want this wrapper div to be responsive.
It's working fine if I only have one item in my filter list but as soon as I put more than the wrapper width size, it's not responsive anymore.
Here are some pictures to illustrate the problem :
Responsive and working fine :
OK
The scrollbar is blocking the width of the wrapper that doesn't shrink to fit the dimension of the window (we can see that the picture of the girl is no longer it's 100% square size):
NOT OK
Here is the code :
body {
display: flex;
align-items: center;
justify-content: center;
}
.wrapper {
width: 800px;
display: flex;
justify-content: flex-start;
flex-direction: column;
align-items: center;
}
.magic_wand {
margin: 15px 0px 20px;
max-width: 50px;
}
.ico_magic_wand {
width: 100%;
height: 100%;
object-fit: contain;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
width: 100%;
height: 100%;
object-fit: contain;
}
.filter_list {
width: 100%;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
<body>
<div class="wrapper">
<div class="magic_wand">
<img src="img/ico/magic_wand.png" class="ico_magic_wand">
</div>
<div class="picture_preview">
<img src="https://images.unsplash.com/photo-1527514086375-0a7bae9089be">
</div>
<div class="filter_list">
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
<div class="filter">
</div>
</div>
</div>
</body>
I would like to understand why the div class="filter_list" width won't shrink with it's parent div while reducing the width of the window and how to fix the problem, thanks a lot !
Try this code.. I can't understand your question.. it may ur expectation,, else explain it clearly..
css
.filter {
display: inline-block;
height: 150px;
width: 21.3%;
background-color: blue;
margin-right: 15px;
}
.filter:nth-child(4n+4) {
margin-right: 0px;
}
Please remove ur css code and add this codes.. I think display:flex; is the issue for ur code..
body {
margin:0px;
}
img {
max-width: 100%;
height: auto;
}
.wrapper {
width: 800px;
margin: 0 auto;
text-align: center;
}
.magic_wand {
margin: 15px auto 20px;
max-width: 50px;
}
.picture_preview {
width: 100%;
margin-bottom: 50px;
height: 100px;
}
.picture_preview img {
height: 100%;
}
.filter_list {
width: auto;
background-color: blueviolet;
overflow-x: auto;
white-space: nowrap;
font-size: 0;
}
.filter:last-child {
margin-right: 0px;
}
.filter {
display: inline-block;
height: 150px;
width: 150px;
background-color: blue;
margin-right: 15px;
}
#media only screen and (max-width: 1024px) {
.wrapper {
width: 100%;
}
}

how to make website responsive vertically?

I have a webpage and I have the "body" wrapped around all my content. But when I do this webpage responsive and want the body to enlarge the web content the body stops enlarge the content vertically. It do enlarge the content when I increase the width but not vertically. I don't want the extra black area.
body {
background-color: black;
padding-bottom: 10vh;
padding-top: 10vh;
padding-right: 10vh;
padding-left: 10vh;
margin: 0;
height: 100%;
align-content: center;
justify-content: center;
position: relative;
}
#wrapper {
position: static;
align-items: center;
height: 100%;
width: 100%;
align-content: center;
display: flex;
flex-direction: row;
margin: 0 auto;
justify-content: center;
overflow: auto;
}
#wrapper2 {
align-items: center;
width: 100%;
height: 100%;
align-content: center;
display: flex;
flex-direction: row;
margin: 0 auto;
justify-content: center;
overflow: auto;
}
img {
width: 100%;
height: 100%;
display: block;
}
.cell1 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.cell2 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.cell3 {
width: calc(100% / 3);
text-align: center;
background-size: contain;
height: 100%;
background-position: center;
position: relative;
}
.dogname {
color: white;
top: 20px;
font-family: 'Roboto Condensed', sans-serif;
text-align: center;
position: absolute;
width: 100%;
margin: 0;
}
.dogtext {
color: white;
top: 0;
font-family: 'Roboto Condensed', sans-serif;
text-align: center;
position: relative;
width: 100%;
margin-bottom: 30px;
margin-top: 0px;
display: none;
}
#media screen and (max-width: 500px) {
#wrapper {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
#wrapper2 {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.cell1 {
width: 100vw;
}
.cell2 {
width: 100vw;
}
.cell3 {
width: 100vw;
}
.dogname {
display: none;
}
.dogtext {
display: block;
}
body {
background-color: black;
height: 100%;
padding: 0;
margin: 0;
}
}
<body>
<div id="wrapper">
<div class="cell1">
<p class="dogname">David Neal</p>
<img src="images/image1.jpg" />
</div>
<p class="dogtext">After the hunt (1870) by David Neal</p>
<div class="cell2">
<p class="dogname">BG Tiepolo</p>
<img src="images/image2.jpg" />
</div>
<p class="dogtext">Portrait of a Toy Spaniel Belonging to the Infanta Maria Josefa of Bourbon (1763) by Giovanni Battista Tiepolo</p>
<div class="cell3">
<p class="dogname">AF Desportes</p>
<img src="images/image3.jpg" />
<p class="dogtext">Chienne blanche devant un buisson de sureau (1714) by Alexandre-François Desportes</p>
</div>
</div>
<div id="wrapper2">
<div class="cell1">
<p class="dogname">JC Merck</p>
<img src="images/image4.jpg" />
<p class="dogtext">Ulmer Dogge (1705) by Johann Christof Merck</p>
</div>
<div class="cell2">
<p class="dogname">John Wootton</p>
<img src="images/image5.jpg" />
<p class="dogtext">A Grey Spotted Hound (1738) by John Wootton</p>
</div>
<div class="cell3">
<p class="dogname">EH Landseer</p>
<img src="images/image6.jpg" />
<p class="dogtext">A Distinguished Member of the Humane Society (1838) by Edwin Henry Landseer</p>
</div>
</div>
</body>
It really depends on what do you want to achieve, but generally, you can use media queries for height and combine them with the ones for width.
#media screen and (max-width: 800px) , screen and (max-height: 600px) {
...
}
By default, your webpage is vertically scaled based on the height of the content. To always have it at least be one viewheight high, you can insert this rule into your css:
html, body {
min-height: 100vh;
}

Keeping P Element Inside A Div

I would like to make this div responsive and keep the text in the center of it the entire time. As of now, it looks fine on mobile since I added media queries to it, but on desktop the p element in my .info-p-div goes into the div below and looks awful. These divs are side-by-side on the page. I will post my HTML and CSS code relating to this section of the page so you can see what I mean.
HTML
<div class="info">
<div class="info-img-div">
<img src="images/owner.jpg" />
<p><font color="#F5F5F5">Text here</font></p>
</div>
<div class="info-p-div">
<p><font color="#F5F5F5">Text here</font></p>
</div>
</div>
<div class="parallax-3"></div>
CSS
.info {
text-align: center;
min-height: 250px;
width: 100%;
background-color: #000;
}
.info-img-div {
position: left;
width: 35%;
border-right-style: solid;
border-color: #F5F5F5;
}
.info-img-div img {
border-radius: 50%;
height: 25%;
width: 25%;
min-height: 100px;
min-width: 100px;
margin-top: 20px;
}
.info-p-div {
height: 25%;
width: 50%;
max-width: 65%;
text-align: center;
position: relative;
float: right;
font-size: 12px;
word-wrap: break-word;
vertical-align: middle;
}
.parallax-3 {
background-image: url("images/background3.jpg");
height: 400px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#media only screen and (max-width: 600px) {
.info {
text-align: center;
float: none;
height: 50%;
}
.info-img-div {
float: none;
border-right-style: none;
position: relative;
width: 100%;
}
.info-p-div {
float: none;
text-align: center;
width: 100%;
max-width: 100%;
}
}
I think you are looking for below solution.
I posted an working example.
.box {
display: flex;
justify-content: center;
flex-direction: row;
align-items: center;
width: 100%;
height: 300px;
background: tomato;
}
.box p {
flex: 1 0 0;
text-align: center;
}
#media screen and (max-width:600px) {
.box {
flex-direction: column;
}
.box p {
display: flex;
justify-content: center;
align-items: center;
}
}
<div class="box">
<p>One</p>
<p>Two</p>
</div>

Automatically resize image an inline image in CSS

I want my inline images to automatically resize with browser size and at the same time it should be inline with the header too. I have already tried solution given here but it is not working for me.
Here is my code:
#header_title {
font-weight: bolder;
text-align: center;
}
#header_photo {
display: none;
}
.floatingimage {
float: right;
max-width: 100%;
height: auto;
}
#media all and (max-width: 1024px) {
#header_title {
margin-left: 10%;
min-width: 67%;
max-width: 77%;
display: inline-block;
vertical-align: top;
position: relative;
}
#header_photo {
display: inline-block;
vertical-align: top;
max-width: 20%;
height: auto;
}
}
<header>
<div id="header_title">
<h1>Title h1</h1>
<h3>Title h3</h3>
</div>
<aside id="header_photo">
<img class="floatingimage" src="http://www.planwallpaper.com/static/images/Awesome-Nature-Background.jpg" width="100px" height="100px" />
</aside>
</header>
You find this code on jsfiddle here.
NOTE: I am using Firefox 53.0.3(32-bit)
I slightly modified your HTML and CSS. I add flex display and image height related to width.
HTML code:
<header>
<div id="header_title">
<h1>Title h1</h1>
<h3>Title h3</h3>
</div>
<aside id="header_photo">
<img class="floatingimage" src="http://www.planwallpaper.com/static/images/Awesome-Nature-Background.jpg"/>
</aside>
CSS code:
header {
display: flex;
}
#header_title
{
font-weight: bolder;
text-align: center;
}
#header_photo
{
display: none;
max-width: 100%;
height: auto;
align-self: center;
}
#header_photo img {
width: 100%;
height: auto;
max-height: 120px;
}
.floatingimage
{
float: right;
}
#media all and (max-width: 1024px)
{
#header_title
{
margin-left: 10%;
min-width: 67%;
max-width: 77%;
display: inline-block;
vertical-align: top;
position: relative;
}
#header_photo
{
display: inline-block;
vertical-align: top;
max-width: 20%;
height: auto;
}
}
You check it on fiddle here
You have sized the image using inline-styling; that is the main problem. You can do two 2 things:
add the width and height to the floatingimage class
OR
create a new class e.g. .wh100, with width:100px; and height:100px; and use a second class with the .floatingimage in your html e.g img class="floatingimage wh100"
In either option, remember to REMOVE the inline styling from the html!!
Then your images should size appropriately.
Give that a whirl
RE-EDIT: (back on computer - sigh..).. here you go.. the fiddle i posted a while ago with the header narrowed to 75%.
header {
width: 75%;
height: auto;
margin: 0 auto;
padding: 0;
}
#header_title {
font-weight: bolder;
text-align: center;
max-width: 80%;
}
#header_photo {
/*display: none;*/
margin: 0;
padding: 0;
max-width: 20%;
height: auto;
float: right;
}
.floatingimage {
position: relative;
display: none;
}
.wh100 {
width: 100px;
height: 100px;
}
#media all and (max-width:480px){
#header_photo {
margin-top: 8%!important;
}
}
#media all and (max-width:1024px) {
#header_title,
#header_photo img {
margin: 0;
padding: 0;
top: 2%;
display: inline!important;
vertical-align: middle!important;
}
#header_title {
max-width: 80%;
position: relative;
float: left;
}
#header_photo {
margin-top: 4%;
max-width: 20%;
position: relative;
float: right;
}
#header_photo img {
position: relative;
max-width: 100%;
height: auto;
}
}
<header>
<div id="header_title">
<h1>Title h1</h1>
<h3>Title h3</h3>
</div>
<aside id="header_photo">
<img class="floatingimage wh100" src="http://www.planwallpaper.com/static/images/Awesome-Nature-Background.jpg" />
</aside>
</header>
New fiddle

How to force space inbetween a css table (responsive webpage)

I have a CSS table and I would like to have space in-between the cells but not at the left of the first image and the right of the last image.
Here is a screenshot of what I have:
Here is a screenshot of what I would like:
The current HTML is:
<div id="footer">
<div class="lower"><img src="images/one.jpg" alt="Ring being put on finger"/></div>
<div class="lower"><img src="images/two.jpg" alt="The mens trousers"/></div>
<div class="lower"><img src="images/three.jpg" alt="Flowers"/></div>
<div class="lower"><img src="images/four.jpg" alt="The rings"/></div>
</div>
and the CSS is
#footer {
display: table;
width: 100%;
max-width: 1024px;
margin-top: 1%;
}
.lower {
display: table-cell;
}
#footer img {
width: 100%;
height: auto;
max-width: 256px;
}
Please bear in mind that this is a responsive webpage so I would like the space to always remain however I would like the space to change according to device size, so using %.
Apply this.
#footer {
display: flex;
justify-content: space-between;
width: 100%;
max-width: 1024px;
background-color: #F00;
padding: 0;
margin: 0;
max-height: content-height;
}
.lower {
margin-left: 2%;
}
#footer img {
width: 100%;
height: 100%;
}
Demo
hi pls apply this css and set padding
.lower {
display: table-cell;
padding:0 20px;
}
.lower:first-child{ padding-left:0}
.lower:last-child{ padding-right:0}
Try display: flex; instead of display: table;
Give display: flex; and justify-content: space-between; to the parent.
Use CSS adjacent element selector:
.lower + .lower {
padding-left: 20px;
}
#footer {
display: table;
width: 100%;
max-width: 1024px;
margin-top: 1%;
}
.lower {
display: table-cell;
}
.lower + .lower {
padding-left: 20px;
}
#footer img {
width: 100%;
height: auto;
max-width: 256px;
}
<div id="footer">
<div class="lower"><img src="images/one.jpg" alt="Ring being put on finger"/></div>
<div class="lower"><img src="images/two.jpg" alt="The mens trousers"/></div>
<div class="lower"><img src="images/three.jpg" alt="Flowers"/></div>
<div class="lower"><img src="images/four.jpg" alt="The rings"/></div>
</div>