RESPONSIVE IMAGE ON RIGHT SIDE - html

Im trying to position my image on the right side of my screen and my text on the left, but make the image responsive as i resize my browser.
#fmap{
position: absolute;
right: 0%;
margin-right: 0;
display:block;
margin:10px;
width: 100%;
height: auto;
border: 12px double #d3d3d3;
max-width:850px;
}
<div class="maptext" id="facilitymap">
<p><a href="https://www.google.co.uk/maps/dir//Colman+House,+University+of+East,+Norwich+NR4+7TJ/#52.6212166,1.244658,17z/data=!4m9!4m8!1m0!1m5!1m1!1s0x47d9e1e20deda5b1:0x60290452cbfc9649!2m2!1d1.2468467!2d52.6212134!3e0">
<img src="https://4.img-dpreview.com/files/p/E~TS590x0~articles/3925134721/0266554465.jpeg" alt="" id="fmap" >
</a>
</p>
</div>

Here is one way using flexbox on the parent div;
.container {
/*this makes the parent container into a flex container*/
/*divs within this parent container become responsive flex items*/
display: flex;
}
.left {
padding: 20px;
}
#facilitymap {
width: 100%;
}
img {
width: 100%;
}
#media screen and (max-width: 600px) {
.container {
/*switch to column view when screen is 600px or smaller*/
flex-direction: column;
}
}
<div class="container">
<div class="left">
<p>left side text</p>
</div>
<div class="maptext" id="facilitymap">
<a href="https://www.google.co.uk/maps/dir//Colman+House,+University+of+East,+Norwich+NR4+7TJ/#52.6212166,1.244658,17z/data=!4m9!4m8!1m0!1m5!1m1!1s0x47d9e1e20deda5b1:0x60290452cbfc9649!2m2!1d1.2468467!2d52.6212134!3e0">
<img src="https://cdn.pixabay.com/photo/2020/07/27/14/34/stars-5442598__340.jpg" alt="" id="fmap">
</a>
</div>
</div>

Related

3 columns image layout with image text

I need three columns of image layout with image text like this picture
its responsive, like below picture no border no background color, image text background color like this required, I'm new to css/html
I need three columns of image layout with image text like this picture
its responsive, like below picture no border no background color, image text background color like this required, I'm new to css/html
* {
box-sizing: border-box;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.figure {
border: thin #c0c0c0 solid;
display: flex;
flex-flow: column;
padding: 5px;
max-width: 220px;
margin: auto;
position: relative;
}
.imgdiv {
max-width: 220px;
max-height: 150px;
}
.figcaption {
background-color: pink;
color: #fff;
font: italic smaller sans-serif;
padding: 3px;
text-align: center;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 700px) {
.column {
width: 100%;
}
}
<h2>Responsive Three Column Layout</h2>
<p>Resize the browser window to see the responsive effect (the columns will stack on top of each other instead of floating next to each other, when the screen is less than 600px wide).</p>
<div class="row">
<div class="column" style="">
<figure>
<img class="column" src="image1.jpg" style="width:100%;height:100%;">
<figcaption>Register here</figcaption>
</figure>
</div>
<div class="column" style="background-color:#bbb;">
<h3>image 2</h3>
<p>Info 2</p>
</div>
<div class="column" style="background-color:#ccc;">
<h3>Publications</h3>
<p>Info 3</p>
</div>
</div>
Use flex and flex-direction
.row {
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-end;
}
.column {
padding: 10px;
box-sizing: border-box;
}
img {
max-width: 100%;
}
.caption {
background-color: purple;
color: white;
/* padding: 0.1rem; */
}
.caption h3,
.caption p {
padding: 0.5rem;
margin: 0;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 700px) {
.row {
flex-direction: column;
}
}
<h2>Responsive Three Column Layout</h2>
<p>Resize the browser window to see the responsive effect (the columns will stack on top of each other instead of floating next to each other, when the screen is less than 600px wide).</p>
<div class="row">
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/arctichare.png" alt="arctichare">
</div>
<div class="caption">
<h3>image 1</h3>
<p>Info 1</p>
</div>
</div>
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/airplane.png" alt="airplane">
</div>
<div class="caption">
<h3>image 2</h3>
<p>Info 2</p>
</div>
</div>
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/baboon.png" alt="baboon">
</div>
<div class="caption">
<h3>Publications</h3>
<p>Info 3</p>
</div>
</div>

Image grid with autorescaling in HTML & CSS Only

I have been trying to make a responsive auto rescaling image grid to display ads on our website. I used this as a reference - W3Schools-ImageGridMaker
Based on that, I tried 4days to come up with this piece of code.
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
display: block;
object-fit: contain;
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
div.boxed {
border: 5px solid red;
width: 100%;
height: auto;
overflow: auto;
}
<div class="boxed">
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/UgPbxk2.jpg" alt="Shiva1"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/ColLeDr.png" alt="Shiva2"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/gVjcLg2.jpg" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/nxGxovl.png" alt="Shiva4"></a>
</div>
</div>
</div>
This code is responsive, and on mobiles I got no problem because it looks neat by filling the full area. But if you look at it on a desktop, it injects empty space underneath some pics that doesn't fit the height. I am using bunch of URLs and can feed them as a list so that this 1280X200px area on desktop fills up neat with images that are of different sizes. I tried looking into freewall and a ton of other jsfiddles and pens but couldn't achieve on how to make the whitespace removed and make that particular box look good. Thanks.
Per my comments - I would go with a flexbox solution that uses object-fit (with a polyfil for ie):
.container {
display: flex;
flex-direction: row; /* default value so optional - lines children in a row */
flex-wrap: wrap; /* allows children to wrap */
justify-content: space-between; /* space children evenly over row */
}
.responsive {
flex-basis: 25%; /* makes the width 25% */
/* if you don't want a fixed height image, I would use the padding top trick for aspect ratio divs */
position: relative;
padding-top: 30%;
}
.responsive img {
position:absolute;
display: block;
width: 100%;
height: 100%;
top:0;
left:0;
object-fit:cover;
}
#media only screen and (max-width: 700px) {
.responsive {
flex-basis: 50%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
flex-basis: 100%;
padding-top: 50%;
}
}
<div class="container">
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/600" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/400" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/900" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/700" alt="Shiva3"></a>
</div>
</div>
</div>

