Aligning images in a row with text below each image - html

In short, I'm trying to achieve a design similar to this:
Where the white boxes are images, and the red brushes are lines of text (the top line would hold a name and underneath their specialty) but using divs has proven to be problematic as I can't get the content to line up in a proper row - I'm not too keen on using a table for something like this due to compatibility problems, so I'm hoping someone on here would be able to assist me in trying to get it to work with divs before I fall back to that.
Below is the code I have so far and a jsfiddle accompaniment.
<div id="design-cast">
<h4>Design</h4>
<div class="member">
<img src="http://i.imgur.com/OBUL7se.jpg" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
<div class="member">
<img src="http://i.imgur.com/OBUL7se.jpg" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
<div class="member">
<img src="http://i.imgur.com/zmPeyso.png" class="img-responsive img-thumbnail" alt="Responsive image" />
<div class="name">Name
<br />Description</div>
</div>
</div>
CSS
.member {
display: inline;
}
.name {
display: inline;
}
.member img {
width: 13%;
display: block;
}
jsfiddle

Set a width on the .member elements, and float them.
jsFiddle example - it works responsively.
Notice, as pointed out in the comments, this also aligns the text at the bottom if the images are of differing demensions.
Updated CSS
#design-cast {
position: relative;
overflow: hidden;
}
.member {
float: left;
width: 31%;
margin: 1% 1% 45px 1%;
}
.name {
position: absolute;
bottom: 0px;
}
.member img {
width: 100%;
display: block;
}

An inline-block solution (this way you can put the whole thing in a text-align: center container if you want):
.member {
display: inline-block;
width: 150px;
height: 200px;
vertical-align: top;
}
.name {
display: inline;
}
.member img {
width: 100%;
display: block;
}
http://jsfiddle.net/MhRnz/2/

Just what you wanted and the text is centered.
.member {
display: inline-block;
width: 150px;
height: 200px;
vertical-align: top;
text-align:center;
}
.name {
display: inline;
}
.member img {
width: 100%;
display: block;
}
jsfiddle: http://jsfiddle.net/skoltyno/MhRnz/4/

Related

3 Horizontal Box - CSS

What i would like to achieve is that i want to change the way my boxes appear only on the mobile version of the website. I experimented with display: and flex: rules but had no luck. I want them stick to each other but Couldn't find the right CSS rule. Help.
Thanks.
Example picture of how i want them:
The way they appear on desktop version of the website:
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/></div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img /></div>
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
#media only screen and (max-width: 1000px) {
.main {
display: flex;
gap: 10px;
}
.m-image {
border: solid black 3px;
}
}
<div class = "main">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1">
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" />
</div>
</div>
Couple of things to think about when it comes to mobile view. When wanting certain items to display a certain way on mobile view you want to use #media only screen and (max-width: /* width of the device */. Place all the CSS rules inside of here. These rules will change the rules set above or run new rules that you have define below.
Also, when it comes to display: flex; you want to make sure you wrap it into another div. This "wrapper" or "container" will provide the structure to the way you want the images to display.
add a main container to compress the class m-image then add display flex
Ex:
<div id="main-container">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
.main-container {
display: flex;
}
then add padding left and right to your m-image class
what you should do in this case is put your images in a single container and apply flex property in the css.
basically manipulate your html and css like this.
HTML:
<div class="image-container">
<div class="m-image">
<img srcset="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"><img/>
</div>
<div class="m-image">
<img alt="" loading="lazy" src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" /><img />
</div>
</div>
CSS:
.image-container{
display:flex;
gap: 8px;
flex-wrap: nowrap;
}
.m-image {
border: 5px dashed black;
width: 100%;
height: 70px;
margin: 10px 0;
position: relative;
display: inline-block;
vertical-align: top;
overflow: hidden;
}
img {
width: 100%;
height: 300px;
}
This should give you your desired result for the desktop and for the mobile version you will have to apply media query into your CSS code.
hope this answers your question!
I couldn't really understand your code, So I wrote one for you suiting your needs
I hope it will fix your problem!
#content{
display: flex;
justify-content: space-around;
width: 100%;
}
.imagecontainer{
overflow: hidden;
width: 30%;
}
img{
width: 100%;
}
<div id="content">
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6395415/pexels-photo-6395415.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6044656/pexels-photo-6044656.jpeg"></div>
<div class="imagecontainer"><img src="https://images.pexels.com/photos/6045291/pexels-photo-6045291.jpeg"></div>
</div>

