Fill empty spaces with sibling elements using CSS - html

I'm trying to create a mosaic of images, but i'm having a hard time positioning them.
The elements i'm using are floated left, have different sizes and are following a specific display order. Is there a way of doing it using only CSS?
This is how i want it to be:
And this is how it is right now:
Finally, what i've coded so far:
span {
font-family: Arial;
}
.mosaic_wrapper {
float: left;
clear: both;
overflow: hidden;
width: 100%;
max-width: 1075px;
margin-bottom: 50px;
}
.mosaic_wrapper div {
float: left;
width: 100%
}
.mosaic_wrapper div .image_wrapper {
width: 48%;
height: 400px;
float: left;
position: relative;
margin: 0.5% 0.5%;
overflow: hidden;
}
.mosaic_wrapper div .image_wrapper a {
width: 100%;
height: 100%;
float: left;
}
.mosaic_wrapper div .image_wrapper a:hover img {
transform: scale(1.1);
}
.mosaic_wrapper div .image_wrapper a:hover span.bg {
opacity: 0.5;
}
.mosaic_wrapper div .image_wrapper a img {
float: left;
width: 100%;
height: 100%;
transition: transform 0.4s ease-in-out;
backface-visibility: hidden;
filter: grayscale(0%);
}
.mosaic_wrapper div .image_wrapper a span.bg {
background-image: linear-gradient(to bottom, #999999, #222222);
opacity: 0;
position: absolute;
width: 100%;
height: 100%;
top: 0;
z-index: 5;
display: block;
transition: opacity 0.3s ease;
}
.mosaic_wrapper div .image_wrapper a div.text {
color: #ffffff;
position: absolute;
font-size: 1.7rem;
bottom: 0;
z-index: 10;
padding: 20px;
box-sizing: border-box;
width: 100%;
}
.mosaic_wrapper div .image_wrapper a div.text span {
float: left;
width: 100%;
}
.mosaic_wrapper div .image_wrapper a div.text span.parent {
font-size: 14px;
text-transform: uppercase;
}
.mosaic_wrapper div .image_wrapper a div.text span.dept {
font-size: 50px;
font-weight: bold;
line-height: 1.1;
}
.mosaic_wrapper div .image_wrapper a div.text span.desc {
font-size: 14px;
line-height: 1.2;
}
<div class="mosaic_wrapper">
<div>
<div class="image_wrapper" style="width: 58%;">
<a href="#">
<img src="http://placehold.it/623x400">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
<div class="image_wrapper" style="width: 40%;height: 800px;">
<a href="#">
<img src="http://placehold.it/430x800">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
<div class="image_wrapper" style="width: 28%;">
<a href="#">
<img src="http://placehold.it/300x400">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
<div class="image_wrapper" style="width: 29%;">
<a href="#">
<img src="http://placehold.it/300x400">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
<div class="image_wrapper" style="width: 100%;">
<a href="#">
<img src="http://placehold.it/1075x400">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
</div>
</div>
Can someone please help?
Thanks in advance!

Add a float:right to the 430x800 mosaic;
<div class="image_wrapper" style="width: 40%;height: 800px;float:right">
<a href="#">
<img src="http://placehold.it/430x800">
<div class="text">
<span class="parent">Test</span>
<span class="dept">Test</span>
<span class="desc">Test</span>
</div>
<span class="bg"></span>
</a>
</div>
Alternatively you can add an id attribute to the 430x800 mosaic like id="rightMosaic"and create this style for it:
.mosaic_wrapper div .image_wrapper#rightMosaic{
float: right;
}
And of corse remove it from the inline style

I would use flex rows and columns to lay this out. Adjusted your image dimensions a little so everything will line up
* {
margin:0;padding:0;box-sizing:border-box;
}
.flex {
display: flex;
}
.col {
flex-direction: column;
}
img {
max-width: 100%;
display: block;
}
<div class="flex" style="margin: 0 0 12px;">
<div class="flex col" style="margin: 0 12px 0 0;">
<div style="margin: 0 0 12px 0;">
<img src="http://placehold.it/612x400">
</div>
<div class="flex">
<div style="margin: 0 12px 0 0;">
<img src="http://placehold.it/300x400">
</div>
<div>
<img src="http://placehold.it/300x400">
</div>
</div>
</div>
<div>
<img src="http://placehold.it/430x812">
</div>
</div>
<div>
<img src="http://placehold.it/1054x400">
</div>

Related

Inline-block top align issue; blocks seemingly randomly aligned [duplicate]

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>

How do I make p appear on hover ONTOP of an image?

