Align <div>'s in <td> horizontally - html

I want to align three div's horizontally in a td.
I want also change div of A and B in the picture below:
It is just important that A goes left side of the SecondOne and B on the right of it. I used span as well but it didn't work.
jsFiddle
<table>
<tr>
<td>
<div style="width: 55px; background: yellow; margin-left: 50px;">
FirstOne
</div>
</td>
<td>
<div style="width: 11px; background: red; margin-left: 50px">
A
</div>
<div style="width: 75px; background: green; margin-left: 50px;">
SecondOne
</div>
<div style="width: 11px; background: red; margin-left: 50px">
B
</div>
</td>
<td>
<div style="width: 65px; background: blue; margin-left: 50px;">
ThirdOne
</div>
</td>
</tr>
</table>

set div to display:inline:block
Don't use inline styles.
.table-divs {
font-size: 0;
/*fix inline-block gap*/
border: 1px dashed red
}
.table-divs div {
display: inline-block;
font-size: 16px
/* set font-size again */
}
.table-divs td:nth-of-type(2) {
padding: 0 50px
}
.first {
width: 55px;
background: yellow;
}
.second {
width: 75px;
background: green;
}
.third {
width: 65px;
background: blue;
}
.a,
.b {
width: 11px;
background: red;
}
<table class="table-divs">
<tr>
<td>
<div class="first">
FirstOne
</div>
</td>
<td>
<div class="a">
A
</div>
<div class="second">
SecondOne
</div>
<div class="b">
B
</div>
</td>
<td>
<div class="third">
ThirdOne
</div>
</td>
</tr>
</table>
<hr />
<div class="a">
A
</div>
<div class="second">
SecondOne
</div>
<div class="b">
B
</div>
<div class="third">
ThirdOne
</div>

Add this to the style part of your middle 3 divs:
float: left;
So it becomes:
<table>
<tr>
<td>
<div style="width: 55px; background: yellow; margin-left: 50px;">
FirstOne
</div>
</td>
<td>
<div style="width: 11px; background: red; margin-left: 50px; float: left;">
A
</div>
<div style="width: 75px; background: green; margin-left: 50px;float: left;">
SecondOne
</div>
<div style="width: 11px; background: red; margin-left: 50px;float: left;">
B
</div>
</td>
<td>
<div style="width: 65px; background: blue; margin-left: 50px;">
ThirdOne
</div>
</td>

You can use float property
below is the working fiddle
https://jsfiddle.net/w5zu09ny/1/

user "float: left" to put div on left and remove "margin-left" for secondOne and B
<table>
<tr>
<td>
<div style="width: 55px; background: yellow; margin-left: 50px;">
FirstOne
</div>
</td>
<td>
<div style="width: 11px; background: red; margin-left: 50px;float: left;">
A
</div>
<div style="width: 75px; background: green; float: left;">
SecondOne
</div>
<div style="width: 11px; background: red;float: left;">
B
</div>
</td>
<td>
<div style="width: 65px; background: blue; margin-left: 50px;">
ThirdOne
</div>
</td>
</tr>
</table>

Try this
<td>
<div style="width: 11px;background: red;margin-left: 50px;float: left;">
A
</div>
<div style="width: 75px;background: green;float: left;">
SecondOne
</div>
<div style="width: 11px;background: red;float: left;">
B
</div>
</td>

Related

Stuck in css image gallery coding

