2 headers lined up with 2 images side by side - html

I have the following HTML structure currently:
<div id="image" style="margin: 20px;">
<h5>
<span>DriverName1</span>
<span>DriverName2</span>
</h5>
<img src=/>
<img src= />
</div>
I am trying to make the images appear side by side which they are doing, but the headers for drivername1 and drivername2 are appearing right next to each other over the same image. How do I make these spans match up with the top left edge of each image? I tried adding separate headers over each image but that makes the images go vertically one on top of the other then.

you can consider using display:flex for this
check the following snippet
div{
display:flex;
}
.image {
display: flex;
flex-direction: column;
border:1px solid;
margin-left:10px;
}
img {
width: 100px;
height: 100px;
}
<div id="image" style="margin: 20px;">
<section class="image">
<header>DriverName1</header>
<img src="http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg">
</section>
<section class="image">
<header>DriverName2</header>
<img src="http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg" width=25px height=25px>
</section>
</div>
Non-flex solution
div * {
display: inline-block;
}
.image {
border: 1px solid;
margin-left: 10px;
}
img {
width: 100px;
height: 100px;
display: table-cell;
}
header {}
<div id="image" style="margin: 20px;">
<section class="image">
<header>DriverName1</header>
<img src="http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg">
</section>
<section class="image">
<header>DriverName2</header>
<img src="http://blog.caranddriver.com/wp-content/uploads/2015/11/BMW-2-series.jpg" width=25px height=25px>
</section>
</div>
Hope this helps

Related

Unable to line up text next to image when text wraps to second row with flex

I need help. Been trying for a few days to get the text to wrap up properly using flex. Nothing seems to work. flex-wrap:nowrap; and flex-direction:row; text:wrap; I would like to have the image then the text wrapped so it is even with the text on the other line like. Plus also control the spacing between the rows. I even tried adding the <div> but I believe the issue is with my css code just haven't been able to figure out the right combination to fix my issue.
<div class="image"><img src="images/trash.png" width="32" height="32" alt="Landfill" style="display: flex; flex-direction: row;">
<div class="text">
Landfill
</div>
</div>
image Target Property
image Drinking Water Well
image Hazardous Waste
Generator
div class="mb-4">
<div class="row justify-content-center">
<div class="map-wrapper">
<div class='map-container'id="map"></div>
<div class="flex-container">
<div class="legend">
<h2> Legend </h2>
<div class="image">
<img style="vertical-align:left" src="images/house_icon.png" width="32" height="32" alt="Pin that indicates target property">
<span style="vertical-align:left">Target Property</span>
</div>
<div class="image">
<img src="images/well.png" width="32" height="32" alt="Waterwell">
<span>Drinking Water Well</span>
</div>
<div class="image">
<img style="vertical-align:left" src="images/hazardous.png" width="32" height="32" alt="Hazardous waste sight">
<span>Hazardous Waste Generator</span>
</div>
</div>
</div>
</div>
</div>
</div>
<button id='center-button'>Center</button>
</div>
<!-- Map End -->
legend{
border-radius: 3px;
overflow-y:auto;
padding:10px;
position: absolute;
bottom:20px;
right:20px;
width:220px;
height:260px;
max-height:100%;
z-index:4;
background: rgba(255, 255, 255, 0.8);
}
.legend img {
padding-right: 10px;
max-width: 100%;
max-height: 100%;
}
.legend span {
flex-direction: row;
flex-wrap: nowrap;
flex: 0 0 0%;
padding-right: 2px;
}
.legend h2{
text-align:center;
margin-top:0px;
margin-bottom:0px;
}
Apply display:flex to your image class
.image {
display: flex;
align-items: center;
width: 175px;
}
img {
padding: .5em;
}
<div class="image">
<img src="https://toppng.com//public/uploads/preview/warning-vectors-and-icons-warning-svg-icon-11553508662kccnngsukp.png" width="32" height="32" alt="Hazardous waste sight">
<span>Hazardous Waste Generator</span>
</div>
Thanks for everyone help your tips work.
.image {
display: flex;
align-items: right;
padding-right: 20px;
margin-bottom: .5em;
}
<div class="image">
<img style="float: left; padding-right: 6px;" src="images/house_icon.png" width="32" height="32" alt="Pin that indicates target property">
<span>Target Property</span>
</div>
You can try adding display : flex to image class.
Checkout code pen solution.
https://codepen.io/gauravshankar/pen/KKWvjzj
You need to make changes whatever is written between the comment - /* Required Changes*/
.image {
display: flex;
}
You can also add align-items: center; if you want to align image to the center of text.
If image is of different size you can provide width to the image.
final code may be something like this.
.image {
display: flex;
align-items: center;
width: 30px;
}
https://codepen.io/gauravshankar/pen/KKWvjzj

Trying to simulate a shelf of books in HTML CSS: How to resize books, keep aligned to bottom?

