Line up Text to top of Image in divs - css

I'd like to line up the text to the top of the images in my divs.
Currently the title: Webinar, Blog, etc are sitting below the top of the squares. I have a style in there: vertical-align: top; but it's not aligning to the top of the square.
See my Fiddle - http://jsfiddle.net/huskydawgs/e9pZr/
HTML
<div id="wrapper-resources">
<div id="resources_row">
<div class="resources_cell1">
<div class="resources_lt">
<img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
<div class="resources_rt">
<p><strong>Webinar</strong></p>
</div>
</div>
<div class="resources_cell2">
<div class="resources_lt">
<img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
<div class="resources_rt">
<p><strong>Article</strong></p>
</div>
</div>
<div class="resources_cell3">
<div class="resources_lt">
<img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
<div class="resources_rt">
<p><strong>Blog</strong></p>
</div>
</div>
<div class="resources_cell4">
<div class="resources_lt">
<img height="76" src="https://cdn1.iconfinder.com/data/icons/softwaredemo/PNG/256x256/Box_Red.png" width="76" /></div>
<div class="resources_rt">
<p><strong>Market</strong></p>
</div>
</div>
</div>
</div>
CSS
#wrapper-resources {
position:relative;
width:100%;
border: none;
margin: 50px 0 0 0;
}
#resources_row {
height:100%;
white-space:nowrap;
}
.resources_cell1, .resources_cell2, .resources_cell3, .resources_cell4 {
height:100%;
width:25%;
display:inline-block;
white-space:normal;
}
.resources_lt {
height:100%;
width:33%;
display:inline-block;
white-space:normal;
margin-right: 20px;
vertical-align: top;
}
.resources_rt {
height:100%;
width:50%;
display:inline-block;
white-space:normal;
vertical-align: top;
}
/* Fonts */
#wrapper-resources p {
color: #666666;
font-family: 'SegoeRegular', Helvetica, Arial, sans-serif;
font-size: .9em;
line-height: 1.6em;
}

you need to reset margin to 0 for your <p> http://jsfiddle.net/e9pZr/3/
it has by default margin:1em 0; see http://reference.sitepoint.com/css/collapsingmargins for more explanations.

Related

CSS masonry problems

