I've got the following issue. I've got a div where I'm unable to vertically align its text and also unable to place it below other divs.
My div:
<div th:text="#{mailContent.resetBtn}" style="
border: 0;
color: white;
height: 25px;
display: table-cell;
background-color: #FD8907;
cursor: pointer;
border-radius: 2px;
outline: 0;
text-align: center;
font-family: 'Rubik', sans-serif;
font-size: 16px;
padding: 50px;
display: table;
margin: 0 auto;
vertical-align: middle;
">
RESET PASSWORD
</div>
It ends up looking like this
I want it to be below the text that says "click on the following button...".
And I also find it impossible to set some padding to the text and centering it.
(Padding there is exaggeratedly set to 50px but it doesn't work anyways).
Full code:
https://pastebin.com/NqgXs4tD
Consider using <td> inside a <tr> instead of div
#title{
font-size: 25px;
font-weight: bold;
}
#pass-content {
font-style: italic;
font-family: 'Rubik', sans-serif;
color: #999;
font-size: 15px;
}
#btn-info {
padding: 20px 0 10px 0;
color: #153643;
font-family: 'Rubik', sans-serif;
font-size: 15px;
line-height: 20px;
}
#btn {
border: 0;
color: white;
height: 25px;
background-color: #FD8907;
cursor: pointer;
border-radius: 2px;
outline: 0;
text-align: center;
font-family: 'Rubik', sans-serif;
font-size: 13px;
padding: 5px;
display: table;
margin: 0 auto;
vertical-align: middle;
}
<table>
<tr id="title">
<td>Password Reset</td>
</tr>
<tr>
<td id="pass-content"> This is an email to reset the password for the account 123#gmail.com. If you don't wish to change your password please ignore this email. </td>
</tr>
<tr id="btn-info">
<td>
Click on the following button:
</td>
</tr>
<tr id="btn">
<td>RESET PASSWORD</td>
</tr>
</table>
Use flex-box as display, so you can align it horizontal and vertical.
Also you use display 2 times. And you should sort ur rules..
And because HTML5 exist you should never ever use table for design and only for tables. Did you validate your file? You open a new table tag while the old one isn't closed.
With display: flex and align-items: center you can vertically align the content elements (and text). And with order: {number} you can re-order the child elements of a flexbox element.
Related
I have a problem laying out and centering the navbar and the table. I want the navbar to be right under the h2 element and centered. At the moment, the navbar breaks onto the next line. The layout of the table is fine, but it should be centered. I wonder if there is a better technique for making a navbar.
Here is my code:
* {
background-color: #2c2f33;
text-decoration: none;
}
.bet-table {
display: table-cell;
margin: 0;
color: white;
}
.bet-table th,
td {
border: 1px solid;
text-align: center;
padding: 5px 5px 5px;
}
.bet-table table {
margin-left: auto;
margin-right: auto;
}
.logo {
text-align: center;
font-size: 40px;
font-family: arial;
font-weight: lighter;
color: white;
}
.nav-g ul {
list-style: none;
padding: 0;
margin: 0;
}
.nav-g li {
list-style: none;
display: inline-block;
}
.nav-g a {
text-decoration: none;
width: 100px;
display: block;
padding: 2px 2px 2px;
font-size: 15px;
font-weight: lighter;
text-align: center;
color: white;
font-family: arial;
float: left;
}
.Choose h3 {
color: white;
background-color: #7289da;
padding: 8px 8px 8px 8px;
border: 1px solid black;
font-family: Arial, Helvetica, sans-serif;
font-weight: lighter;
margin-top: 5pc;
}
.navbar a:hover {
color: #7289da;
}
<div id="h-container">
<h2 class="logo">Betbowl
<h2>
<div class="nav-g">
<ul>
<li><a href="#">Make-A-Bet</li>
<li><a href="#">Pending</li>
<li><a href="#">Completed</li>
</ul>
</div>
</div>
<div class="Choose">
<h3>Choose</h3>
</div>
<div class="bet-table">
<table style="width:100%; margin-left: auto; margin-right: auto;">
<tr>
<th>Situation</th>
<th>Bet</th>
<th>Winner</th>
<th>Earnings</th>
</tr>
<tr>
<td>blank</td>
<td>blank</td>
<td>blank</td>
<td>blank</td>
</tr>
<tr>
<td>blank</td>
<td>blank</td>
<td>blank</td>
<td>blank</td>
</tr>
<tr>
</tr>
</table>
</div>
</div>
First you need to close your <a> tags. like this:
I AM A LINK
ul needs to be centered:
text-align:center
for the table you should remove display property from the container, default value works fine:
.bet-table{
/* display: table-cell; REMOVE THIS LINE */
margin: 0;
color: white;
text-align: center;
width: 100%;
}
table{
margin: 0 auto
}
find the edited version here: https://codepen.io/theBehrouz/pen/QWmXZbr
This question already has answers here:
How can I make a div not larger than its contents?
(43 answers)
Closed 2 years ago.
.main-heading {
display: block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
text-align: center;
color: #ba9a45;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
color: #fff;
padding-top: 30px;
}
<!-- Headings -->
<div>
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>
I seem to not be able to make my h1 and h3 background only as wide as the text and not span the whole width of the line.
How can I reduce the background of the h1 and h3 so it only spans to the end of the text?
--
I've managed to resolve my issue by taking into consideration all the advice given by users below.
Have a look at my revised code which works:
<div class="title-headings">
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>
.main-heading{
display: block;
margin-left: auto;
margin-right: auto;
width: max-content;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
color: #ba9a45;
}
.subheading{
display: block;
margin-left: auto;
margin-right: auto;
width: max-content;
font-family: "Cardo", sans-serif;
font-size: 23.5px;
color: #fff;
padding-top: 30px;
}
Headings (<h1>, <h2>, ...) are block-level elements (display: block); if you want these to only take up as much space as the text is, you should set these to display: inline.
You can easily do it by:
.element{
display: inline-block
}
It will now take up only the width it is supposed to take!
Whilst the comments and other answers are correct in that - display : inline-block is the correct answer if the text was to be on one line, they do not address the fundamental semantic flaw in the code - you should have only one h1 element and for that to be followed by a h2.
It is important to maintain the correct hierarchy or headings in your page structure.
The way that I would do this is to have the h1 to be display: inline-block and within that to have spans for each word - and to have these spanss a display: block so that they are on separate lines.
Note that I added a red border to demonstrate the layout. And also added a text-align: center to the wrapping div to allow al lthe text to be centered.
div {
text-align: center;
}
.main-heading {
display: inline-block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
color: #ba9a45;
border: solid 1px red
}
.main-heading span {
display: block;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
}
<!-- Headings -->
<div>
<h1 class="main-heading">
<span>ATLANTIC</span>
<span>CASINO</span>
</h1>
<h2 class="subheading">FEED YOUR DESIRES</h2>
</div>
To make a block HTML element not span the full width of its container, change its style.display property to inline-block.
You can do it with CSS like this:
display: inline-block
If you wanted to do it in the element itself, the equivalent would be:
style="display: inline-block;"
On .main-heading change display:block; to display:inline-block;
.main-heading {
display: inline-block;
font-family: "Josefin-Sans", sans-serif;
font-size: 70.6px;
font-weight: bold;
text-align: center;
color: #ba9a45;
}
.subheading {
font-family: "Cardo", sans-serif;
font-size: 23.5px;
text-align: center;
color: #fff;
padding-top: 30px;
}
<div>
<h1 class="main-heading">ATLANTIC</h1>
<h1 class="main-heading">CASINO</h1>
<h3 class="subheading">FEED YOUR DESIRES</h3>
</div>
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
How to prevent line breaks in list items using CSS
(6 answers)
Closed 3 years ago.
I have a page where links overflow the page.
I wish they would stay on the line below.
I put the follow lines:
display:inline-block; overflow: auto;
But didn't work.
.hashtag {
font-family: 'Titillium Web', sans-serif;
padding: 28px;
font-size: 30px;
width: auto;
text-align: center;
text-decoration: none;
margin: 5px 2px;
background-color: rgb(98,124,169,0.8);
color: white;
display: inline-block;
line-height: 1;
<a style="background-color: rgb(98,124,169,0.8); color: white; cursor: pointer;line-height: 1;" class="hashtag" id="load2">TODAY</a> <a style="background-color: rgb(98,124,169,0.8); color: white; cursor: pointer;overflow: auto;" class="hashtag" id="load3">LIVE</a> PODCASTS
(Sorry my English)
Thanks in advance.
You need to add vertical-align:middle; to .hashtag to stop the first element being dropped down. You can also add white-space: nowrap; to the parent center element to stop the elements wrapping.
center {
white-space: nowrap;
}
.hashtag {
font-family: 'Titillium Web', sans-serif;
padding: 28px;
font-size: 30px;
width: auto;
text-align: center;
text-decoration: none;
margin: 5px 2px;
background-color: rgb(98,124,169,0.8);
color: white;
display: inline-block;
line-height: 1;
vertical-align:middle;
}
<center><a style="background-color: rgb(98,124,169,0.8); color: white; cursor: pointer;line-height: 1;" class="hashtag" id="load2">TODAY</a> <a style="background-color: rgb(98,124,169,0.8); color: white; cursor: pointer;overflow: auto;" class="hashtag" id="load3">LIVE</a> PODCASTS</span>
QUESTION 1:
Why do the following textarea and text input have different vertical text alignment if they both have the same font-size, line-height, height, padding ?
QUESTION 1.1
How can I make the textarea have the same vertical alignment as the input ?
.myTextarea {
display: block;
font-family: Arial;
font-size: 14px;
line-height: 21px;
height: 32px;
padding: 2px 5px;
resize: none;
}
.myInput {
display: block;
font-family: Arial;
font-size: 14px;
line-height: 21px;
height: 32px;
padding: 2px 5px;
}
.myDiv {
margin-top: 20px;
margin-bottom: 5px;
font-weight: bold;
}
<div>
<div class="myDiv">Textarea</div>
<textarea class="myTextarea" rows="1">12345</textarea>
<div class="myDiv">Input</div>
<input class="myInput" type="text" value="12345"/>
</div>
Textareas are for multiline texts while inputs are made for single line.
That's why line height won't have effect on input as it's considered to be equal to the input's height.
You can remove line height on your input since it has no effect on it.
Beside you should have the same line height as height for your textarea to reproduce the same effect than the input.
.myTextarea {
display: block;
font-family: Arial;
font-size: 14px;
line-height: 32px;
height: 32px;
padding: 2px 5px;
resize: none;
}
.myInput {
display: block;
font-family: Arial;
font-size: 14px;
height: 32px;
padding: 2px 5px;
}
.myDiv {
margin-top: 20px;
margin-bottom: 5px;
font-weight: bold;
}
<div>
<div class="myDiv">Textarea</div>
<textarea class="myTextarea" rows="1">12345</textarea>
<div class="myDiv">Input</div>
<input class="myInput" type="text" value="12345"/>
</div>
I'm using a <ul> with css display: inline; set to use as a toolbar/menu at the top of my page like this:
As you can see, the text vertically aligns perfectly, however the img on the left is too high, and the input box on the right is slightly low. I'm struggling to move them so they are perfectly vertically aligned.
Below is my CSS:
.mynav {
font-weight: 300;
border: 1px solid #ccc;
border-width: 1px 0;
list-style: none;
margin: 0;
padding: 0;
text-align: center;
background-color: #0067b1;
}
.mynav li {
display: inline;
align-items: center;
vertical-align:middle;
line-height:35px;
}
.mynav a {
color: white;
display: inline-block;
padding: 15px;
font-size: 14pt;
text-decoration: none;
}
.mynav input {
margin-left: 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
font-style: italic;
-moz-border-radius: 10px;
border-radius: 10px;
border: none;
padding: 5px;
width: 200px;
height: 25px;
margin-top: 0px;
}
.mynav i
{
font-weight: 300;
color: white;
font-size: 24px;
margin-left: 15px;
}
And my HTML (if needed):
<ul class="mynav">
<li><img src="http://www.advancegroupholdings.com.au/my_logo_nav.png" style="width: 100px; height:25px; padding-right:25px;" /></li>
<li>My Jobs</li>
<li>Obtain a Quote</li>
<li>Submit New Instruction</li>
<li>Settings</li>
<li>Help</li>
<li><input type="text" placeholder="Enter Your Ref or Job Number"/><i class="fa fa-search"></i></li>
</ul>
As for the input box, it has a padding of 5 which I have tried to remove with no luck. I have also set margin-top: 0px on the input, still no luck.
As for the logo, I'm also quite stumped. I've tried adding margin-top: 5px, but it's not working.
I also have found both these questions on StackOverflow:
<ul> horizontal nav bar... vertically-align element
css - verticaly align horizontal li
The first had no effect and the second wanted to change the CSS to display: flex, which for me gets rid of the horizontal bar, doesn't it?
Can anyone help me get the logo and the input box (and the magnifying glass) vertically centered? Thank you in advance!
Plunker here
I created a small bootstrap example for what you require. Different to what you have but give the required output more or less. Hopefully you can continue from here if this solution works for you.
HTML
<div class="col-md-2"><img src="http://www.advancegroupholdings.com.au/my_logo_nav.png" /></div>
<div class="col-md-1">My Jobs</div>
<div class="col-md-2">Obtain a Quote</div>
<div class="col-md-2">Submit a New Instruction</div>
<div class="col-md-1">Settings</div>
<div class="col-md-1">Help</div>
<div class="col-md-3"><input class="inputHeight" type="text" placeholder="Enter Your Ref or Job Number"/><i class="fa fa-search"></i></div>
</div>
</div>
CSS
.navbar {
width:80%;
font-weight: 300;
border: 1px solid #ccc;
border-width: 1px 0;
margin: 0;
padding: 0;
text-align: center;
background-color: #0067b1;
vertical-align:middle;
line-height:50px;
}
.inputHeight {
margin-left: 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 300;
font-style: italic;
-moz-border-radius: 10px;
border-radius: 10px;
border: none;
padding: 5px;
width: 200px;
height: 25px;
margin-top: 0px;
}
Plunker Example
Adding next two rules to your image will center it correctly.
display: inline-block;
vertical-align: sub; /* or text-bottom */
As for the input , it looks correctly centered to me.
In your specific example it's enough to add vertical-align:middle; to <img> and to <a>, <i> elements! Also I'd recommend to have <li> elements as inline-block, not inline for more flexibility.
In general case, to align vertically the image height must be equal as
other element's line-height in the line and vertical-align:middle has to be set.
If image height is 25px then set:
.mynav li, .mynav i {
vertical-align:middle;
line-height:25px;
}
img {
vertical-align:middle;
height: 25px;
line-height:25px;
}
Here you go: https://plnkr.co/edit/Xf3uvvjuqykQMjnhVxes?p=preview