I'm trying to simulate a shelf of books so that they look like this:
photoshop_mock_up
I can get the books to align just fine, but can't figure out how to make them retain their odd heights/widths, and not all just resize to the container:
HTML:
<div class="images-outer">
<div class="image-inner">
<img src="img/_0002_aristotle__poetics_and_rhetoric.png">
</div>
<div class="image-inner">
<img src="img/_0005_david_mamet__make_believe_town.png">
</div>
<div class="image-inner">
<img src="img/_0003_david_mamet__bambi_vs_godzilla.png">
</div>
<div class="image-inner">
<img src="img/_0006_annie_dillard__pilgrim_at_tinker_creek.png ">
</div>
</div>
CSS:
.images-outer {
height: 50%;
max-height: 50%;
display: flex;
vertical-align: bottom;
}
.image-inner img {
max-height: 100%;
}
img {
max-height: 100%;
}
This makes them look like this: web_page
Ideas?
In display: flex, you should use align-items to set vertical align and justify-content for horizontal align.
.images-outer {
height: 300px;
max-height: 50%;
display: flex;
align-items:flex-end;
justify-content:center;
background: black
}
.image-inner {
max-width:30px;
padding: 0px 5px;
}
.image-inner {
object-fit: contain;
object-position: bottom;
width: 100%;
}
<div class="images-outer">
<div class="image-inner">
<img src="https://picsum.photos/30/200" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/240" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/180" />
</div>
<div class="image-inner">
<img src="https://picsum.photos/30/200" />
</div>
</div>
</div>
.image-inner img{
width:100%;
height:auto;}
This should help in sizing the images properly
Else, you could dive each image an individual class and give each it's individual height.

Organize responsive images on desktop and mobile layouts

I'm trying to align two images side by side - pair after pair down by landing page on wide screen and single image - one after another on mobile screen layout:
<div class="container">
<div class="set">
<div class="column">
<img src="" id="img3" class="images">
</div>
<div class="column">
<img src="" id="img4" class="images">
</div>
<div class="column">
<img src="" id="img5" class="images">
</div>
<div class="column">
<img src="" id="img6" class="images">
</div>
</div>
</div>
container css:
.container {
height: relative;
padding: 0px 12px;
margin-top:0px;
margin-bottom:0px;
border-radius: 0px;
background-color: transparent;
}
set and column css:
* {
box-sizing: border-box;
}
.set {
display: flex;
}
.column {
flex: 33.33%;
padding: 5px;
}
images css:
.images {
position: relative;
width: 100%;
height: auto;
padding: 23px;
}
Actual result is a scalable images in one line with both screen layouts, left is a wide screen, right is mobile:
but I'm trying to get this result:
You just need to give one more parameter in your css file
#media screen and (max-width:768px){
.set{display:block}
}

centering pictures HTML

I try to center pictures in the container. I've set left and right margin to 0 and still something is not working right.
#navbut {
width: 100%;
background: red;
margin: -7px 0 0 0;
color: white;
}
.container .box {
display: inline-block;
width: 10%;
margin-left: auto;
margin-right: auto;
}
.box img.Newspaper_pic {
width: 50%;
margin-left: auto;
margin-right: auto;
}
<section id="navbut">
<div class="container">
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://placehold.it/100x100" alt="News-pic" class="Newspaper_pic">
</div>
</div>
</section>
What I am doing wrong that I cannot center pictures in one line?
If your images are set to inline-block, you have to use
text-align:center;
. If your images are set to block,
margin: 0 auto;
will work.
Looks like your pictures are centered, but only within the .box divs, you have to center those .box divs in the .container aswell. The .container also needs to be width 100% so it spans over the whole #navbut.
Try to use flex. flex is very easy to make for these kind of layouts because of these alignment properties.
Reference Link flex
Stack Snippet
body {
margin: 0;
}
.container, .box {
display: flex;
justify-content: center;
}
.Newspaper_pic {
display: block;
max-width: 100%;
}
<section id="navbut">
<div class="container">
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
<div class="box">
<img src="http://lorempixel.com/400/200/sports" alt="News-pic" class="Newspaper_pic">
</div>
</div>
</section>
Put whatever you want inside the center tags, e.g:
<center>
<img src="" alt="">
</center>

css instaframe effect on html page

I need to align images like this photo. My code is:
<html>
<head>
<style>
.main
{
width: 634px;
height: 634px;
}
.img1
{
width: 315px;
height: 315px;
}
</style>
</head>
<body>
<img src="photo/01.jpg" class="main"><br>
<img src="photo/05.jpg" class="img1">
<img src="photo/01.jpg" class="img1">
<img src="photo/01.jpg" class="img1">
</body>
</html>
I want to create instaframe effect on html page. But I cant add images to the right side
You can use floating to achieve your desired effect:
.main {
width:80%; /* width can be anything */
overflow:auto; /* clears floating */
}
.main img {
width:33.33%; /* images are responsive, usually 3 images per row (33.33) */
height: auto; /* resize height based on width to keep image proportion */
float:left; /* float images to the left */
border:2px solid white; /* optional border */
box-sizing:border-box; /* makes sure border does not break total width */
}
.main img.big {
width:66.66%; /* big image takes 2/3 of grid size, so 66.66 of 100 */
}
<div class="main">
<img src="https://placehold.it/100x100" class="big">
<img src="https://placehold.it/100x100">
<img src="https://placehold.it/100x100">
<img src="https://placehold.it/100x100">
<img src="https://placehold.it/100x100">
<img src="https://placehold.it/100x100">
</div>
It is best to wrap the floated elements inside a common parent so that they do not affect the rest of page elements. In this case, the parent is <div class="main">.
jsFiddle
You can use CSS3 flexbox to achieve this;
See code below; you probably also want to use % or ems instead of fixed height/width;
using float as per answer above is more beautiful of course, flexbox is just one more way to achieve same results
Demo: jsFiddle
.main {
width: 300px;
height: 300px;
}
.img {
width: 150px;
height: 150px;
}
.rowContainer {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.columnContainer {
display: flex;
flex-direction: column;
}
.mainContainer {
width: 450px
}
<div class="mainContainer">
<div class="columnContainer">
<div class="rowContainer">
<img class="main">
<div class="columnContainer">
<img class="img">
<img class="img">
</div>
</div>
<div class="rowContainer">
<img class="img">
<img class="img">
<img class="img">
<img class="img">
<img class="img">
<img class="img">
</div>
</div>
</div>