I've recently discovered a neat way to do a masonry layout using columns, as found here: http://w3bits.com/css-masonry/. I've expanded on this layout by adding an overlay with text to each item upon hover. This works pretty well except for 2 problems:
The overlay is slightly larger than the image at the bottom. This persists even when different images are used.
The transitions do not work; the hover effect displays and hides abruptly.
Some explanations regarding my code:
I've added margin: 0; border:0; padding:0 to the entire document in an attempt to prevent problems just like this one, to no avail. .item has margin: 0 0 20px to provide vertical spacing between each item.
Because .item-overlay requires position:absolute to work, and position:absolute requires the parent element to be positioned, I've added position:relative to .item. This doesn't affect anything beyond allowing the overlay to show up correctly, as far as I can tell.
.item-overlay uses display:flex to vertically and horizontally centralise its content, but this shouldn't affect the layout.
Could someone help me figure out what's wrong with the code? JSFiddle: https://jsfiddle.net/nattanyz/sfn47me9/1/
Use vertical-align: top on the img and transition opacity instead of display
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
background-color: honeydew;
font-size: 16px;
line-height: 120%;
color: #333;
margin: 0;
padding: 0;
}
.wrapper {
min-height: 100vh;
width: 80vw;
max-width: 1200px;
margin: auto;
border: 0;
padding: 0;
column-count: 3;
column-gap: 20px;
}
.item {
display: block;
margin: 0 0 20px;
border: 0;
width: 100%;
position: relative;
}
.item-overlay {
position: absolute;
top: 0;
left: 0;
bottom: 0;
width: 100%;
background-color: rgb(51, 51, 51, 0.6);
color: white;
opacity: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(51, 51, 51, 0.6);
transition: opacity 300ms ease;
}
.item:hover .item-overlay {
opacity: 1;
}
.project-img {
width: 100%;
margin: 0;
border: 0;
padding: 0;
vertical-align: top;
}
.project-name {
font-weight: bold;
}
.project-category {
font-size: 0.75em;
text-transform: uppercase;
<body>
<div class="wrapper">
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb" />
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
</div>
</body>
The overlay is slightly larger than the image at the bottom. This persists even when different images are used.
The problem is on the image itself, it has height smaller than the container. Try to put some background-color on the container, you will see that the overlay height is equal with it's parent.
The transitions do not work; the hover effect displays and hides abruptly.
You cannot implements transition on the css display, other alternative would be using opacity. I modified your code, please try.
html {
box-sizing:border-box;
}
*, *:before, *:after {
box-sizing:inherit;
}
body {
background-color:honeydew;
font-size: 16px;
line-height: 120%;
color: #333;
margin: 0;
padding: 0;
}
.wrapper {
min-height: 100vh;
width: 80vw;
max-width:1200px;
margin: auto;
border: 0;
padding: 0;
column-count: 3;
column-gap: 20px;
}
.item {
display:block;
margin: 0 0 20px;
border:0;
width:100%;
position:relative;
background-color: black;
}
.item-overlay {
position:absolute;
top:0;
left:0;
bottom:0;
width:100%;
background-color: rgba(51,51,51,0.6);
color:white;
opacity:0;
transition:300ms ease opacity;
display: flex;
flex-direction:column;
justify-content:center;
align-items:center;
}
.item:hover .item-overlay {
opacity: 1;
background-color: rgba(51,51,51,0.6);
}
.project-img {
width:100%;
margin:0;
border:0;
padding:0;
}
.project-name {
font-weight:bold;
}
.project-category {
font-size:0.75em;
text-transform:uppercase;
<body>
<div class="wrapper">
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
<div class="item">
<img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
<div class="item-overlay">
<p class="project-name">Project Name</p>
<p class="project-category">Commercial</p>
</div>
</div>
</div>
</body>

How to position overlay above the photo?

I am trying to make the overlap appear on top of the photo instead of under it. Here is a link to my test page - http://kaniamea.com/image.htm
How can I position this correctly and be responsive in the same time?
And here is the code:
<div align="center">
<div class="image-container"> <a href="link"><img src="https://www.hawaiidiscount.com/Portals/0/Skins/HD-custom-design-s/images/activities/oahu_dinner.jpg" height="174" width="231">
<div class="after">This is some content</div>
</a> </div>
<div class="image-container"> <a href="link"><img src="https://www.hawaiidiscount.com/Portals/0/Skins/HD-custom-design-s/images/activities/oahu_dinner.jpg" height="174" width="231">
<div class="after">This is some content</div>
</a> </div>
<div class="image-container"> <a href="link"><img src="https://www.hawaiidiscount.com/Portals/0/Skins/HD-custom-design-s/images/activities/oahu_dinner.jpg" height="174" width="231">
<div class="after">This is some content</div>
</a> </div>
<style>
.image-container {
width:230px;
height:200px;
display:inline-block;
vertical-align:top;
margin-top:4px;
}
.image-container .after {
width:230px;
height:200px;
display:inline-block;
vertical-align:top;
margin-top:4px;
position:absolute;
display: none;
color: #FFF;
}
.image-container:hover .after {
display: block;
background: rgba(0, 0, 0, .6);
}
</style>

Containers do not fit inside a big one

The problem is that #lesson containers do not fit inside the #container. How can I make that only 3 containers fit into one column? CSS ninjas, I need your help :)
My CSS: #container - main container, #first - green container, #lesson- gray divs.
#container {
position: relative;
top: 70px;
left: 80px;
width:100%;
height:80%;
}
#first {
background-color: #A1D490;
width:45%;
height:100%;
float:left;
border:2px solid black;
margin: 5px;
}
.lesson {
position: relative;
background-color: #DCDDDE;
margin:10px;
width:200px;
height:200px;
border:1px solid;
text-align: center;
}
HTML:
<div id="container">
<div id="first">
<tpl for=".">
<div class="lesson"; >
<p class="txt"><b>Lesson:</b> {lesson} </p>
<p class="txt"><b>Score:</b> {score}</p>
</div>
</tpl>
</div>
<div id="second">
</div>
</div>
For fitting the containers on the big one you just need to remove the height 100% from the id first
#first { /* height: 100% */ }
Codepen http://codepen.io/noobskie/pen/dYGLeo
It seems to be working fine for me here. Are you sure you dont have any other css being applied and overwriting rules somewhere?
HTML
<div id="container">
<div id="first">
<div class="lesson">
<p class="txt"><b>Lesson:</b> {lesson} </p>
<p class="txt"><b>Score:</b> {score}</p>
</div>
<div class="lesson">
<p class="txt"><b>Lesson:</b> {lesson} </p>
<p class="txt"><b>Score:</b> {score}</p>
</div>
<div class="lesson">
<p class="txt"><b>Lesson:</b> {lesson} </p>
<p class="txt"><b>Score:</b> {score}</p>
</div>
<div class="lesson">
<p class="txt"><b>Lesson:</b> {lesson} </p>
<p class="txt"><b>Score:</b> {score}</p>
</div>
</div>
</div>
CSS
#container {
position: relative;
top: 70px;
left: 80px;
width:100%;
height:80%;
}
#first {
background-color: #A1D490;
width:45%;
height:100%;
float:left;
border:2px solid black;
margin: 5px;
}
.lesson {
position: relative;
background-color: #DCDDDE;
margin:10px;
width:200px;
height:200px;
border:1px solid;
text-align: center;
}