Resizing image within flexbox layout

I have a pay layout which works how I want to when using the .slides element has a background colour and height, it flexes as expected, however when I switch to filling it with an image this behaviour breaks as the images won't resize and I can't get my head around how to make them resize.
The idea is the left column of text remains fixed size, and the right column flexes up and down, eventually snapping under the left column at small sizes.
The reason for using an <img> and not a background image is because there is a image slide show that I want to put in here.
Can anyone help fix this issue?
body {
margin: 1em;
}
p {
margin: 0;
}
.container {
display: flex;
margin-top: 1em;
width: 100%;
flex-wrap: wrap;
}
.text {
flex: 0 0 auto;
width: 15em;
margin-right: 1em;
}
.images {
flex: 1 1 auto;
min-width: 15em;
max-width: 800px;
}
.caption {
margin-top: .25em;
}
<div class="header">
Title
</div>
<div class="container">
<div class="text">
<p>Something about this project is really interesting.</p>
</div>
<div class="images">
<div class="slides">
<img src="https://via.placeholder.com/800x800">
</div>
<div class="caption">
<p>Text about this project</p>
</div>
</div>
</div>
Changes made:
Enabled responsiveness for img elements
Commented out the flex-wrap: wrap
Set #media queries to define when the wrapping inside the .container div takes place
body {
margin: 1em;
}
p {
margin: 0;
}
img {
display: block; /* removes bottom margin/whitespace */
max-width: 100%; /* horizontally responsive */
max-height: 100vh; /* vertically responsive */
}
.container {
display: flex;
margin-top: 1em;
width: 100%;
/*flex-wrap: wrap;*/
}
.text {
flex: 0 0 auto;
width: 15em;
margin-right: 1em;
}
.images {
flex: 1 1 auto;
min-width: 15em;
max-width: 800px;
}
.caption {
margin-top: .25em;
}
#media (max-width: 33em) { /* 2 x 15em (.text & .images) + 2em (left & right margin of the body element) + 1em (.text margin-right) */
.container {flex-wrap: wrap}
}
<div class="header">
Title
</div>
<div class="container">
<div class="text">
<p>Something about this project is really interesting.</p>
</div>
<div class="images">
<div class="slides">
<img src="https://via.placeholder.com/800x800">
</div>
<div class="caption">
<p>Text about this project</p>
</div>
</div>
</div>
Do you mean something like this ?
body {
margin: 1em;
}
p {
margin: 0;
}
.container {
display: flex;
margin-top: 1em;
width: 100%;
flex-flow:row wrap;
}
.text {
flex: 0 0 auto;
width: 15em;
margin-right: 1em;
}
.images {
flex:1 0 15em;
min-width: 15em;
max-width:800px;
}
.slides {
display:flex;
}
.caption {
margin-top: .25em;
}
<div class="header">
Title
</div>
<div class="container">
<div class="text">
<p>Something about this project is really interesting.</p>
</div>
<div class="images">
<div class="slides">
<img src="https://via.placeholder.com/800x800" />
</div>
<div class="caption">
<p>Text about this project</p>
</div>
</div>
</div>

