I'm trying to fix when I shrink my website down to 768 pixels there seems to be too much whitespace on the left side, I am unable to work out where it is coming from and how I can fix it, I've tried to remove the default padding and margins, and changed the size of images, but that didn't seem to solve it. I will post some code. Any help would be appreciated.
{
margin: 0px;
padding: 0px;
}
div.item {
/* To correctly align image, regardless of content height: */
vertical-align: top;
display: inline-block;
/* To horizontally center images and caption */
text-align: center;
/* The width of the container also implies margin around the images. */
width: 120px;
position: relative;
left: 30%;
color: #f8d501;
}
img {
width: 100px;
height: 100px;
border: solid 5px #f8d501;
}
.caption {
/* Make the caption a block so it occupies its own line. */
display: block;
color: #f8d501;
}
div.item-1 {
/* To correctly align image, regardless of content height: */
vertical-align: top;
display: inline-block;
/* To horizontally center images and caption */
text-align: center;
/* The width of the container also implies margin around the images. */
width: 120px;
padding-top: 40px;
position: relative;
left: 30%;
color: yellow;
}
img {
max-width: 100%;
height: auto;
}
.caption-1 {
/* Make the caption a block so it occupies its own line. */
display: block;
color: #f8d501;
font-family: 'Verdana-bold';
}
h1 {
padding-top: 20px;
color: #fad700;
transform: rotate(-90deg);
font-size: 50px;
}
body {
background-color: #0d395e;
}
.logo-floatRight {
padding-left: 20px;
display: flex;
border: none;
max-width: 100%;
height: auto;
}
.logo-floatLeft {
padding-left: 20px;
display: inline-block;
border: none;
max-width: 100%;
height: auto;
padding: 10px;
}
.flex-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
padding-left: 35%;
max-width: 600px;
height: auto;
}
.logoHeader{
color: #f8d501;
font-family: "Franklin Gothic Heavy regular"
padding: 10px;
max-width: 100%;
height: auto;
}
.text{
color: #f8d501;
text-align: center;
padding-right: 30px;
}
.logo-floatLefts{
border: none;
width: 100%;
height: auto;
}
#media only screen and (max-width: 768px) {
img {
width: 60%;
}
.logoHeader{
font-size: 15px;
}
.flex-container{
width: 120px;
height: 120px;
}
.caption {
font-size: 12px;
}
.item {
font-size: 15px;
}
}
}
<div class="main">
<div class="showcase-content">
<div class="flex-container">
<img src="https://via.placeholder.com/150" class="logo-floatLeft" alt="logo">
<h2 class="logoHeader">LATIN<br>AMERICAN<br>FILM<br>FESTIVAL IN<br>AUSTRALIA</h2>
<img src="https://via.placeholder.com/150" class="logo-floatRight" alt="logo">
</div>
<div class="item">
BRAZIL
<img src="https://via.placeholder.com/150"/>
<span class="caption">LIFE IS A BITCH<br>Como e Cruel Viver Assim</span>
</div>
<div class="item">
CHILE
<img src="https://via.placeholder.com/150"/>
<span class="caption">BROKEN PANTIES<br>Colzones Ratos</span>
</div>
<div class="item">
COLOMBIA
<img src="https://via.placeholder.com/150"/>
<span class="caption">BAD LUCKY GOAT<br>El Dia De La Cabra</span>
</div>
<div class="item">
COSTA RICA
<img src="https://via.placeholder.com/150"/>
<span class="caption">THE GAZELLE'S DANCE<br>El Baile La Gacela </span>
</div>
<div class="item">
CUBA
<img src="https://via.placeholder.com/150"/>
<span class="caption">FALLEN GODS<br>Los Dioses Rotos</span>
</div>
<br>
<div class="item-1">
ECUADOR
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">QUIJOTES NEGROS<br>Quijotes Negros</span>
</div>
<div class="item-1">
EL SALVADOR
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE PATH OF THE SHADOWS<br>El Camino De Las Sombras</span>
</div>
<div class="item-1">
GAUTEMALA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">WHERE ALL ROADS END<br>Donde Acaban Los Caminos.</span>
</div>
<div class="item-1">
MEXICO
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">MARA'AKAME'S DREAM<br>El Sueno Del Mara'akame</span>
</div>
<div class="item-1">
PANAMA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">GRACE & SPLENDOUR<br>Donaire Y Esplendo</span>
</div>
<br>
<div class="item-1">
<h1> FREE<br>EVENT </h1>
</div>
<div class="item-1">
PARAGUAY
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE HEIRESSES<br>Las Herederas</span>
</div>
<div class="item-1">
PERU
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">OLD FRIENDS<br>Viejos Amigos</span>
</div>
<div class="item-1">
URUGUAY
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE POPES TOILET<br>El Bano Del Papa.</span>
</div>
<div class="item-1">
ARGENTINA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">MAN FANCING SOUTHEAST<br>Hombre Mirando al Sudeste</span>
</div>
<div class="text">
<h3>FIND OUT WHEN FESTIVAL IS COMING TO YOUR CITY AT<br>WWW.FACEBOOK.COM/LAFFAUSSIE</h3>
<img src="footer.png" class="logo-floatLefts" alt="logo">
</div>
</div>
</div>
I just removed your extra margin and padding both from the item,item-1, flex-container class, and add only vertical-align and text-align center. And there is no extra margin or padding on the left. all the content remains in the center. Hope it will solve your problem. I also removed img and flex-container class from the media queries.
{
margin: 0px;
padding: 0px;
}
div.item {
/* To correctly align image, regardless of content height: */
vertical-align: top;
display: inline-block;
/* To horizontally center images and caption */
text-align: center;
/* The width of the container also implies margin around the images. */
width: 120px;
position: relative;
color: #f8d501;
}
img {
width: 100px;
height: 100px;
border: solid 5px #f8d501;
}
.caption {
/* Make the caption a block so it occupies its own line. */
display: block;
color: #f8d501;
}
div.item-1 {
/* To correctly align image, regardless of content height: */
vertical-align: top;
display: inline-block;
/* To horizontally center images and caption */
text-align: center;
/* The width of the container also implies margin around the images. */
width: 120px;
padding-top: 40px;
position: relative;
color: yellow;
}
img {
max-width: 100%;
height: auto;
}
.caption-1 {
/* Make the caption a block so it occupies its own line. */
display: block;
color: #f8d501;
font-family: 'Verdana-bold';
}
h1 {
padding-top: 20px;
color: #fad700;
transform: rotate(-90deg);
font-size: 50px;
}
body {
background-color: #0d395e;
}
.logo-floatRight {
border: none;
max-width: 100%;
height: auto;
padding: 10px;
}
.logo-floatLeft {
border: none;
max-width: 100%;
height: auto;
padding: 10px;
}
.center-text {
text-align: center;
}
.flex-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
justify-content: center;
}
.logoHeader{
color: #f8d501;
font-family: "Franklin Gothic Heavy regular"
padding: 10px;
max-width: 100%;
height: auto;
}
.text{
color: #f8d501;
text-align: center;
padding-right: 30px;
}
.logo-floatLefts{
border: none;
width: 100%;
height: auto;
}
#media only screen and (max-width: 768px) {
.logoHeader{
font-size: 15px;
}
.caption {
font-size: 12px;
}
.item {
font-size: 15px;
}
}
<div class="main">
<div class="showcase-content">
<div class="flex-container">
<img src="https://via.placeholder.com/150" class="logo-floatLeft" alt="logo">
<h2 class="logoHeader">LATIN<br>AMERICAN<br>FILM<br>FESTIVAL IN<br>AUSTRALIA</h2>
<img src="https://via.placeholder.com/150" class="logo-floatRight" alt="logo">
</div>
<div class="center-text">
<div class="item">
BRAZIL
<img src="https://via.placeholder.com/150"/>
<span class="caption">LIFE IS A BITCH<br>Como e Cruel Viver Assim</span>
</div>
<div class="item">
CHILE
<img src="https://via.placeholder.com/150"/>
<span class="caption">BROKEN PANTIES<br>Colzones Ratos</span>
</div>
<div class="item">
COLOMBIA
<img src="https://via.placeholder.com/150"/>
<span class="caption">BAD LUCKY GOAT<br>El Dia De La Cabra</span>
</div>
<div class="item">
COSTA RICA
<img src="https://via.placeholder.com/150"/>
<span class="caption">THE GAZELLE'S DANCE<br>El Baile La Gacela </span>
</div>
<div class="item">
CUBA
<img src="https://via.placeholder.com/150"/>
<span class="caption">FALLEN GODS<br>Los Dioses Rotos</span>
</div>
</div>
<br>
<div class="center-text">
<div class="item-1">
ECUADOR
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">QUIJOTES NEGROS<br>Quijotes Negros</span>
</div>
<div class="item-1">
EL SALVADOR
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE PATH OF THE SHADOWS<br>El Camino De Las Sombras</span>
</div>
<div class="item-1">
GAUTEMALA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">WHERE ALL ROADS END<br>Donde Acaban Los Caminos.</span>
</div>
<div class="item-1">
MEXICO
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">MARA'AKAME'S DREAM<br>El Sueno Del Mara'akame</span>
</div>
<div class="item-1">
PANAMA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">GRACE & SPLENDOUR<br>Donaire Y Esplendo</span>
</div>
</div>
<br>
<div class="center-text">
<div class="item-1">
<h1> FREE<br>EVENT </h1>
</div>
<div class="item-1">
PARAGUAY
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE HEIRESSES<br>Las Herederas</span>
</div>
<div class="item-1">
PERU
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">OLD FRIENDS<br>Viejos Amigos</span>
</div>
<div class="item-1">
URUGUAY
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">THE POPES TOILET<br>El Bano Del Papa.</span>
</div>
<div class="item-1">
ARGENTINA
<img src="https://via.placeholder.com/150"/>
<span class="caption-1">MAN FANCING SOUTHEAST<br>Hombre Mirando al Sudeste</span>
</div>
</div>
<div class="text">
<h3>FIND OUT WHEN FESTIVAL IS COMING TO YOUR CITY AT<br>WWW.FACEBOOK.COM/LAFFAUSSIE</h3>
<img src="footer.png" class="logo-floatLefts" alt="logo">
</div>
</div>
</div>
The padding:0 and margin:0 in the start are for body, which I think you have forgot to write.
If that doesn't solve, check each section by commenting to see which section is bigger in width to leave the white spaces.
Related
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 2 years ago.
I'm trying to align multiple inline-blocks at the top of my page, but for reasons that are baffling to me, it's not working. The CSS could hardly be cleaner or less, but the top isn't aligning properly. I thought it could be a floating issue, but even after applying a clear:both it doesn't fix this.
Please see the program here:
https://jsfiddle.net/yezwocta/
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
Add vertical-align: top; to your .article CSS (the default is baseline):
#page {
text-align: center;
}
.article {
width: 350px;
height: 150px;
margin: 5px;
display: inline-block;
background-color: #fafafa;
vertical-align:top;
}
.article img {
float: left;
width: 150px;
height: 130px;
margin-top: 10px;
}
.content {
position: relative;
display: inline-block;
width: 170px;
height: 130px;
margin-top: 10px;
margin-left: 10px;
text-align: left;
}
.title {
font-size: 1.2rem;
}
.source {
font-size: 0.8rem;
position: absolute;
bottom: 0;
left: 0;
}
<div id="page">
<div class="article">
<a href="https://cnn.com" target="_blank">
<img alt="News" src="https://loremflickr.com/150/130/news?random=1">
<div class="content">
<span class="title">Cable News Network</span>
<span class="source">CNN</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.mozilla.org/en-US/firefox/new/" target="_blank">
<img alt="Firefox browser" src="https://loremflickr.com/150/130/browser?random=2">
<div class="content">
<span class="title">Get the Latest Firefox Browser</span>
<span class="source">Mozilla</span>
</div>
</a>
</div>
<div class="article">
<a href="https://www.kproxy.com/" target="_blank">
<img alt="kproxy" src="https://loremflickr.com/150/130/proxy?random=3">
<div class="content">
<span class="title">Surf the web anonymously and bypass filters</span>
<span class="source">kproxy</span>
</div>
</a>
</div>
</div>
I have been designing a website using html and css, for which i have made a footer.
the code for the footer is as follows:
footer {
color: white;
width: 100%;
height: 40px;
padding: 0;
display: block;
clear: both;
}
.footrow {
overflow: hidden;
background-color: #111;
display: block;
line-height: 18px;
background-image: url('../images/footer.jpg');
}
.footrow2 {
overflow: hidden;
background-color: #002c42;
display: block;
padding: 15px;
height: 48px;
}
.foot {
max-width: 1080px;
margin: 0 auto;
font-size: 11px;
}
.foot-p {
font-weight: 600;
color: #66e355 !important;
margin: 15px;
}
.half-width {
width: 50%;
float: left;
line-height: 1px;
}
.quarter-width {
width: calc(25% - 30px);
float: left;
padding: 20px;
}
#social2 {
display: block;
background-color: transparent;
float: left;
margin: 0 auto;
}
.sc-icn2 {
width: 50px;
height: 50px;
display: block;
margin-right: 5px;
margin-bottom: 5px;
float: left;
}
<footer>
<div class="footrow">
<div class="foot">
<div class="quarter-width">
<p style="color:#fff;">Address</p>
<hr>
<div>
Science & Technology University
<hr> Phone: 02-7458745
<hr> Email: registrar#abc.gmail.com
</div>
</div>
<div class="quarter-width">
<p style="color:#fff;">Quick Links</p>
<hr>
Link 1<br>
Link 2<br>
Link 3<br>
</div>
<div class="quarter-width">
<p style="color:#fff;">Follow Us</p>
<hr>
<div id="social2">
<div class="sc-icn2">
<img src="images/social/facebook.png" width="50px" height="50px" alt="facebook" title="fb">
</div>
<div class="sc-icn2">
<img src="images/social/twitter.png" width="50px" height="50px" alt="twitter" title="#board">
</div>
<div class="sc-icn2">
<img src="images/social/instagram2.png" width="50px" height="50px" alt="instagram" title=" Photography">
</div>
</div>
</div>
<div class="quarter-width">
<p style="color:#fff;">Report</p>
<hr>
<a style="cursor:pointer;" onclick="feedClick('bug')">Found
a Bug</a><br>
<a style="cursor:pointer;" onclick="feedClick('feed')">Feedback</a><br>
<a style="cursor:pointer;" onclick="feedClick('feature')">Request feature</a><br>
</div>
</div>
</div>
<div class="footrow2">
<div class="foot">
<div class="half-width">
<p class="foot-p">©- 2018 | All rights reserved</p>
</div>
<div class="half-width">
<p style="float:right !important;" class="foot-p">Developed & Maintained By <a style="color:orange" href="https://www.facebook.com/abc"><strong>SK Biswas</strong></a></p>
</div>
</div>
</div>
</footer>
The footer has two parts. one is within class "footrow" and another is within "footrow2". footrow will take position above footrow2. the problem is the height of the content of footrow2 class is taking different height for different pages. Is there any way to make it of a fixed height?
If you want to give any element 100% width of your page better use the vw instead of % as:
width: 10vw;
vw stands for viewport width and 10 means 100%. It will set the complete width on all devices.
I am trying to align an icon with some text like this:
however it comes out like this:
.percent {
float: right;
display: inline-block;
position: relative;
}
.card-icon {
float: left;
}
<div class="col-md-4">
<div class="card">
<div class="card-header" id="blue">
<p class="text-center"> Self Managed <img src="app/assets/images/star.png" alt=""> </p>
</div>
<p class="percent"> <img class="card-icon" src="app/assets/images/self.png" alt="Smiley face"> 1% </p>
EDIT ****
With the last answer provided it shows up like this:
.card-icon {float: left;margin-right:10px; }
<style type="text/css">
</style>
<div class="col-md-4">
<div class="card">
<div class="card-header" id="blue">
<p class="text-center"> Self Managed <img src="app/assets/images/star.png" alt=""> </p>
</div>
<div class = "percent">
<img class="card-icon" src="app/assets/images/self.png" alt="Smiley face">
<div class="card-txt"> 1% </div>
</div>
</div>
</div>
Try to use inline-block instead of floats:
.card-icon {
display: inline-block;
vertical-align: middle;
position: relative;
z-index: 1;
}
.card-icon:after {
content: "=";
position: absolute;
right: -16px;
top: 50%;
transform: translateY(-50%);
}
.percent .card-txt:nth-of-type(1) {
text-align: center;
}
.card-txt {
display: inline-block;
vertical-align: middle;
text-align: center;
margin-left: 24px;
}
.block {
display: block;
}
<div class="col-md-4">
<div class="card">
<div class="card-header" id="blue">
<p class="text-center"> Self Managed <img src="app/assets/images/star.png" alt=""> </p>
</div>
<div class="percent">
<img class="card-icon" src="app/assets/images/self.png" alt="Smiley face">
<div class="card-txt">
<span class="block">1%</span>
<span class="block">service tax + VAT</span>
</div>
</div>
</div>
</div>
Sometimes the best solution is an old solution. Using HTML tables allows you to control vertical height with a high level of browser support, and backwards compatibility. Using this approach also make the element responsive. Other solutions that adopt the relative/absolute position method can suffer when resizing browser window size.
table {
margin: 0 auto;
border: 1px solid blue;
}
table tr td {
padding: 10px;
width: 100px;
text-align: center;
vertical-align: middle;
position: relative;
}
table tr .number-cell {
padding-top:10px;
width: 80px;
}
table tr .number-cell .value {
margin-top: 4px;
font-size: 42px;
}
table tr .number-cell .sub-heading {
background: grey
}
table tr .equal-cell {
width: 0px;
}
table tr td img {
width: 100%;
}
<div>
<h1>MY WEBSITE</h1>
<table>
<tr>
<td class="image-cell">
<img src="https://www.fillmurray.com/100/100"/>
</td>
<td class="equal-cell">
<span class="equal">=</span>
</td>
<td class="number-cell">
<div class="value">1%</div>
<div class="sub-heading">service fee</div>
</td>
</tr>
</table>
</div>
.card-icon {float: left;position:relative;z-index:1; }
.card-icon:after {content:"=";position:relative; left:25px;}
.percent .card-txt:nth-of-type(1) {text-align:center;position:relative; left:-55px;}
.card-txt {text-align:center; width:400px;background:#ddd;}
<div class="col-md-4">
<div class="card">
<div class="card-header" id="blue">
<p class="text-center"> Self Managed <img src="app/assets/images/star.png" alt=""> </p>
</div>
<div class = "percent">
<img class="card-icon" src="app/assets/images/self.png" alt="Smiley face">
<div class="card-txt"> 1% </div>
<div class="card-txt"> service tax + VAT </div>
</div>
</div>
</div>
If you want more controle you can use flex styling. An example:
.card {
position: relative;
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
width: 500px;
}
.card-header {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 10px;
background-color: blue;
color: white;
font-size: 24px;
}
.card-content {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
background-color: gray;
}
.card-header > img {
position: absolute;
right: 0;
width: 50px;
height: 50px;
}
<div class="card">
<div class="card-header">
<span>Self Managed</span>
<img src="app/assets/images/star.png" alt="">
</div>
<div class="card-content">
<img class="card-icon" src="app/assets/images/self.png" alt="Smiley face">
<span>1%</span>
</div>
</div>
I'm trying to draw a dotted line between some of my elements without success; I'm trying to accomplish something like the following:
I've looked at a few tutorials to write a line between the elements using the ::after pseudo-element, but I don't see anything happening.
.container {
width: 1066px;
margin: 0 auto;
}
.services {
text-align: center;
max-width: 1080px;
padding: 80px 0;
position: relative;
}
.services .step {
display: inline-block;
width: 152px;
height: 100px;
margin: 50px;
vertical-align: text-top;
}
.services .step .first {
float: right;
}
.services .icons {
background: url("https://www.icracked.com/themes/icracked/images/steps-line.png") repeat-x;
}
<div class="services container">
<div class="step first">
<strong>PASO 1</strong>
<br>
<p>Pon el codigo postal donde te encuentres</p>
</div>
<div class="step">
<strong>PASO 2</strong>
<br>
<p>Dinos qual es el problema</p>
</div>
<div class="step">
<STRONG>PASO 3</STRONG>
<br>
<p>Relajate, nuestro tecnico esta de camino</p>
</div>
<div class="step last">
<STRONG>PASO 4</STRONG>
<br>
<p>Voilà! En menos de una hora tienes el movil arreglado!</p>
</div>
<div class="icons">
<div class="step first">
<img src="http://via.placeholder.com/50x50" alt="" height="50" width="50"></div>
<div class="step">
<img src="http://via.placeholder.com/50x50" alt="" height="50" width="50"></div>
<div class="step">
<img src="http://via.placeholder.com/50x50" alt="" height="50" width="50"></div>
<div class="step last">
<img src="http://via.placeholder.com/50x50" alt="" height="50" width="50"></div>
</div>
</div>
http://jsfiddle.net/zhpmahnq/187/
You could try using display: flex; and creating a dotted border on only the top or bottom of a span between images.
.wrapper {
align-items: center;
display: flex;
justify-content: space-between; /* not necessary */
}
.dots {
border-top: 1px dotted black;
width: 100%;
}
https://jsfiddle.net/zhpmahnq/191/
I have a gallery with image, title and description.
The image uses float: left; while the title and description stack to the right of it.
https://jsfiddle.net/aeuz0n8g/
I'm looking for a way to use display: inline-block; on the image instead of float, but the description will not stack under the title.
https://jsfiddle.net/5jbswg39/
.item-container {
display: inline-block;
width: 300px;
min-height: 90px;
margin: 0.2em;
padding: 0.5em;
vertical-align: top;
text-align: left;
background: white;
}
.img-wrapper {
float: left;
max-width: 50px;
max-height: 60px;
height: 60px;
margin: 0.6em 1em 0 0;
text-align: center;
background: gray;
}
.img-wrapper img {
width: auto;
max-width: 50px;
max-height: 50px;
vertical-align: top;
}
.title {
max-width: 275px;
font-size: 1.05em;
font-weight: 700;
padding: 0.3em 0;
text-align: left;
vertical-align: top;
}
.description {
max-width: 275px;
font-size: .9em;
line-height: 1.4em;
text-align: left;
vertical-align: top;
}
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div>
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
Note: this is an explanation of why I'm looking to use inline-block instead of float.
For an unknown reason, when using my full site in Chrome, on 720p resolution, the Title will overlap the Image. But not in Firefox, IE or 1080p.
I'm only able to show a screenshot, since it's a local site being developed on my computer. But the JSFiddle link is the exact code being used. Though I cannot replicate the overlap in JSFiddle.
I cannot debug the problem, because when I inspect element and touch any of the css, the titles reset back to normal, no longer overlapping. So I thought I would try alternative css to achieve the same layout and see if it removes the problem. I thought it might be a float rendering glitch with chrome.
Wrap the title and text in a new element, set that to inline-block and contain it's width so it will fit on the same row.
.info {
width: calc(100% - (50px + 1em));
display: inline-block;
vertical-align: top;
}
Here's a demo.
.item-container {
display: inline-block;
width: 300px;
min-height: 90px;
margin: 0.2em;
padding: 0.5em;
vertical-align: top;
text-align: left;
background: white;
}
.img-wrapper {
display: inline-block;
max-width: 50px;
max-height: 60px;
height: 60px;
margin: 0.6em 1em 0 0;
text-align: center;
background: gray;
}
.img-wrapper img {
width: auto;
max-width: 50px;
max-height: 50px;
vertical-align: top;
}
.title {
display: inline-block;
max-width: 275px;
font-size: 1.05em;
font-weight: 700;
padding: 0.3em 0;
text-align: left;
vertical-align: top;
}
.description {
display: inline-block;
max-width: 275px;
font-size: .9em;
line-height: 1.4em;
text-align: left;
vertical-align: top;
}
/* added this */
.info {
width: calc(100% - (50px + 1em));
display: inline-block;
vertical-align: top;
}
<!-- Item 1 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
<!-- Item 2 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
<!-- Item 3 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
You could also make this a flex layout with the default flex-direction: row between the left/right sections, and a flex-direction: column for the title/text.
.item-container {
display: inline-flex;
width: 300px;
min-height: 90px;
margin: 0.2em;
padding: 0.5em;
vertical-align: top;
text-align: left;
background: white;
}
.img-wrapper {
max-width: 50px;
max-height: 60px;
height: 60px;
margin: 0.6em 1em 0 0;
text-align: center;
background: gray;
}
.img-wrapper img {
width: auto;
max-width: 50px;
max-height: 50px;
vertical-align: top;
}
.title {
font-size: 1.05em;
font-weight: 700;
padding: 0.3em 0;
text-align: left;
}
.description {
max-width: 275px;
font-size: .9em;
line-height: 1.4em;
text-align: left;
}
.info {
flex-grow: 1;
display: flex;
flex-direction: column;
}
<!-- Item 1 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
<!-- Item 2 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
<!-- Item 3 -->
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div><!--
--><div class="info">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
If you're open to using display: flex you could wrap the title and description in a div and do this.
<div class="item-container">
<div class="img-wrapper">
<a href="#">
<img src="https://i.imgur.com/Bt0p3FG.jpg" width="70" height="70">
</a>
</div>
<div class="content-wrapper">
<div class="title">
Title
</div>
<div class="description">
Description description description description description description.
</div>
</div>
</div>
and then
.item-container {
display: flex;
width: 300px;
min-height: 90px;
margin: 0.2em;
padding: 0.5em;
vertical-align: top;
text-align: left;
background: white;
}
You can optionally add display: flex to the content-wrapper class as well like this
.content-wrapper {
display: flex;
flex-direction: column;
}
FWIW I tested this on my MBP with the resolution changed and nothing overlapped for me.