I'm using standard CSS/HTML for designing my website. Using a table for the navigation, I assign my "#nav table" with a width of 100% and my "#nav th" with a height of 50px.
My issue is that it's not actually setting itself to what I define. I had assumed it was as easy as just saying height: 50px but even when I define it as 0px it remains at 90.5px. In the HTML I did define my cells and what the table was, etc.
How can I fix this? Right now my site header is outrageously large because my table cells won't adjust to what I define them.
Using just PHP, HTML, and CSS.
CSS:
#nav table {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 0px;
border: 5px black solid;
padding: 25px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
}
HTML:
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<th><a href="LINK5><h1>LINK5</h1></a></th>
</tr>
</table>
</center>
<p>
Page Directory:
Using the code #nav table assumes an element with the ID "nav" with a table inside, and not a table element with the id "nav".
<style type="text/css">
/* For a table with the id of 'nav'. You could equally remove 'table'. */
table#nav {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 0px;
border: 5px black solid;
padding:0 25px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
}
th h1 {
margin:0;
}
</style>
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<!-- Don't forget to close all hrefs with a double-quote: -->
<th><h1>LINK5</h1></th>
</tr>
</table>
</center>
https://jsfiddle.net/cz1o8a2n/1/
Note that if you have an element inside of your th that is 90.5px tall, you will not be able to make the table header less tall using CSS (unless you use CSS to decrease the height of that element).
Edit: Consider using the more moder nav instead, with list-items. Plus, you'll have an easier time making your site responsive if you like. :)
<style type="text/css">
nav {
margin: 15px;
width: calc(100% - 30px);
position: fixed;
text-align:center;
}
nav ul {
padding-left:0;
list-style:none;
}
nav li {
display:inline-block;
border: 3px black solid;
padding:0 20px;
text-align: center;
white-space: nowrap;
letter-spacing: 0px;
word-spacing: 5px;
margin:2px 0;
}
</style>
<nav id="nav">
<ul>
<li>LINK</li>
<li>LINK1</li>
<li>LINK2</li>
<li>LINK3</li>
<li>LINK4</li>
<li>LINK5</li>
</ul>
</nav>
https://jsfiddle.net/cz1o8a2n/2/
HTML
You're missing a " for LINK5.
<center>
<table id="nav">
<tr>
<th><h1>LINK</h1></th>
<th><h1>LINK1</h1></th>
<th><h1>LINK2</h1></th>
<th><h1>LINK3</h1></th>
<th><h1>LINK4</h1></th>
<th><h1>LINK5</h1></th>
</tr>
</table>
</center>
CSS
If you want to apply css to a table with the id set to nav your selector needs to be table#nav. As for the table headings being larger than you like, the issue is the h1 tag inherently has a pretty big margin. This big margin is making your table headings larger than you'd like.
table#nav {
margin: 15px;
width: 100%;
position: fixed;
}
#nav th {
height: 50px;
border: 5px black solid;
text-align: center;
white-space: nowrap;
overflow: hidden;
}
#nav th h1 {
margin: 0;
}
Related
I have figured out a new problem in TCPDF (new for me), ie I can't place elements next to each other. I have tried so many solutions but they were zero in the end. Seems like TCPDF doesn't support the converting from all the css attributes. Hope you can help ;)
The code I had tried:
<style>
.protHeader{
position: relative;
border: 2px solid black;
display: table;
height: 250px !important;
}
.protHeader div{
width: 100%;
}
.protHeader div img{
position: relative;
display: inline-block;
float: left;
height: 100px;
overflow: hidden;
}
.protHeader div a{
position: relative;
display: inline-block;
text-align: right;
horiz-align: right;
overflow: hidden;
float: right;
font-weight: bold;
font-size: 50px;
width: 40% !important;
}
</style>
And the html:
<div class="protHeader">
<div class="fl_left">
<div style="border: 1px solid black;"><img src="$LogoN"></div>
<div style="border: 1px solid black;"><a>$protocol</a></div>
</div>
</div>
Thanks in advance for the answers!
Maybe this is your problem:
You are adding this:
.protHeader div{
width: 100%;
}
that means, that every <div> in your class .protHeader has 100% width.
EDIT: (i change the last part of the css and colored the inline-block divs red, for viewing that they should stay next each other)
Try to remove this line or change your styling to:
.protHeader{
position: relative;
border: 2px solid black;
display: table;
height: 250px !important;
}
.protHeader .fl_left{
width: 100%;
}
.protHeader div img{
position: relative;
display: inline-block;
float: left;
height: 100px;
overflow: hidden;
}
.protHeader div a{
position: relative;
display: inline-block;
text-align: right;
overflow: hidden;
float: right;
font-weight: bold;
font-size: 50px;
width: 40% !important;
}
.protHeader .fl_left div {
background-color: red;
display: inline-block;
}
<div class="protHeader">
<div class="fl_left">
<div style="border: 1px solid black;"><img src="$LogoN"></div>
<div style="border: 1px solid black;"><a>$protocol</a></div>
</div>
</div>
Okay, found a method, I had changed the whole framework to another (dompdf), which is easier to use and supports the newer CSS too.
When two inline-block divs have different heights, why does the shorter of the two not align to the top of the container? (DEMO):
.container {
border: 1px black solid;
width: 320px;
height: 120px;
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
How can I align the small div at the top of its container?
Because the vertical-align is set at baseline as default.
Use vertical-align:top instead:
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align:top; /* <---- this */
}
http://jsfiddle.net/Lighty_46/RHM5L/9/
Or as #f00644 said you could apply float to the child elements as well.
You need to add a vertical-align property to your two child div's.
If .small is always shorter, you need only apply the property to .small.
However, if either could be tallest then you should apply the property to both .small and .big.
.container{
border: 1px black solid;
width: 320px;
height: 120px;
}
.small{
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
vertical-align: top;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
vertical-align: top;
}
Vertical align affects inline or table-cell box's, and there are a large nubmer of different values for this property. Please see https://developer.mozilla.org/en-US/docs/Web/CSS/vertical-align for more details.
Use display: flex property for the parent div
The flexbox items are aligned at the start of the cross-axis.
By default, the cross-axis is vertical. This means the flexbox items will be aligned vertically at the top.
So when you apply the display: flex property to the parent div, it sets its child elements with vertical-align: top.
See the following code:
.container {
border: 1px black solid;
width: 320px;
height: 120px;
display: flex;
/** CSS flex */
}
.small {
display: inline-block;
width: 40%;
height: 30%;
border: 1px black solid;
background: aliceblue;
}
.big {
display: inline-block;
border: 1px black solid;
width: 40%;
height: 50%;
background: beige;
}
<div class="container">
<div class="small"></div>
<div class="big"></div>
</div>
Browser Compatibility: Flexbox is very well supported across modern browsers.
<style type="text/css">
div {
text-align: center;
}
.img1{
width: 150px;
height: 150px;
border-radius: 50%;
}
span{
display: block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type='password' class='secondInput mt-4 mr-1' placeholder="Password">
<span class='dif'></span>
<br>
<button>ADD</button>
</div>
<script type="text/javascript">
$('button').click(function() {
$('.dif').html("<img/>");
})
Add overflow: auto to the container div.
http://www.quirksmode.org/css/clearing.html This website shows a few options when having this issue.
I'm having trouble getting the height of my HTML divs to scale with the content of my PHP-generated table.
The table I'm using might change size so I don't want to set the height of the parent divs statically, but I can't seem to get it to work otherwise. I'm not floating anything.
The main script for this page is like this:
<div id="wrapper">
<div id="contentmain">
<div id="contentleft">
<?php
include ('get_table.php');
?>
</div>
<div id="contentright">
</div>
</div>
</div>
I thought that if #wrapper and #contentleft has height:auto or height unset that the table would decide the size of those divisions, but instead the table just sits on its own, extending into white space while the divs sit as thin lines at the top.
CSS:
#contentmain
{
width:940px;
height: 1164px;
background-color:aqua;
margin: 10px 10px 0px 10px;
}
#contentleft
{
width: 700px;
height:inherit;
background-color: #CAE2ED;
position:absolute;
}
table
{
border-spacing:8px;
font-family:Georgia, serif;
padding:0px;
box-shadow:1px 0px 5px 0px #000000;
border-top-left-radius:5px;
border-top-right-radius:5px;
border-bottom-left-radius:3px;
border-bottom-right-radius:3px;
margin:0 auto;
background-color:white;
/*border-collapse: separate;
border-spacing: 0 10px;*/
}
Note: contentleft is resizing with the table properly, but contentmain and wrapper are not.
Any help appreciated!
Try this css:
#contentmain
{
width:940px;
height: 1164px;
background-color:aqua;
margin: 10px 10px 0px 10px;
display:inline;
}
#contentleft
{
width: 700px;
height:inherit;
background-color: #CAE2ED;
position:absolute;
display:inline;
}
table
{
border-spacing:8px;
font-family:Georgia, serif;
padding:0px;
box-shadow:1px 0px 5px 0px #000000;
border-top-left-radius:5px;
border-top-right-radius:5px;
border-bottom-left-radius:3px;
border-bottom-right-radius:3px;
margin:0 auto;
background-color:white;
display:inline;
/*border-collapse: separate;
border-spacing: 0 10px;*/
}
have you tried using the clearfix method?
http://jsfiddle.net/zqtWL/
. clearfix{display:block;clear:both; float:none; width:100%;}
You can try this:
- set your #contenmain display to block.
- set your #contentleft and #contentright display to inline-block.
#contentmain { display: block; ...}
#contentleft { display: inline-block; ...}
#contentright { display: inline-block; ..}
I'm trying to horizontally center an image. However it does not move from the left side of the page. This answer does not work in my case. What am I doing wrong?
#container {
width: 100%;
border: 2px yellow dashed;
height: 100px;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
}
mypage:
<div id="container">
<div id="profile-image">
<p><img src="<?php echo $data['profile_image_url'];?>" alt="me"></p>
</div>
to make any div or anything horizontally at center , common css approach will be,lets have a width and declare margin:0 auto;
#profile-image{
width:400px;
margin:0 auto;
}
Try this: http://jsfiddle.net/rua4d/2/
#container {
width: 300px;
border: 2px yellow dashed;
height: 100px;
display:table-cell;
position:relative;
vertical-align:middle;
}
#profile-image img{
margin-left: auto;
margin-right: auto;
border: 2px orange solid;
display:block;
position:relative;
vertical-align:middle;
text-align:center;
width:50px;
}
You just need to add display:block to your image's style. Images are inline elements, and inline elements ignore margins.
why cant this work?
#profile-image p { text-align: center; }
#profile-image img { display: inline; }
that way you won't need to specify the width.. if you want margins to work together with the text-align: center you would need inline-block instead:
#profile-image p { text-align: center; }
#profile-image img { display: inline-block; }
I am trying to show a lot of results at once (like 25) but my program cut the results around the 5th record having area space still available, the results are in a table
created dynamically but seems that the area doesn't expand accordingly.
<div id="contenido" class="contenido">
<div id="Tabs">
<ul style="cursor:pointer;">
<li id="li_tab1" onclick="tab('tab1')" >
<a>Últimas alertas</a> </li>
<li id="li_tab2" onclick="tab('tab2')"> <a>otras</a> </li>
</ul>
<div id="Content_Area">
<div id="tab1">
<p class="notas">Showing last alerts</p>
<table>
<tr>
<td style="color:blue">Alert</td>
<td style="color:blue">User</td>
</tr>
<?php
while ( $row = $result->fetch_array() ){
echo "<tr><td>".$row['DESCRIPTION']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['SUB_SECCION']."</td></tr>";
}
}
else
echo "error on query: ".$conx->error;
}//else
?>
</table>
</div>
<div id="tab2" style="display: none;">
<!-- We set its display as none because we don’t want to make this
tab visible by default. The only visible/active tab should
be Tab 1 until the visitor clicks on Tab 2. -->
<p>This is the text for tab 2.</p>
</div>
</div> <!-- End of Content_Area Div -->
</div> <!-- End of Tabs Div -->
</div>
CSS creates tabs, but for the moment only the first has the table the other just one line of text, but the table is inside this tab div
archivo css
.contenido {
color: black;/*#333*/
background-color: #F2F2E6;
margin: 0px 0px 5px 0px;
padding: 10px;
border: 1px solid #ccc;
width: 75%;/*678px;*/
height: 480px;
float: right;
display: inline;
}
#Tabs ul {
padding: 0px;
margin: 0px;
margin-left: 10px;
list-style-type: none;
}
#Tabs ul li {
display: inline-block;
clear: none;
float: left;
height: 24px;
}
#Tabs ul li a {
position: relative;
margin-top: 16px;
display: block;
margin-left: 6px;
line-height: 24px;
padding-left: 10px;
background: #f6f6f6;
z-index: 9999;
border: 1px solid #ccc;
border-bottom: 0px;
/* make the top left and top right corners of each tab rounded. */
-moz-border-radius-topleft: 4px;
border-top-left-radius: 4px;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px;
/* end of rounded borders */
width: 130px;
color: #000000;
text-decoration: none;
font-weight: bold;
}
#Tabs ul li a:hover {
text-decoration: underline;
color:red;
}
#Tabs #Content_Area {
/* this is the css class for the content displayed in each tab */
padding: 0 15px;
clear:both;
overflow:hidden;
line-height:19px;
position: relative;
top: 20px;
z-index: 5;
height: 150px;
overflow: hidden;
}
p { padding-left: 15px; }
The problem is inside your CSS.
height: 150px; and overflow: hidden; in #Tabs #Content_Area could be factor.
Since you have overflow: hidden; set to "hidden", it could be a factor.
Try changing it to overflow:scroll; or overflow:visible; to see if that works, and/or changing the heights to a higher number for those IDs.
Try different variations.
I see a two possible causes:
The database query only returns 5 results
the DIV is not large enough, and even though the table ends up in,
say, 25 records, the first 5 are only displayed and the rest are
hidden by the boundaries of DIV.
It would help if you put some more PHP code or even the CSS of the #area.