I know the question of overlapping has been answered multiple times, however, I'm trying to place the text on top of the image centred once hovered.
I tried z-index, I tried relative and absolute, decided I'd ask for help.
.flex-container {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
margin: 0;
padding-left: 7%;
padding-right: 7%;
padding-top: 25px;
padding-bottom: 50px;
justify-content: center;
}
.flex-container div {
margin: 0;
position: relative;
margin-bottom: -5px;
font-size: medium;
text-align: center;
z-index: 0;
}
.flex-container div:hover {
filter: brightness(50%);
}
.flex-container div p {
display: none;
}
.flex-container div:hover p {
position: absolute;
color: black;
z-index: 1;
text-align: center;
}
<div>
<a href="Printing/menus.html">
<img src="../Images/menus-01.png" alt="Printing" style="width:100%; height:auto;"/>
</a>
<p>Menus</p>
</div>
You should have set the text CSS first and just then get the hover to show the styles, also, you forgot to set the container styles on your code.
See if that's what you want :
HTML :
<div class="container">
<img src="../Images/menus-01.png" alt="Image" style="width:100%;">
<div class="topTxt">Text on Center/div>
</div>
CSS :
.container {
position: relative;
text-align: center;
}
.topTxt {
position: absolute;
display: none;
top: 0;
left: 50%;
transform: translate(-50%, 0%);
}
.container:hover .topTxt {
display: block;
}
OR use JavaScript :
document.getElementsByClass("container").addEventListener("mouseover", function() {
document.getElementsByClass("topTxt").style.display = "block";
});
Get the following snippet to better view of what you requested :
#container {
max-width: 900px;
margin: 0 auto;
padding: 5px;
font-size: 0;
list-style: none;
background-color: #444;
}
#container li {
display: inline-block;
width: 25%;
vertical-align: middle;
box-sizing: border-box;
margin: 0;
padding: 0;
}
.container-cells {
margin: 5px;
box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
display: block;
position: relative;
overflow: hidden;
}
.imgs {
display: block;
width: 100%;
height: auto;
border: none;
filter: brightness(100%);
transition: all 0.3s;
}
#container li:hover .imgs {
filter: brightness(50%);
}
.overlay {
position: absolute;
display: block;
top: 0;
left: 0;
width: 100%;
height: 0px;
margin: auto;
background: #000;
background-size: 50px 50px;
transition: all 0.3s;
}
#container li:hover .overlay {
height: 30px;
}
.title {
display: block;
padding: 5px 30px;
box-sizing: border-box;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 40px;
text-align: center;
font-size: 18px;
color: white;
opacity: 0;
transform: translateY(-20px);
transition: all .3s;
}
#container li:hover .title {
transform: translateY(0px);
opacity: 0.9;
}
#media (max-width: 9000px) {
#container li {
width: 25%;
}
}
#media (max-width: 700px) {
#container li {
width: 33.33%;
}
}
#media (max-width: 550px) {
#container li {
width: 50%;
}
}
<ul id="container">
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
<li>
<a class="container-cells" href="#">
<img class="imgs" src="https://www.madpaws.com.au/wp-content/uploads/2019/02/Raise-Your-Kitten-to-Use-the-Litter-Box-300x200.jpg">
<span class="overlay"></span>
<span class="title">Hello World !</span>
</a>
</li>
</ul>
You just need to put the text before the image, as the image will be the background either way, just add the the text before, then the image and the text will be siblings, not parent and child, so the effect of hover won't affect the child, therefore, the text color will remain without having the filter applied to it.
Maybe the below is what you're looking for?
How to put text over images in html?
The answer suggests using a "div" tag rather than an "img" tag. Here is an example:
.image {
width:400px;
height:400px;
background-image: url(http://lorempixel.com/output/cats-q-c-640-480-4.jpg);
background-size:cover;
}
<div class="image">Text on top of image</div>

Cannot get text centered in a div

Could somebody help me with this HTML to make the <h1> and <h2> texts centrify, because I have lost it a bit on this.
<div class="container-fluid">
<a href="http://www.pagename.com" style="text-decoration: none; color: black">
<div class="pull-left" style="top: 270 px">
<img src="pic1.gif" alt="Paradise" width="215px" height="215px"/>
</div>
<div style="position: absolute; width: 100%; text-align: center">
<h1 style="font-size: 7vw; position: relative; top: 2.5vh">PAGENAME.COM</h1>
<h2 style="font-size: 2.3vw"SLOGAN FOR THE WEBSITE</h2>
</a>
</div>
<div class="pull-right" style="margin-left: 1vw";>
<img src="pic2.gif" alt="Beach" width="215px" height="215px" />
</div>
Is this what you need?
https://jsfiddle.net/scorpio777/k99ywpng/6/
CSS
h1 {
font-size: 7vw;
position: relative;
top: 0.5vh
}
h2 {
font-size: 2.3vw
}
.container-fluid {
width: 100%;
position: relative;
}
.pull-left {
vertical-align: top;
display: inline;
position: absolute;
left: 0;
}
.pull-right {
height: 215px;
vertical-align: top;
display: inline;
position: absolute;
right: 0;
}
.center {
display: inline;
position: absolute;
width:100%;
text-align:center;
z-index: 2;
}
HTML
<div class="container-fluid">
<a href="http://www.pagename.com" style="text-decoration: none; color: black">
<div class="pull-left">
<img src="pic1.gif" alt="Paradise" width="215px" height="215px"/>
</div>
<div class="center">
<h1>PAGENAME.COM</h1>
<h2>SLOGAN FOR THE WEBSITE</h2>
</div>
</a>
<div class="pull-right">
<img src="pic2.gif" alt="Beach" width="215px" height="215px" />
</div>
</div>
Try this:
CSS
.your-element {
display: flex !important;
flex-flow: row wrap !important;
justify-content: center !important;
}

Why is all content on my home page overflowing the body border? [duplicate]

This question already has answers here:
What is a clearfix?
(10 answers)
Closed 7 years ago.
On my home page Kendall_Gregory.html, my body border is ignoring the contents in the body and setting an arbitrary border around the page. It ignores every image that is on the page and the divs around them. The same code works on other pages and i can't figure out why this is the exception.
https://jsfiddle.net/hgaLsaz6/3/
HTML
<div>
<a href="Html/MenuPage.html">
<img id="topMenu" src="http://s4.postimg.org/7636jv04p/menu_Top.png">
</a>
</div>
<img id="headerImage" src="http://s16.postimg.org/uqbzk51yd/Header.png">
<div class ="card">
<div class="no-hover">
<!-- <span class = "caption"> Fade </span> -->
<img class="left Fade" src="http://s16.postimg.org/monr28j6t/Fade_Mag.png">
<!-- hover image -->
</div>
<div class="on-hover">
<a href="Html/Fade.html">
<img class="left Fade" src="http://s21.postimg.org/o0f1chw13/Xenia_Lally_Hover.png">
</a>
</div>
</div>
<!-- GE -->
<div class ="card">
<div class="no-hover">
<!-- <span class = "caption"> GE </span> -->
<img class="whiteOverlay right GE" src="http://s16.postimg.org/6vislrw9x/image.png">
</div>
<div class="on-hover">
<a href="Html/GE.html">
<img class="whiteOverlay right GE" src="http://s21.postimg.org/6yhlwnrs7/GE_hover.png">
</a>
</div>
</div>
<!-- Kaleidoscope -->
<div class ="card">
<div class="no-hover">
<img class="left KALEIDOSCOPE " src="http://s16.postimg.org/5fcc0qzol/KALEIDOSCOPE_Thumb.png">
</div>
<div class="on-hover mt100">
<a href="Html/Pantene.html">
<img class="left KALEIDOSCOPE" src="http://s16.postimg.org/7q5c7t44l/KALEIDOSCOPE_Thumb_hover.png">
</a>
</div>
</div>
<!-- AOHH -->
<div class ="card">
<div class="no-hover">
<img class="right ArtofHealthyHair" src="http://postimg.org/image/n7subiald/">
</div>
<div class="on-hover">
<a href="Html/AOHH.html">
<img class=" right ArtofHealthyHair" src="http://s21.postimg.org/u56jpto4n/Artof_Healthy_Hair_Hover.png">
</a>
</div>
</div>
<!-- Nexxus -->
<div class ="card mt100">
<div class="no-hover mt100">
<img class=" left Nexxus" src="http://s16.postimg.org/e05nrx9ut/Nexxus.png">
</div>
<div class="on-hover mt100">
<a href="Nexxus.html">
<img class="left Nexxus" src="http://s21.postimg.org/g00qo0f3b/Nexxus_Hover.png">
</a>
</div>
</div>
<!-- Covergirl -->
<div class ="card">
<div class="no-hover">
<img class="whiteOverlay right CoverGirl" src="http://s16.postimg.org/lh9ta0t2d/Cover_Girl.png">
</div>
<div class="on-hover">
<a href="Html/CoverGirlByKendallG.html">
<img class="whiteOverlay right CoverGirl" src="http://s21.postimg.org/6n05jwbc7/Cover_Girl_Hover.png">
</a>
</div>
</div>
<!-- PRTR -->
<div class ="card">
<div class="no-hover">
<img class="whiteOverlay left PRTR" src="http://s16.postimg.org/ee6zrityd/PRTR.png">
</div>
<div class="on-hover">
<a href="Html/RTR.html">
<img class="whiteOverlay left PRTR" src="http://s21.postimg.org/edbj2s31j/RTR_Hover.png">
</a>
</div>
</div>
<!-- Pantene -->
<div class ="card">
<div class="no-hover">
<img class="whiteOverlay right Pantnene" src="http://s16.postimg.org/3xqvp6uxx/Pantnene.png">
</div>
<div class="on-hover">
<a href="Html/Pantene.html">
<img class="whiteOverlay right Pantnene" src="http://s16.postimg.org/wia0c5rmt/WIOL_Hover.png">
</a>
</div>
</div>
CSS
body{
margin: 0px;
border: black 10px solid;
font-family: 'brandon_grotesque_regularRg', Arial, sans-serif;
line-height: normal;
}
a{
text-decoration: none;
color: black;
}
#topMenu{
right: 20px;
position: fixed;
letter-spacing: 4px;
z-index: 24;
-webkit-font-feature-settings: "kern";
-moz-font-feature-settings: "kern";
-moz-font-feature-settings: "kern=1";
}
.MenuBar{
text-align: center;
width: 65%;
margin:17 auto;
text-decoration: none;
letter-spacing: 2px;
-webkit-font-feature-settings: "kern";
-moz-font-feature-settings: "kern";
-moz-font-feature-settings: "kern=1";
}
.consocials{
bottom: 40;
margin-left: 70px;
margin-right: 70px;
width: 80%;
text-decoration: none;
}
.consocials:hover{
border-bottom:solid black 2px;
padding-bottom: 20px;
text-decoration: none;
color: black;
}
.socials{
margin-right: 20px;
margin-left: 20px;
color: black;
text-decoration: none;
text-transform: uppercase;
}
.socials:hover{
border-bottom:solid black 2px;
padding-bottom: 15px;
text-decoration: none;
color: black;
}
.socials:active{
text-decoration: none;
color: black;
}
.center{
text-align: center;
margin: 0 auto;
}
.left{
float: left;
margin-left: 70px;
}
.right{
float: right;
margin-right: 70px;
}
.rightNoMargin{
float: right;
}
.bottom{
bottom: 30px;
}
.hide{
display: none;
}
.m0a{
margin: 0 auto;
}
.m10a{
margin: 10 auto;
}
.h100{
height: 100%;
}
.w100{
width: 100%;
}
.w85{
width: 85%;
}
.w50{
width: 50%;
}
.w49{
width: 49%;
}
.w40{
width: 40%;
}
.mb200{
margin-bottom: 200px;
}
.mb100{
margin-bottom: 100px;
}
.pb30{
padding-bottom: 30px;
}
.FloatL{
float: left;
}
.FloatR{
float: right;
}
.tAc{
text-align: center;
}
.iLb{
display: inline-block;
}
.m3{
margin-top: 3px;
}
.h90{
height: 90%;
}
.h850p{
height: 850px;
}
.vA{
vertical-align: center;
height: 100%;
}
.h75{
height: 60%
}
.pl20p{
padding-left: 19%;
}
.pR100px{
padding-right: 75px;
}
.w450{
width: 450px;
}
.absolute{
position: absolute;
}
.relative{
position: relative;
}
.mnh100{
min-height: 100px;
}
.mt100px{
margin-top: 100px;
}
.mt200px{
margin-top: 200px;
}
.h700{
height: 700px;
}
.h800{
height: 800px;
}
.w89{
width: 89%;
}
.mT20{
margin-top: 20%;
}
.mt50p{
margin-top: 50%;
}
The reason your border isn't wrapping the image elements is because the image elements are floated and the container hasn't been cleared.
Anytime you float an image or any other object you take it out of the normal flow. This means that the parent container doesn't even know it exists.
There are several ways to address this issue – known as clearfix methods. In this case I've used the overflow property. Add overflow: auto to the container divs.
.no-hover {overflow: auto;}
.on-hover {overflow: auto;}
I tested this code and it solves the problem.
DEMO
Just keep in mind that when using the overflow property you can have different values (auto, hidden, scroll) each of which will have a different effect when content overflows the container. To understand what each value does you can refer to this article: MDN - CSS Overflow Property
Hope this helps. Good luck!