Vertically align images in full-height columns

Given the following layout:
.half-side {
width: 50%;
display: inline-block;
vertical-align: middle;
text-align: center;
}
.leftbox {
margin: 0px auto;
}
.rightbox {
margin: 0px auto;
}
<div class="half-side">
<div class="leftbox">
<img src="https://68.media.tumblr.com/avatar_65ce634bba10_128.png" />
</div>
</div><!--
--><div class="half-side">
<div class="rightbox">
<img src="https://68.media.tumblr.com/avatar_65ce634bba10_128.png" />
</div>
</div>
Here's a Fiddle.
How can I vertically center my images?
As you can see, I've tried vertical-align: middle to no avail. To be frank, I don't really understand why this doesn't work.
I keep seeing this "trick" - and similar approaches using negative transformations - everywhere:
.element {
position: relative;
top: 50%;
transform: translateY(-50%);
}
Which causes the images to be pushed halfway off the top of the page.
How do I vertically align the content in my two columns?
In your code, your divs don't have height so it will never know where the vertical center is. The simplest hack is to use an inline-block helper with height: 100% and vertical-align: middle on both elements.
Here's the full code solution:
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
.half-side {
width: 50%;
height: 100%;
display: inline-block;
text-align: center;
}
.helper {
display: inline-block;
height: 100%;
vertical-align: middle;
}
img {
vertical-align: middle;
}
.leftbox {
margin: 0px auto;
height: 100%;
}
.rightbox {
margin: 0px auto;
height: 100%;
}
<div class="half-side">
<div class="leftbox">
<span class="helper"></span>
<img src="https://68.media.tumblr.com/avatar_65ce634bba10_128.png" />
</div>
</div><!--
--><div class="half-side">
<div class="rightbox">
<span class="helper"></span>
<img src="https://68.media.tumblr.com/avatar_65ce634bba10_128.png" />
</div>
</div>
Vertical centering problems are usually best solved with display: flex. See https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/

How to keep three div images on the same line?