I have been trying to figure out what causes this issue but couldn't. This image gallery is responsive but when I hover my mouse pointer on the thumbnails the image is shown on the left side main gallery but the thumbnail set disappears. Tried everything I know. I think my mind got fed up and gave up :-(. Any help in fixing it will be much appreciated. Thanks much in advance.
<style>
#gallery_container {
position: relative;
margin-bottom: 16px;
}
#gallery_mobile_container {
position: relative;
}
.gallery_main {
position: absolute;
visibility: hidden;
opacity: 0;
top: 0px;
left: 0px;
transition: visibility 0s, opacity 0.5s;
text-align: left; /*changing image appears on the left*/
background-color: #ffffff;
}
.gallery_large_img_table .gallery_main {
visibility: visible;
opacity: 1;
position: relative;
}
.gallery_thumbnail:hover > .gallery_main {
visibility: visible;
opacity: 1;
}
.gallery_thumbnail {
padding:2px;
cursor: pointer;
text-align: center;
}
.gallery_thumbnail_img {
transition: opacity 0.5s;
max-width: 100%;
max-height: 230px;
}
.gallery_thumbnail_img:hover {
opacity: 0.5;
}
</style>
<style>
#gallery_container .gallery_large_img_table {
width: 100%;
}
#gallery_container .gallery_main {
width: 100%;
height: 100%;
}
#gallery_container .gallery_main img {
max-width: 100%;
max-height: 100%;
}
</style>
<div style="display: table-cell; width: 90%; height: auto; text-align: center; vertical-align: top; padding: 7px; border: 1px solid #202020; border-radius: 12px;">
<div id="desc" name="desc">
<div id="gallery_container">
<table class="hide_product_photo">
<tbody>
<tr>
<td style="width: 80%; vertical-align: top;"> <!--width: 80% of the total Gallery is taken by main image-->
<!---css code here--->
<table class="gallery_large_img_table">
<tbody>
<tr>
<td>
<div class="gallery_main">
<img src="https://i.imgur.com/6h1GdR5.jpg"> <!--non-grid standalone image-->
</div>
</td>
</tr>
</tbody>
</table>
</td>
<td style="width: 20%; vertical-align: top;"> <!--width: 20% of the total Gallery is taken by thumbnails-->
<table>
<tbody>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/ZDUmji7.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/ZDUmji7.jpg">
</div>
</div>
</td>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/ByPVSkn.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/ByPVSkn.jpg">
</div>
</div>
</td>
</tr>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/dXQjDR7.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/dXQjDR7.jpg">
</div>
</div>
</td>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/5SR520h.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/5SR520h.jpg">
</div>
</div>
</td>
</tr>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/3uJiUDq.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/3uJiUDq.jpg">
</div>
</div>
</td>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/2dWjFD0.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/2dWjFD0.jpg">
</div>
</div>
</td>
</tr>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/LUCcLCL.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/LUCcLCL.jpg">
</div>
</div>
</td>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/q0Y4Cdb.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/q0Y4Cdb.jpg">
</div>
</div>
</td>
</tr>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/8VJF5pE.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/8VJF5pE.jpg">
</div>
</div>
</td>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/8VJF5pE.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/8VJF5pE.jpg">
</div>
</div>
</td>
</tr>
<tr>
<td style="width: 50%;">
<div class="gallery_thumbnail">
<img class="gallery_thumbnail_img" style="width: 100%; text-align: center;" src="https://i.imgur.com/8VJF5pE.jpg">
<div class="gallery_main">
<img src="https://i.imgur.com/8VJF5pE.jpg">
</div>
</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
If I got the question right: Actually the thumbnail will not disappear, it will hide under the hovered image because you set hovered image width and height to 100% and it will cover all of the space is available to showing itself!
on this section: (inside the second <style> tag)
#gallery_container .gallery_large_img_table {
width: 100%;
}
#gallery_container .gallery_main {
width: 100%;
height: 100%;
}
#gallery_container .gallery_main img {
max-width: 100%;
max-height: 100%;
}
there are no rooms for other thumbnail images!
so if you change these two attribute to something fewer than 100% you can see them as well but be sure to change the main image width and height too.
you can replace the above section with these styles to solve your issue:
#gallery_container .gallery_large_img_table {
width: 80%;
}
#gallery_container .gallery_main {
width: 80%;
height: 80%;
}
#gallery_container .gallery_main img {
max-width: 80%;
max-height: 80%;
}

Not able to split the div for rows and columns

