Vertical alignment of text within a <div> - html

I am making a webpage and learning how to use stylesheets.
I have 3 side by side "div" boxes, each with an image and text underneath the image.
HTML and CSS:
.prod_img_box {
vertical-align: middle;
text-align: center;
width: 300px;
border: 2px solid #black;
margin: 0 auto;
display: inline-block;
position: relative;
}
<div class="prod_img_box">
<img src="direct.png" alt="Storage Vessels" class="prod_img" border=2/>
<h3 class="white_font">Storage Vessels</h3>
</div>
<div class="prod_img_box">
<img src="tran_imm.png" alt="Immersion Heaters" class="prod_img" border=2/>
<h3 class="white_font">Immersion Heaters</h3>
</div>
<div class="prod_img_box">
<img src="at_chrome.png" alt="Towel Rail Heating Elements" class="prod_img " border=2/>
<h3 class="white_font">Towel Rail Heaters</h3>
</div>
This gives me something like the following:
which is almost what I want - but the text underneath each image is currently vertically centered (as it should be as it is inside the "prod_img_box" - but I want the text to be all in a horizontal line at the bottom.
I'm not sure of the best way to do this. Should it be something like:
<div class="image">IMAGE</div>
<div class="text">Storage Vessels</div>
<div class="image">IMAGE</div>
<div class="text">Immersion Heaters</div>
<div class="image">IMAGE</div>
<div class="text">Towel Rail Elements</div>
The webpage can be found here also.

I think you should use
<div class="image">IMAGE</div>
<div class="text">Storage Vessels</div>
and then set height for image class to set the text always stay at the bottom

Check border in this class It should be 2px solid black; or 2px solid #000;
.prod_img_box {
vertical-align: middle;
text-align: center;
width: 300px;
border: 2px solid black;
margin: 0 auto;
display: inline-block;
position: relative;
}
And Remove border=2 from every image tag if not required
Note: If you are using # tag then you need to set color by color code i.e. #000 or if you are using direct color name then you don't need to put # tag

You can set a default height to the div so that however the image is , it will display all the divs to be same and thus same level of texts.

The Div element is most commonly used to keep a group of content together. If you would like to keep the code together, the best way of moving the text is simply manipulating the padding and margin properties in the CSS file.

Related

How to stop the h1 tag from changing the position of column

I've been looking all over for an answer to this but I can't find a fix anywhere. I'm just trying to move the h1 tag right over top of the icons but whenever I use margin-top or padding-top to move the h1 down the page it moves the column down as well. I put borders around all of the columns around there to see if maybe the borders were touching but that was no help. Is there like some sort of default padding around h1's or columns that you can't see?
Here is a link to my codepen: https://codepen.io/4eller/pen/eVmxeM
HTML:
<hr width="35%">
<div class="container maincon2">
<h1 class="wwd">Social Media Has Never Been Easier</h1>
<hr class="hr1">
<h1 class="whatwedo">What makes us stand out from the rest</h1>
<div class="row topicons">
<div class="col-md-4 maintab1">
<img src="images/graph.png" class="barimg">
<hr width="50%" id="hr2">
</div>
<div class="col-md-4 maintab2">
<img src="images/piggy-bank.png" class="pigimg">
<hr width="50%" id="hr2">
</div>
<div class="col-md-4 maintab3">
<img src="images/support.png" class="supportimg">
<hr width="50%" id="hr2">
</div>
</div>
</div>
</div>
</div>
<div class="container maincon3">
<div class="row">
<div class="col-lg-12 mediumcon2">
<hr class="hrgreen">
CSS:
.maincon2 {
width: 100%;
height: 500px;
background: #424242;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
border: 1px solid orange;
}
.topicons {
border: 1px solid red;
margin-top: 70px;
height: 250px;
table-layout: fixed;
}
If I understand correctly what you want (not really 100% clear), you can apply position: relative to that tag and use top to move it down without affecting anything else, since position: relative plus position settings cause an element to be moved in relation to its original (static) position, but elements before and after it will remain were they are:
h1.whatwedo {
position: relative;
top:30px;
}
Changed codepen: https://codepen.io/anon/pen/MQYRKY
Give the h1 tag position:absolute; and then move it left with left:200px(replace 200 with whatever number you want)
The reason why when using margin, padding or position:relative, it will move other elements, is because then they are considered part of the "flow" of the page, meaning they will interact with and bump other elements around. position:absolute, removes the target element from the flow of the page, thus allowing you to put it wherever without moving other elements.

how to make colored border around centered images

I basically have a stack of images that are wrapped in a div that centers the entire stack. I would like to create a thick border or padding around the entire stack, not the individual images but i dont know how to do this with css. any help would be great. Each image is also in its own div for other styling purposes. Also, adding style attributes to the individual images is not acceptable because the images are actually displayed using angularjs ng-repeat directive. below is just pseudocode for what is essentially happening but i am looking for a way to border the entire stack of images.
<div class="center">
<div>
<img>
</div>
<div>
<img>
</div>
<div>
<img>
</div>
</div>
Check out this codepen:
This generates a border around your outer div:
.center {
border: 5px solid #D32232;
}
I used a solid line. You can also use other lines. These are the possibilities:
dotted
dashed
double
groove
ridge
inset
outset
Check out this page for the full documentation on border.
you could border your outer div with a black outline
.center{ border: 5px solid #000;}
and then your inner divs with a color
.center div{border: 4px dashed blue;}
if you wanted to outline each img if there was more than one in a div you could do something like this
.center div img{border: 3px dotted red;}
You would need another wrapper shrink-wrapped around the images to do that. Otherwise, this is not possble.
.center {
text-align: center;
border: 2px solid red;
padding: 5px;
}
.wrapper {
display: inline-block;
border: 2px solid green;
font-size: 0;
}
.wrapper div {
display: inline-block;
padding: 5px;
}
.wrapper div img {
display: block;
}
<div class="center">
<div class="wrapper">
<div>
<img src="http://lorempixel.com/output/city-q-c-100-100-5.jpg" alt="">
</div>
<div>
<img src="http://lorempixel.com/output/city-q-c-100-100-5.jpg" alt="">
</div>
<div>
<img src="http://lorempixel.com/output/city-q-c-100-100-5.jpg" alt="">
</div>
</div>
</div>

DIV on top of image, both inside of parent DIV

I'm working on a photo gallery that is dynamically generated, photos will be different sizes, and each photo will have a DIV overlapping the image, on the same baseline as the image, that will contain "user menu" items related to that photo. (blue box below)
I'm having trouble getting the "user menu" div to position on top of the image. This div needs to be centered, and on the same baseline as the image, regardless of image size (not sure how to do this with absolute positioning)
I've seen suggestions to use CSS background-image, but I don't see that as a good option with dynamically generated content. I've seen a suggestion to position the image absolutely, and this does work except the parent DIV collapses and makes positioning other items on the page a nightmare. There are quite a few post that I've read through on stackoverflow, but I haven't found one that addresses or solves this particular issue.
This is an example of what I'm trying to accomplish. The blue boxes are the user menus, and should be centered on the baseline of the images.
I've tried 2 things, this doesn't seem to work with parent DIVs since the images are removed from flow and spacing gets screwed up as the parent DIVS collapse. http://jsfiddle.net/3d3m1x9k/
CSS
.box1{
position:relative;
display:inline-block;
background-color:orange;
border: 4px solid black;
}
.box2{
position:relative;
top:80px;
left:80px;
margin: 0 auto;
padding: 5px;
background-color: red;
border: 2px solid red;
}
HTML
<div class="box1">
<img src="http://i60.tinypic.com/33n947o.jpg" style="position:absolute;"/>
<div class="box2">box</div>
</div>
<div class="box1">
<img src="http://i60.tinypic.com/33n947o.jpg" style="position:absolute;"/>
<div class="box2">box</div>
</div>
This works better, but I can't get the box to center properly unless I use javascript to position the "user menu" DIV since the image widths are dynamic. (javascript isn't out of the question, just trying to first find a proper way using CSS)
https://jsfiddle.net/vv5rtkqz/
CSS
.box1{
position:relative;
display:inline-block;
background-color:orange;
border: 2px solid black;
}
.box2{
position:absolute;
bottom: 0px;
margin: 0 auto;
padding: 5px;
background-color: red;
border: 2px solid red;
}
HTML
<div class="box1">
<img src="http://i60.tinypic.com/33n947o.jpg"/>
<div class="box2">Center Me</div>
</div>
<div class="box1">
<img src="http://i60.tinypic.com/33n947o.jpg"/>
<div class="box2">Center Me</div>
</div>
You can get a simple start by using absolute positioning and a 2D transform.
.container {
position: relative;
display: inline-block;
}
.info {
background: black;
color: white;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
white-space: nowarp;
}
<div class="container">
<img src="http://shakacity.com/sites/default/files/dog_0.jpg" alt="" />
<div class="info">Contains the user controls</div>
</div>

How do I make these HTML blocks of info stay the same size?

I am trying to make these blocks of info the same size regardless of the number of words each one holds. As seen in the example, when one block has less text than the other, one gets a bit smaller and the other remains a different size.
Now my question is, How do I achieve having these blocks the same size regardless of its content or image? I am also going to use another pair right below them.
Here is the CSS code:
/***********All containers**************/
.bottomContainers{
position: absolute;
margin-left: 0%;
display: inline-box;
}
/**********Small Containers*************/
.container{
max-width: 30%;
max-height: 30%;
margin-top:5%;
margin-bottom: 5%;
margin-left: 10%;
padding-left: 2%;
padding-right: 2%;
padding-bottom: 2%;
background-color: #ecf0f1;
color: grey;
display: inline-block;
/*display: inline-block;*/
border-radius: 5px;
border-bottom: 2px solid grey;
}
Here is the HTML code:
<div class="bottomContainers" role="moreInfo">
<!--Small Inner Containers for Information-->
<div class="container" id="firstContainer">
<br />
<center><img src="img/map.png"></center>
<br>
<article>
Some random text is in this block, It doesnt size like the next one
</article>
</div>
<div class="container" id="firstContainer">
<br />
<center><img src="img/money.png"></center>
<br>
this is another block which also doesnt scale to the other block regardless of text inside of it
</div>
What did I possibly do wrong here ?
I am heavily refactoring your original code in this solution. If this is a static width website then having static width cells won't be a problem. If you want this solution to be responsive you will have a lot of issues with it:
http://jsfiddle.net/VET6x/1/
I positioned the image and its corresponding text using absolute. Again that will work with a static layout, once it goes responsive there will be problems.
<div class="bottomContainers">
<div class="container">
<div>
<img src="http://placekitten.com/g/80/80" />
</div>
<div>
Some random text is in this block, It doesnt size like the next one
</div>
</div>
<div class="container">
<div>
<img src="http://placekitten.com/g/80/80" />
</div>
<div>
This is another block which also doesnt scale to the other block regardless of text inside of it
</div>
</div>
</div>
.bottomContainers { overflow:hidden; }
.container {
width:200px;
height:200px;
float:left;
position:relative;
margin:5% 5%;
padding:2%;
background-color: #ecf0f1;
color: grey;
border-radius: 5px;
border-bottom: 2px solid grey;
}
.container > div { position:absolute; bottom:10px; }
.container > div:first-child { position:absolute; top:10px }
If it were me I would find someway to avoid static height cells.
Here is one solution that may work for you:
Demo Fiddle
I changed up your code a bit. Using the center tag is frowned upon, also it looks like the br tags were there for spacing, which could be done with margin. I ended up giving .container a specified height, the main drawback in that being if the window is sized down too far the overflow text will be hidden.
HTML:
<div class="bottomContainers" role="moreInfo">
<div class="container" id="firstContainer">
<img src="http://www.placehold.it/100x100">
<p>
Some random text is in this block, It doesnt size like the next one
</p>
</div>
<div class="container" id="firstContainer">
<img src="http://www.placehold.it/100x100">
<p>
this is another block which also doesnt scale to the other block regardless of text inside of it
</p>
</div>
</div>
CSS:
.container{
// your current styles here
overflow: hidden;
height: 200px;
display: block;
float: left;
}
.container img {
display: block;
margin: 10px auto 0px;
}
This is a quick fix, but setting an explicit height on the objects will have them all be the same height. This requires some playing around with the best size and such but it will fix your problem. I'm curious how a professional would fix this problem.
Some other things with your code. Centering the <img> using HTML is discouraged, use css instead. Also, where are the <br> tags and why are some closed but some aren't?
Maybe you can use display:table;, display:table-row; and display:table-cell;. This way, your div will act like column of a table. They will stay at the same height.
Take a look at this jsfiddle!

Align images vertically (flush top), not flush bottom

I have a div tag, that contains images. The default seems to align images flush bottom, assuming different vertically sized images. How do I change the code, such that I get the images to align flush top?
Here is the complete HTML code.
CSS
#page {
position: relative;
padding: 0px 0px 0px 0px;
float: left;
border: none;
}
.divPortfolioImageRowFirst
{
display: table-row;
}
.divPortfolioImageCol1 {
vertical-align: top;
}
HTML
<div id="page">
<div>
<div id="divProductLogos">
<div class='divPortfolioImageRowFirst'>
<div class='divPortfolioImageCol1' style='line-height: 78px' id="divProductLogos_1">
<img style='margin-left: 0px;' src="./images/portfolio/ProductLogos_1.png"/>
<img style='margin-left: 15px;' src="./images/portfolio/ProductLogos_2.png"/>
</div>
</div>
</div>
</div>
</div>
The addition of "vertical-align: top;" and "line-height: 78px;" did not do the trick.
What did I forget / not do?
I think you want something like the following:
The HTML:
<div id="divProductLogos">
<div class='divPortfolioImageRowFirst'>
<div class='divPortfolioImageCol1'>
<img src="http://placekitten.com/150/200" />
<img src="http://placekitten.com/150/250" />
</div>
</div>
</div>
and the CSS:
.divPortfolioImageRowFirst {
border: 2px dotted gray;
padding: 10px;
}
.divPortfolioImageCol1 {
border: 1px dotted gray;
}
.divPortfolioImageCol1 img {
vertical-align: top;
}
Originally, you had too many floats affecting the layout, and that was causing some problems.
You could also use CSS table cells depending on other design considerations.
Demo fiddle: http://jsfiddle.net/audetwebdesign/9fhCS/
About the Vertical-align Property
The vertical-align property is not inherited, so it as to be applied to the inline elements that need to be adjusted. Specifying vertical-align on the parent container will not affect the child elements.
Reference: http://www.w3.org/TR/CSS2/visudet.html#propdef-vertical-align
First, valign isn't a valid property, you should use vertical-align: top;
You will also need to set line-height to the height of the tallest image.