I am trying to create three separate rounded images on the same line. I managed to get two in the correct position but I can't get the last one to move up into the correct line.
.wrap {
width: 100%;
}
.image-left {
content: url(https://s16.postimg.org/qm1wc2syd/alexandru_stavrica_166342.png);
height: 250px;
float: left;
padding-left: 10%;
}
.image-centre {
content: url(https://s23.postimg.org/57nxodezv/jorg_angeli_128760.png);
height: 250px;
margin-left: auto;
margin-right: auto;
}
.image-right {
content: url(https://s3.postimg.org/ejuuxd6n7/jay_wennington_2250_min.png);
height: 250px;
float: right;
padding-right: 10%;
}
<div class="wrap">
<div class="image-left"></div>
<div class="image-centre"></div>
<div class="image-right"></div>
</div>
There's probably a better way to do this, but here's one that works: https://jsfiddle.net/5ybLh6vy/
<div class="wrap">
<div class="image-left">
<img src="https://s16.postimg.org/qm1wc2syd/alexandru_stavrica_166342.png">
</div>
<div class="image-centre">
<img src="https://s23.postimg.org/57nxodezv/jorg_angeli_128760.png">
</div>
<div class="image-right">
<img src="https://s3.postimg.org/ejuuxd6n7/jay_wennington_2250_min.png">
</div>
</div>
.wrap {
width: 100%;
display: table;
}
.wrap img {
box-sizing: border-box;
width: 100%;
padding: 5px;
}
.image-left, .image-centre, .image-right {
display: table-cell;
width: 33%;
}
How about using the image tag and wrapping them around a div like this?
.wrap {
width: 100%;
}
.image-wrapper{
width: 33%;
display: inline-block;
text-align: center;
}
.image-wrapper>img{
height:250px;
}
<div class="wrap">
<div class="image-wrapper">
<img src='https://s16.postimg.org/qm1wc2syd/alexandru_stavrica_166342.png'>
</div>
<div class="image-wrapper">
<img src='https://s23.postimg.org/57nxodezv/jorg_angeli_128760.png'>
</div>
<div class="image-wrapper">
<img src='https://s3.postimg.org/ejuuxd6n7/jay_wennington_2250_min.png'>
</div>
</div>
Float all three of the divs right, make them width: 33.33% and box-sizing: border-box.
This will make three evenly spaced images floated inline.
If you want them all in a neat row you'll have to add float:left; to all of them and or to the .wrap class but you would have to add display:inline; to each image which I think is the best solution. Problem is if the the viewport isn't wide enough it will push to the next line.
.wrap {
width: 100%;
float: left;
}
.image-left {
content:url(https://s16.postimg.org/qm1wc2syd/alexandru_stavrica_166342.png);
height: auto;
max-width: 25%;
padding-left: 10%;
display:inline;
}
.image-centre {
content: url(https://s23.postimg.org/57nxodezv/jorg_angeli_128760.png);
max-width: 25%;
height:auto;
display:inline;
}
.image-right {
content:url(https://s3.postimg.org/ejuuxd6n7/jay_wennington_2250_min.png);
height: auto;
max-width: 25%;
display:inline;
padding-right: 10%;
}
<div class="wrap">
<div class="image-left"></div>
<div class="image-centre"></div>
<div class="image-right"></div>
</div>
You could assign float: left; for all of your images, and then set correct margins.

How do I center this line of text?

I have a 'contact' page with three icons laid out horizontally for 'phone', 'email', and 'facebook'. Below each icon is some text, like the phone number, email address, and facebook link.
They're all centered up, except the email address text is bumped to the right a bit. I can't figure out whats causing it. Everything else is centered. Its probably something obvious that I am overlooking.
#contact {
clear: both;
position: relative;
width: 100%;
float: left;
display: block;
}
#contact img {
width: 100%;
overflow: hidden;
}
#phone {
background: yellow;
width: 300px;
height: 30px;
display: block;
float: left;
}
#email {
background: cyan;
width: 300px;
height: 30px;
display: block;
float: left;
}
#fbc {
background: pink;
width: 300px;
height: 30px;
display: block;
float: left;
}
#contactcont {
display: block;
clear: both;
height: 350px;
width: 960px;
margin-left: auto;
Margin-right: auto;
}
<!--Contact-->
<div id="contact">
<img src="Images/contactbanner.jpg" alt="contactbanner">
</div>
<a name="contanch"></a>
<div id="contactcont">
<div id="phone">
<img src="Images/phone.jpg" alt="phone" width="300" height="195">
<br>
<h5 align="center">1-800-759-5275</h5>
</div>
<div id="email">
<img src="Images/email.jpg" alt="email" width="300" height="195">
<br>
<h5 align="center"><a href="mailto:sales#company.com">
sales#company.com</a></h5>
</div>
<div id="fbc">
<img src="Images/fbcont.jpg" alt="fbcont" width="300" height="195">
<br>
<h5 align="center">Like us on Facebook!</h5>
</div>
</div>
After a quick look at your css it doesn't look to me like you are using text-align. If you use text-align:center in your css for each icons parent div you should get the result you are looking for.

How to center align this image with the text?

I am trying to center the rounded image with the text, however I can not succeed to it.
What should I change to my code to do it?
https://jsfiddle.net/zxwz5739/
<div class="col-sm-6">
<div class="team-1-member">
<div class="round">
<center>
<img alt="Team Member" src="http://i.imgur.com/qIKR0Qt.gif">
</center>
</div>
<h2>John Doe</h2>
</div>
</div>
.team-1-member {
text-align: center;
margin-top: 48px;
}
.round {
border-radius: 50%;
overflow: hidden;
width: 150px;
height: 150px;
margin-bottom: 10px;
}
.round img {
display: block;
min-width: 100%;
min-height: 100%;
}
.team-1 h2 {
margin-bottom: 8px;
}
to .round add: display: inline-block;
For .round, change your margin-bottom: 10px; to margin: 0 auto 10px auto;.
I'd also suggest getting rid of your <center> tags. They're technically not supposed to be used anymore.
You can basically remove your outer div and center and change the image itself to display: inline-block.
New HTML code:
<div class="col-sm-6">
<div class="team-1-member">
<img alt="Team Member" src="http://i.imgur.com/qIKR0Qt.gif" class="round" />
<h2>John Doe</h2>
</div>
</div>
New CSS code:
.team-1-member {
text-align: center;
margin-top: 48px;
}
.round {
border-radius: 50%;
width:150px;
height:150px;
display: inline-block;
}
.team-1 h2 {
margin-bottom: 8px;
}
Result as jsfiddle.