creating this application in MVC5 with bootstrap....
I have added div :
<div class="divFullWidth" style="margin:10px 0px 0px -15px; height:150px;background-color:grey;">
<div class="wireframe_div">
<div class="Row">
<div class="Cell">
#Html.Label("Ext :")
</div>
</div>
<div class="Row">
<div class="Cell">
#Html.TextBox("txt_Ext", null, new { #class = "form-control" })
</div>
</div>
</div>
</div>
CSS :
.wireframe_div {
border: 1px solid black;
background-color: darkgrey;
padding: 15px 20px 25px 20px;
.Cell
{
display: table-cell;
padding-left: 5px;
padding-right: 5px;
}
.Row
{
display: table-row;
}
.divFullWidth {
float: left;
width: 100%;
}
But am not able split the div exactly like in screen shot.
Can any one help on this. Am very new to web tech.
<div style="width: 100%; height: 150px;">
<div style=" width: 100%; height: 30%;">
Ext <input type="text" style="width: 35%;"/>
Area <input type="text" style="width: 10%;"/>
</div>
<div style="width: 50%; height: 70%; float: left; text-align: center;">
Activity Catagory <input type="text" style="width: 80%;"/>
</div>
<div style="width: 50%; height: 70%; float: right;">
<div style="width: 50%; height: 100%; float: right; text-align: center;">
Activity Date To<input type="text" style="width: 80%;"/>
</div>
<div style="width: 50%; height: 100%; float: left; text-align: center;">
Activity Date From <input type="text" style="width: 80%;"/>
</div>
</div>
</div>
also try bootstrap it makes life easy

How to vertically top align div inside of div?

I am trying to top align a div inside of a div and I'm having no success. http://jsfiddle.net/jhbs31xv/
<table style="border: 1px solid red; width: 100%">
<tr>
<td>
<div style="display: table-cell; width: 200px; height: 500px; overflow-y: auto;">
<div id="housingTree" class="demo" style="height: 100px;">
</div>
</div>
</td>
<td style="width: 100%; height: 100%; border: 1px solid blue;">
<div style="height: 100%; width: 100%;">
<div id="infoPane" style="width:100%;margin-left:10px; border: 1px solid green;vertical-align:top; ">
How To Top Align Me?
</div>
</div>
</td>
</tr>
</table>
Like this:
<td style="width: 100%; height: 100%; border: 1px solid blue;" valign="top">
<div style="height: 100%; width: 100%;">
<div id="infoPane" style="width:100%;margin-left:10px; border: 1px solid green; ">
How To Top Align Me?
</div>
</div>
</td>
Add valign="top" to the containing .
And, as Goos van den Bekerom mentions, you shouldn't have a div in a td....

HTML-BROWSER ZOOM CAUSES ALIGNMENT PROBLEMS

I have 2 div elements with float left and float right withiin a div element..when i zoom the browser,all the alignment changes..the zooming should be like...how we zoom an image....can anyone give suggestions to resolve this problem
<html>
<style type="text/css">
div.advancedDrugSearchOuterLayout
{
border-style: groove;
border-color: #005ce5;
margin-left:10%;
margin-right:10%;
margin-top:1%;
height: 430px;
zoom: 200%;
}
div.searchByBlock{
border-style: ridge;
border-color: #000;
float: left;
height: 70%;
width: 46%;
margin-left: 2%;
margin-top:1%;
margin-bottom:1%;
}
div.narrowByBlock{
border-style: ridge;
border-color: #000;
float: right;
height: 70%;
width: 46%;
margin-right: 2%;
margin-top:1%;
margin-bottom:1%;
}
div.searchByText{
margin-left: 2%;
float:left;
text-align:left;
width:46%;
}
div.narrowByText{
margin-right: 1.5%;
float:right;
text-align:left;
width:46%;
}
div.compareAndClearFields{
margin-left: 2%;
float:left;
text-align:center;
width:46%;
}
div.errorMessageDisplayforAdvanceDrugSearch{
margin-left: 2%;
float:right;
text-align:center;
width:46%;
}
div.advancedDrugSearchText{
margin-left: 2%;
}
div.textBelowAdvancedDrugSearchText{
margin-left: 2%;
}
div.browseClassesLink{
float:right;
}
input.search{
background-color: #007fea;
height:30px;
width:40%;
font: bold;
font-color: white;
margin-left: 3%;
}
table.blocksForSearchByAndNarrowBy{
margin-bottom:3%;
}
</style>
<body>
<div class="claro">
<div class="advancedDrugSearchOuterLayout">
<div class="advancedDrugSearchText">
<font size="4" color= "mediumorchid"><b>THIS iS AN EXAMPLE</b></font>
</div>
<div class="textBelowAdvancedDrugSearchText">
<font size="3" ><i>THESE ARE DATABASE TEXT</a>
</div>
<div>
<div class="searchByText">
<font size="2"><u><b>searchBy</b><i>SearchTermIsrequired</i></u></font>
</div>
<div class="narrowByText">
<font size="2"><u><b>narrow</b><i>(optional)</i></u></font>
</div>
</div>
<div class="searchByBlock">
<table border="1"">
<tr><td style="width:100px"></td>
<td><div style="float:right"><a href="#">Browse list of classes</div>
</td></tr>
</table>
<div>
<div style="float:left">
<font size="3">drugClass</font>
</div>
<div style="float:right">
<input id="selectDrugClasses">
</div>
</div>
<div>
<table>
<tr>
<td height="110"></td>
<td height="110"></td>
</tr>
</table>
</div>
<div>
<div style="float:left">
<font size="3">CLASS</font>
</div>
<div style="float:right">
<input id="selectIndications">
</div>
</div>
</div>
<div class="narrowByBlock">
<table><tr><td style="width:10px"></td>
<td> <div style="float:right"><input type="radio" checked="true">include
<input type="radio">exclude
</div>
</td>
</tr>
</table>
<div style="float:left">
<font size="3">CLINICAL</font>
</div>
<div style="float:right">
<input id="selectAdverseEffects">
</div>
<div>
<table>
<tr>
<td height="90"></td>
<td height="90"></td>
</tr>
</table>
</div>
<table border="1"><tr><td style="width:10px"></td>
<td><div style="float:right">
<input type="radio" checked="true">include
<input type="radio">exclude
</div></td></tr>
</table>
<div>
<div style="float:left">
<font size="3">Suggestion</font>
</div>
<div style="float:right">
<input id="selectDrugInteractions">
</div>
</div>
</div>
<div>
<div class="compareAndClearFields">
<input class="search" type="submit" value="Search & Compare Drugs" name="submit" id="formSubmit" onClick="submitForm()">
<a onClick="resetForm()">clearAllFields</a>
</div>
</div>
</div>
</div>
</body>
</html>
I just add a div that has a solid size.
Here's mine, and may be it's what you wonder :
<html>
<style type="text/css">
.allbody{
width : 1024px;
height: auto;
margin: 0px auto;
}
div.advancedDrugSearchOuterLayout
{
border-style: groove;
border-color: #005ce5;
margin-left:10%;
margin-right:10%;
margin-top:1%;
height: 430px;
zoom: 200%;
}
div.searchByBlock{
border-style: ridge;
border-color: #000;
float: left;
height: 70%;
width: 46%;
margin-left: 2%;
margin-top:1%;
margin-bottom:1%;
}
div.narrowByBlock{
border-style: ridge;
border-color: #000;
float: right;
height: 70%;
width: 46%;
margin-right: 2%;
margin-top:1%;
margin-bottom:1%;
}
div.searchByText{
margin-left: 2%;
float:left;
text-align:left;
width:46%;
}
div.narrowByText{
margin-right: 1.5%;
float:right;
text-align:left;
width:46%;
}
div.compareAndClearFields{
margin-left: 2%;
float:left;
text-align:center;
width:46%;
}
div.errorMessageDisplayforAdvanceDrugSearch{
margin-left: 2%;
float:right;
text-align:center;
width:46%;
}
div.advancedDrugSearchText{
margin-left: 2%;
}
div.textBelowAdvancedDrugSearchText{
margin-left: 2%;
}
div.browseClassesLink{
float:right;
}
input.search{
background-color: #007fea;
height:30px;
width:40%;
font: bold;
font-color: white;
margin-left: 3%;
}
table.blocksForSearchByAndNarrowBy{
margin-bottom:3%;
}
</style>
<body>
<div class="allbody">
<div class="claro">
<div class="advancedDrugSearchOuterLayout">
<div class="advancedDrugSearchText">
<font size="4" color= "mediumorchid"><b>THIS iS AN EXAMPLE</b></font>
</div>
<div class="textBelowAdvancedDrugSearchText">
<font size="3" ><i>THESE ARE DATABASE TEXT</a>
</div>
<div>
<div class="searchByText">
<font size="2"><u><b>searchBy</b><i>SearchTermIsrequired</i></u></font>
</div>
<div class="narrowByText">
<font size="2"><u><b>narrow</b><i>(optional)</i></u></font>
</div>
</div>
<div class="searchByBlock">
<table border="1"">
<tr><td style="width:100px"></td>
<td><div style="float:right"><a href="#">Browse list of classes</div>
</td></tr>
</table>
<div>
<div style="float:left">
<font size="3">drugClass</font>
</div>
<div style="float:right">
<input id="selectDrugClasses">
</div>
</div>
<div>
<table>
<tr>
<td height="110"></td>
<td height="110"></td>
</tr>
</table>
</div>
<div>
<div style="float:left">
<font size="3">CLASS</font>
</div>
<div style="float:right">
<input id="selectIndications">
</div>
</div>
</div>
<div class="narrowByBlock">
<table><tr><td style="width:10px"></td>
<td> <div style="float:right"><input type="radio" checked="true">include
<input type="radio">exclude
</div>
</td>
</tr>
</table>
<div style="float:left">
<font size="3">CLINICAL</font>
</div>
<div style="float:right">
<input id="selectAdverseEffects">
</div>
<div>
<table>
<tr>
<td height="90"></td>
<td height="90"></td>
</tr>
</table>
</div>
<table border="1"><tr><td style="width:10px"></td>
<td><div style="float:right">
<input type="radio" checked="true">include
<input type="radio">exclude
</div></td></tr>
</table>
<div>
<div style="float:left">
<font size="3">Suggestion</font>
</div>
<div style="float:right">
<input id="selectDrugInteractions">
</div>
</div>
</div>
<div>
<div class="compareAndClearFields">
<input class="search" type="submit" value="Search & Compare Drugs" name="submit" id="formSubmit" onClick="submitForm()">
<a onClick="resetForm()">clearAllFields</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
We can limit the impact of alignment fail to a certain extend using css styling. If you intention is to make the page dynamically re align with zooming. I prefer you to make it an Responsive design. Use Boot Strap it is a powerful tool which can solve these issues.
Just as a temporary fix change these styles
div.searchByBlock {
border-color: #000000;
border-style: ridge;
float: left;
height: 70%;
margin: 1% 1% 1% 2%;
width: 45%;
}
div.narrowByBlock {
border-color: #000000;
border-style: ridge;
float: left;
height: 70%;
margin: 1% 2%;
width: 45%;
}
div.advancedDrugSearchOuterLayout {
border-color: #005CE5;
border-style: groove;
float: left;
height: 430px;
margin-left: 10%;
margin-right: 10%;
margin-top: 1%;
}

Alignment issues inside table

I have two divs which I put inside a table in order to get horizontally alignment.
<table>
<tr>
<td>
<div>
data
</div>
<div>
data
</div>
</td>
</tr>
</table>
Which looks like the following:
I now want to align these 2 in the centre, as opposed to the left.
I have tried <td style="margin-left:auto; margin-right:auto;">
but no joy.
Any idea?`
Apply the margins to the <table/>:
table {
margin: 0 auto;
}
Here is a demo fiddle.
Created a fiddle example
use align="center" for td and for div use display: inline-block;
<table style="border: 1px solid green; width: 100%; ">
<tbody><tr>
<td align="center">
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
</td>
<div id="containerdiv">
<div id="coveringdiv">
<div id="firstdiv">
<div id="yourdata">
Your Data Here
</div>
<div id="yourvalue">
Value
</div>
</div>
<div id="seconddiv">
<div id="yourdata">
Your Data Second
</div>
<div id="yourvalue">
values2
</div>
</div>
</div>
</div>
and CSS:
body
{
background-color: #123456;
}
#coveringdiv
{
border: solid 1px #FFFFFF;
height: 200px;
margin: 0 auto;
width: 100%;
text-align: center;
}
#firstdiv
{
display: inline-block;
}
#yourdata
{
color: #FFFFFF;
font-size: 10px;
}
#yourvalue
{
color: #FFFFFF;
font-size: 24px;
}
#seconddiv
{
display: inline-block;
}