I am trying to align two headers, an h1 and h2 element, in the same row.
I used this code to create a number in a circle which represents the first header and a headline "Device name" which is the second header:
.circle {
border-radius: 45%;
width: 30px;
height: 20px;
padding: 0.5px;
background: #E6354A;
border: 3px solid #E6354A;
color: #FDFEFE;
text-align: left;
font-size: 5px;
}
<table cellpadding='0' cellspacing='0' border='0' border-collapse='collapse' style='width:98%; text-align: center; margin: 0 auto;'>
<tr>
<td colspan='4' <div style='clear:both'>
<div class='circle'>
<h1 style='font-weight: bold; text-align: left; font-size: 13px; margin-top: 0;'>" + obj.value[0].DEVICE_OVERALL_SCORE.toFixed(2) + "</h1>
</div>
<h2 style='font-weight: light; text-align: left; font-size: 16px; margin-top: 0;'> Device name: " + grci.name + " </h2>
</div>
<hr />
</td>
</tr>
</table>
For some reason the circle with the number inside appears in one row and the device name header appears in a row beneath it. Can someone tell me how to make them appear side by side?
It is due to fact that divs and headings are block elements by default, which means they take up all of the space and make other block elements have a separate row. To change this, you would require either to float them, set them as flex, grid, or inline-block element.
I approached to set them as inline-block since it is the fastest, but it really comes down to requirements.
<style>
.circle {border-radius: 45%;width: 30px;height: 20px;padding: 0.5px;background: #E6354A;border: 3px solid #E6354A;color: #FDFEFE;text-align: left;font-size: 5px;}
.circle, h2 {display: inline-block;}
</style>
<table cellpadding='0' cellspacing='0' border='0' border-collapse ='collapse' style='width:98%; text-align: center; margin: 0 auto;'>
<tr>
<td colspan='4'>
<div style= 'clear:both'>
<div class='circle'>
<h1 style='font-weight: bold; text-align: left; font-size: 13px; margin-top: 0;'>" + obj.value[0].DEVICE_OVERALL_SCORE.toFixed(2) + "</h1>
</div>
<h2 style = 'font-weight: light; text-align: left; font-size: 16px; margin-top: 0;'> Device name: " + grci.name + " </h2>
</div>
<hr />
</td>
</tr>
</table>
you can't have 2 header side by side at the same time, because the definition of header is a one row at the top of the table. So make sure you use the correct definitions.
Wrap the headers in a div and make it flex
<style>
div {
display: flex;
}
h1 {
widht: 50%;
}
</style>
<div>
<h1>HEADER1</h1>
<h1>HEADER2</h1>
</div>
Flex direction is row by default, note that I apply width: 50% to create two even columns. You may want to align and justify as well, have a look at align-items and justify-content properties.
Related
So this is actually more of a question why that is and not how I fix it. I could easily make a hack and just give the middle two strings classes that position them correctly, but I would like to know why that is and how I can properly fix it.
Heres an image to show what I mean. All 4 divs have the same code, just different images and text, still the middle two have the "XXXX players" on a different position.
Heres my html and css code:
.lp-popular {
height: 705px;
}
.lp-popular .title {
margin-top: 91px;
margin-left: 457px;
}
.lp-popular .game {
display: inline-block;
width: 240px;
height: 383px;
background-color: rgba(8, 9, 11, 0.5);
margin-top: 35px;
margin-left: 6px;
margin-right: 6px;
}
.lp-popular .game .heart {
float: left;
margin-top: 21px;
margin-left: 20px;
}
.lp-popular .game span {
float: left;
margin-left: 12px;
margin-top: 10px;
font-weight: 500;
font-size: 18px;
color: #ffffff;
}
.lp-popular .game p {
float: left;
margin-left: 15px;
font-family: Arial;
font-weight: normal;
font-size: 14px;
color: rgba(255, 255, 255, 0.5);
}
<div class="lp-popular">
<img class="title" src="img/lp_popular_header.png">
<div align="center">
<div class="game">
<img src="img/lp_popular_game_lol.png">
<img class="heart" src="img/lp_popular_heart_full.png">
<span>League of Legends</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_dota.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>DotA 2</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_csgo.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>CS:GO</span>
<p>4000 Spieler</p>
</div>
<div class="game">
<img src="img/lp_popular_game_hs.png">
<img class="heart" src="img/lp_popular_heart_empty.png">
<span>Hearthstone</span>
<p>4000 Spieler</p>
</div>
</div>
</div>
Thanks in advance!
Add the following line of CSS to clear the floats of the game title:
.lp-popular .game p {
clear: both;
}
why the middle images have different location for 'XXXX players': reason is pretty simple. note that first and last images have string length of 17 characters including space [League of Legends] and 10 characters [Heartstone] which fills up the the whole width available for that row. but in case of middle images, the string lenght is 6 [DOTA 2] and 5 [CS:GO] which is not enough to fill that top row. Hence the next text/string comes up to fill this gap and there-hence you get the 'XXXX players' on the same row instead of second row despite of having same css rules for them.
Fix: as #Ryan and #Akatosh have already given suggestion on how to fix this i.e.
.lp-popular .game p {
clear: both;
// clear: left;
}
I am not able to figure out why my image in between the label is not aligning to the center , even though I have declared the css inline , but the priority is not working.
I have declared text-align as left in the <style> tag , but I want only this particular tag to align center and not others.
here is my html ,
<td class="ospy_td" style="background-color:#ddd;border-bottom-left-radius:5px;style=text-align:center">
<label class="ospy_lab" style="text-align:center">
<img id="bt" src="img/bt.png" width="30" height="29" />
</label>
</td>
Here is my CSS, which is deined within a tag in the same html page,
.ospy_td, label {
text-align: left;
vertical-align: middle;
cursor: default;
font-weight:normal;
color:#0066c0;
};
I see a couple of errors here in CSS and usage of html elements.
But one them that creates the issue, is the style= inside style attribute:
<td class="ospy_td" style="background-color:#ddd;border-bottom-left-radius:5px;
style=
text-align:center"
>
Delete this "style=" and thing will work.
My suggestion code change (jsFiddle):
HTML
<table>
<tr>
<td class="ospy_td">
<i class="ospy_lab" />
</td>
<tr>
</table>
CSS
table {
width: 100%;
}
td {
background: #66f;
text-align: center;
}
.ospy_td {
background-color: #ddd;
border-bottom-left-radius: 5px;
cursor: default;
vertical-align: middle;
}
i.ospy_lab {
background-image: (img/bt.png);
background-position: center center;
background-repeat: no-repeat;
font-weight: normal;
color: #0066c0;
display: inline-block;
height: 29px;
width: 30px;
}
.ospy_td, label {
text-align: left; // this is your problem, change to center
}
you forgot a semicolon here
style="text-align:center"
change to
style="text-align:center;"
How can I have my text between an <HR> line?
For example: http://jsfiddle.net/VrvvX/
<div id="outerDiv">
<button id="myButton">Do This</button>
<br>-----------or do something else-<br>
<table id="mytable">
<tr>
<td>Blah:</td>
<td><select id="foo"></select></td>
</tr>
<tr>
<td>Blah:</td>
<td><select id="foo"></select></td>
</tr>
</table>
Rather than having ----- I'd like to have a pretty <hr> tag which works like a separator between the button and the table.
Set two <hr/> tags to display: inline-block and put a width on them with the text in between. Like this fiddle. Though you may want to adjust the positioning of it.
In addition to Tomás solution, you could create a HR class and add content: attr(data-content); to it. And then use the following HTML <hr class="hr-1" data-content="CONTENT HERE"/>.
This way you can fill in the content through HTML rather than CSS.
Fiddle:
https://jsfiddle.net/xqeuzrg7/
You could do something like this :
<div style="background: url('line-background.png') 50% 50% repeat-x;width: 100%;text-align: center;">
Do this
</div>
Of course you can adjust width or play with padding: 0 ?px;
EDIT :
If you want to hide background under the title you can do :
<div style="background: url('line-background.png') 50% 50% repeat-x;width: 100%;text-align: center;">
<span style="background: white;padding: 2px;"> Do this</div>
</div>
I think this is not the best practice to do this but you can use this css for the <hr/> tag and it will properly work:
hr {
padding: 0;
border: none;
border-top: 1px dashed #CCC;
color: #333;
text-align: center;
font-size:12px;
}
hr:after {
content:"or do something else";
display: inline-block;
position: relative;
top: -0.7em;
font-size: 1.5em;
padding: 0 0.25em;
background: white;
}
I have updated your example, see if this is what you want:
http://jsfiddle.net/VrvvX/146/
In my web application, I have some divs and spans that make table like structure.
the pseudo code is,
<head>
<style>
span{
display:inline-block;
width:auto;
}
.tblbody
{
font-family:'Segoe UI';
font-size:20px;
color:#2A2A2A ;
padding : 0px;
display: inline-block;
padding-top: 5px;
padding-bottom: 5px;
padding-left:9px;
}
</style>
</head>
<body>
<div>
<span style="width: 240px;" class="tblbody">
<span style="width: 240px;" class="tblbody">asia</span></span>
<span><span><br>
<span style="width: 240px;" class="tblbody">india</span></span>
<br><span><br>
<span style="width: 240px;" class="tblbody">china</span</span>
<br><span><br><span style="width: 240px;" class="tblbody">pakisthan</span></span><br><span><br>
<span style="width: 240px;" class="tblbody">bangladesh</span></span><br></span>
</body>
In the first row, the span that contains the continent name is moving downwards leaving space above it.
how can I move the span upwards?
thanx :)
Write vertical-align:top to your span. Write like this:
span{
display:inline-block;
width:auto;
vertical-align:top
}
You have padding-top: 5px try changin it to padding-top: 0px
This is my HTML code to display font with a background in a small container . .
here is the css
.cons_save h4{font:bold 22px/60px Arial,Helvetica, sans-serif;margin:20px 0px -15px 20px; color:#f78d1d;vertical-align: bottom; background:url(../images/save_bg_cons.png) no-repeat; width:151px; height:69px;}
im not able to put it ! in the bottom of that container whatever the other content above it in the container remains
My HTML CODE
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<span class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</span>
</div>
First, I would write each property of the CSS separately as follows:
.cons_save h4 {
font-weight: bold;
font-size: 22px/60px;
font-family: Arial, Helvetica, sans-serif;
margin: 20px 0px -15px 20px;
color: #f78d1d;
vertical-align: bottom;
background: url(../images/save_bg_cons.png) no-repeat;
width: 151px;
height: 69px;
}
then, it seems that the class name does not match the one in the span tag.
You should actually try and set the class name in the header tag itself.
Don't put heading tags insides spans
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<div class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</div>
</div>
And also heading having a lot of margin & padding by default. So might be the reason to come in the bottom. Be sure to clear it
.cons_save h4 { margin: 0;padding:0; }
It works without the reset too, check here
not sure what is the problem, if you could sepcify using http://jsfiddle.net/ then it would be nice.
anyway, i suggest you changing span to div, like this:
<div id ="<?php echo $store->branch_id;?>Collect" style="display:block">
<div class="cons_save fl clr">
<h4><?php echo $save. " %"; ?> </h4>
</div>
</div>
moreover, you have vertical-align which would not work, unless you add to your css display: table-cell [note: this will not work in IE7]:
.cons_save h4{display: table-cell;font:bold 22px/60px Arial,Helvetica, sans-serif;margin:20px 0px -15px 20px; color:#f78d1d;vertical-align: bottom; background:url(../images/save_bg_cons.png) no-repeat; width:151px; height:69px;}
I wouldn't recommend you to use that property (vertical-align) on block level elements. And don't put a heading inside a span.
Without changing the HTML I would do this:
#Collect{
border: 1px solid #ccc;
width: 151px;
height: 69px;
}
h4{
font-weight: bold;
font-size: 22px/60px;
font-family: Arial, Helvetica, sans-serif;
margin: 0;
color: #f78d1d;
background: url(../images/save_bg_cons.png) no-repeat;
background:#eee;
position: absolute;
bottom: 0;
}
You can even get rid of the span.