Div moves on top of div on some screen sizes

On a specific range of screen sizes (in the low 1000s), I have a content div that will move over a navigation div completely. It's as if both divs begin at the top of the page.
Here is the HTML:
<body id="about">
<div class="topnav" id="myTopnav">
Home
About
Contact
</div>
<div class="row">
<div class="col-md-6" id="left">
<h4><b>Lots of text.../b><h4>
</div>
<div class="col-md-6" id="right">
<img class="rounded" src="IMG-5-12-2017.jpg">
</div>
</div>
</div>
Here is the relevant CSS:
#media screen and (min-width: 993px) {
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#myTopnav {
position: absolute;
top: 0px;
left: 0px;
}
.row {
margin: 0;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
#left h4 {
margin: 5em;
}
}
.rounded {
border-radius: 50%;
width: 65%;
}
#left {
margin: 0;
padding: 0;
}
#left h4 {
line-height: 150%;
}
#right {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
Why would the row div move on top of the myTopnav div?
You have given your #myTopnav an absolute position. This takes it out of the flow of page.
It means you must handle spacing other elements so they do not to overlap the absolutely positioned ones.
In your case, you need to give your row class a margin that matches the height of #myTopnav element.
Since row is a class that is probably used in many places, you should probably add a new css class and use that to set the spacing. e.g.
<div class="row with-spacing">
<div class="col-md-6" id="left">
<h4><b>Lots of text.../b><h4>
</div>
<div class="col-md-6" id="right">
<img class="rounded" src="IMG-5-12-2017.jpg">
</div>
</div>
CSS:
#media screen and (min-width: 993px) {
.row.with-spacing {
margin-top:50px;
}
}

Container with max-width won't wrap inline-block children when resized

I have this code:
#media screen and (max-width: 600px) {
.col {
max-width: 150px;
}
}
.wrapper {
max-width: 500px;
margin: 0 auto;
background: grey;
font-size: 0;
}
.col {
width: 200px;
margin-right: 100px;
display: inline-block;
}
.col:last-child {
margin-right: 0px;
}
img {
max-width: 100%;
}
<section class="wrapper clearfix">
<section class="col">
<img src="http://placehold.it/200x120" alt="">
</section>
<section class="col">
<img src="http://placehold.it/200x120" alt="">
</section>
</section>
DEMO
The container won't wrap around its elements when media query gets activated. The same thing happens with floated children (which is normal, I guess).
Demo
one option is to add an "inner" wrapper; just a wrapper within your wrapper. you can make it display inline-block and set text-align center on the parent wrapper. Finally, remove the grey background from the wrapper and apply to the inner wrapper.
just one drawback is that when you make the window really small the .col divs are not lined up on the left. not sure if that's an issue for you
html
<section class="wrapper clearfix">
<div class='inner-wrap'>
<section class="col">
<img src="http://placehold.it/200x120" alt="">
</section>
<section class="col">
<img src="http://placehold.it/200x120" alt="">
</section>
</div>
</section>
css
#media screen and (max-width: 600px) {
.col {
max-width: 150px;
}
}
.inner-wrap {
display: inline-block;
background: grey;
}
.wrapper {
text-align: center;
max-width: 500px;
margin: 0 auto;
font-size: 0;
}
.col {
width: 200px;
margin-right: 100px;
display: inline-block;
}
.col:last-child {
margin-right: 0px;
}
img {
max-width: 100%;
}