Strange css floating behaviour

Why is the professor div not floating to the left? It is "hanging up" on the members container. The main container containing all of the red divs does not have a set height so the professor div has room to go to the left so to say. The divs are set to float left in case it wasn't apparent. I know what's wrong, How do I fix it?
<div id="displayEventInfoDiv">
<div class="eventInfoDiv">
<p id="infoClassTitle" class="eventInfoTitle">Class:</p>
<p id="infoClassP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoLocationTitle" class="eventInfoTitle">Location:</p>
<p id="infoLocationP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoTimeTitle" class="eventInfoTitle">Time:</p>
<p id="infoTimeP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoToolsTitle" class="eventInfoTitle">Tools:</p>
<p id="infoToolsP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoMessageTitle" class="eventInfoTitle">Message:</p>
<p id="infoMessageP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoMembersTitle" class="eventInfoTitle">Members:</p>
<p id="infoMembersP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoSectionTitle" class="eventInfoTitle">Section:</p>
<p id="infoSectionP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoNumberTitle" class="eventInfoTitle">Course Number:</p>
<p id="infoNumberP" class="eventInfoP"></p>
</div>
<div class="eventInfoDiv">
<p id="infoProfessorTitle" class="eventInfoTitle">Professor:</p>
<p id="infoProfessorP" class="eventInfoP"></p>
</div>
<button id="exitEventInfoDivButton">exit</button>
</div>
#displayEventInfoDiv // main container
{
position:absolute;
width:60%;
left:20%;
padding: 10px 10px 40px 10px;
background-color: rgba(0,0,0,0.7);;
border-radius: 10px;
display:none;
z-index: 30;
}
#exitEventInfoDivButton // exit button
{
position:absolute;
bottom:10px;
right:10px;
height:30px;
width:80px;
background-color: rgba(255,255,255,0.4);
font-size:20px;
color:black;
border-radius: 10px;
border:none;
outline:none;
font-family: 'Indie Flower', cursive;
cursor:pointer;
}
.eventInfoDiv // red div
{
width:200px;
float:left;
padding: 0 10px 0 10px;
background-color:red;
border:3px solid black;
}
.eventInfoTitle //titles
{
height:30px;
width:100%;
font-size:25px;
color:white;
text-align:center;
margin:0 0 20px 0;
}
.eventInfoP // info under titles
{
width:100%;
border-radius: 10px;
text-align:center;
font-size:20px;
background-color: rgba(255,255,255,0.4);
padding: 10px 0 10px 0;
}
I would either add an extra class to members to resize it properly, so you're Professor div is not sitting next to it because of float: left.
Or target you're professor div and set it to: clear:both
You can do this by using
<div class="eventInfoDiv professor">
<p id="infoProfessorTitle" class="eventInfoTitle">Professor:</p>
<p id="infoProfessorP" class="eventInfoP"></p>
</div>
.professor {
clear: both;
}

CSS Issue with alignment of divs

I have an issue with the following CSS. The votes I wan't to be in the same height as the Title. Although it looks like the Votes is on the same div as tags and by div. So that the 3 items to the left looks shrunken. I am quite new to it so I fail to see what I have done wrong. I had it working before I changed the height from 54 to 60 pixels, but I assume that there is something else I have added as well.
#containerpostsmall {
width: 800px;
height:60px;
}
.votes {
height:60px;
width:100px;
float: left;
}
.number {
height:40px;
text-align: center;
}
.number-text {
height:20px;
text-align: center;
}
.texttags {
width:500px;
height:60px;
float: left;
}
.title {
height:40px;
width:500px;
font-size:32px;
overflow: hidden;
white-space: nowrap;
}
.tagsby {
height:20px;
width:500px;
float: left;
}
.tags {
float: left;
}
.by {
float: right;
}
I have the following code part:
<div id="containerpostsmall">
<div class="votes">
<div class="number">
<h1>6</h1>
</div>
<div class="number-text">
votes
</div>
</div>
<div class="votes">
<div class="number">
<h1>1</h1>
</div>
<div class="number-text">
answers
</div>
</div>
<div class="votes">
<div class="number">
<h1>4</h1>
</div>
<div class="number-text">
comments
</div>
</div>
<div class="texttags">
<div class="title">
We were very tired.
</div>
<div class="tagsby">
<div class="tags">
<span style="background-color: #ffffff; border-color: #000000;">Forest</span>
<span style="background-color: #ffffff; border-color: #000000;">Ocean</span>
</div>
<div class="by">
Peter |
2013-12-03 18:56:34
</div>
</div>
</div>
</div>
It looks to me like a default h1 formatting issue. Browsers are going to apply default styling to certain elements.
I set
h1{
margin: 0;
}
See fiddle: http://jsfiddle.net/kZLub/

Resources