How to box with div the propper way?

I am often using div to box in information but I have notice that the wrapping box might sometimes not fill out the space and this leads to elements from other wrappers entering the box area.
For example :
<div>
<div style="length:150px;">my info1</div>
<div style="length:50px;">my Info2</div>
</div>
Take a look at this example
.topic {
width: 500px;
background-color: green;
display: block;
}
.topic .tInfo {
float: left;
width: 460px;
background-color: blue;
}
.topic .tName {
width: 460px;
background-color: brown;
}
.topic .tTime {
width: 460px;
background-color: lime;
}
.topic .tUImgLnk {
width: 40px;
height: 40px;
float: left;
position: relative;
background: red;
}
.topic .tUImgLnk .tUImg {
margin: 0px auto;
display: block;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
position: absolute;
}
<div class="topic" data-reactid=".24rl768raww.$0">
<div class="tUImgLnk" data-reactid=".24rl768raww.$0.0">
<a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.0.0">
<img class="tUImg" src="" data-reactid=".24rl768raww.$0.0.0.0">
</a>
</div>
<div class="tInfo" data-reactid=".24rl768raww.$0.1">
<div class="tName" data-reactid=".24rl768raww.$0.1.0"><a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.1.0.0">Carl</a>
</div>
<div class="tTime" data-reactid=".24rl768raww.$0.1.1"><span data-reactid=".24rl768raww.$0.1.1.0">2015-02-20 18:43:03</span>
</div>
</div>
</div>
<div class="topic" data-reactid=".24rl768raww.$0">
<div class="tUImgLnk" data-reactid=".24rl768raww.$0.0">
<a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.0.0">
<img class="tUImg" src="" data-reactid=".24rl768raww.$0.0.0.0">
</a>
</div>
<div class="tInfo" data-reactid=".24rl768raww.$0.1">
<div class="tName" data-reactid=".24rl768raww.$0.1.0"><a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.1.0.0">Carl</a>
</div>
<div class="tTime" data-reactid=".24rl768raww.$0.1.1"><span data-reactid=".24rl768raww.$0.1.1.0">2015-02-20 18:43:03</span>
</div>
</div>
</div>
I have used <br style="clear:both"/> at the end of each wrapper box but is this really the best way to go?
This is happenning because you don't have a wrapper , and the elements are liberaly floating;
in the below snippet I wrapped your elements in rows with article selector and cleared floats:
.topic {
width: 500px;
background-color: green;
display: block;
}
.topic .tInfo {
float: left;
width: 460px;
background-color: blue;
}
.topic .tName {
width: 460px;
background-color: brown;
}
.topic .tTime {
width: 460px;
background-color: lime;
}
.topic .tUImgLnk {
width: 40px;
height: 40px;
float: left;
position: relative;
background: red;
}
.topic .tUImgLnk .tUImg {
margin: 0px auto;
display: block;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
position: absolute;
}
article:after {
content: "";
display: table;
clear: both;
}
<article>
<div class="topic" data-reactid=".24rl768raww.$0">
<div class="tUImgLnk" data-reactid=".24rl768raww.$0.0">
<a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.0.0">
<img class="tUImg" src="" data-reactid=".24rl768raww.$0.0.0.0">
</a>
</div>
<div class="tInfo" data-reactid=".24rl768raww.$0.1">
<div class="tName" data-reactid=".24rl768raww.$0.1.0"><a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.1.0.0">Carl</a>
</div>
<div class="tTime" data-reactid=".24rl768raww.$0.1.1"><span data-reactid=".24rl768raww.$0.1.1.0">2015-02-20 18:43:03</span>
</div>
</div>
</div>
<article>
</article>
<div class="topic" data-reactid=".24rl768raww.$0">
<div class="tUImgLnk" data-reactid=".24rl768raww.$0.0">
<a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.0.0">
<img class="tUImg" src="" data-reactid=".24rl768raww.$0.0.0.0">
</a>
</div>
<div class="tInfo" data-reactid=".24rl768raww.$0.1">
<div class="tName" data-reactid=".24rl768raww.$0.1.0"><a title="Carl" target="_blank" href="http://www.bradspel.net" data-reactid=".24rl768raww.$0.1.0.0">Carl</a>
</div>
<div class="tTime" data-reactid=".24rl768raww.$0.1.1"><span data-reactid=".24rl768raww.$0.1.1.0">2015-02-20 18:43:03</span>
</div>
</div>
</div>
</article>