How to align table row to the right with css? - css

I'm trying to move a table row containing navigation links for my website from being left aligned to being right aligned, but no matter what I edit nothing moves. I've only recently started learning HTML and CSS so any help would be appreciated.
HTML
<div id="nav">
<table>
<tr>
<td>
<a href="index.html">
<img src="Images/Home.png"/>
</a>
</td>
<td>
<a href="Learn.html">
<img src="Images/Learn.png"/>
</a>
</td>
<td>
<a href="Practice.html">
<img src="Images/Practice.png"/>
</a>
</td>
<td>
<a href="About.html">
<img src="Images/About.png"/>
</a>
</td>
<td align="right">
Donate
</td>
</tr>
</table>
</div>
CSS
#nav {
width: 100%;
height: 10%;
float: right;
background-color: #47B531;
margin: 0px;
padding:0px;
white-space: nowrap;
}
#nav tr {
margin: 0px;
padding: 0px;
width: 100%;
}
#nav td {
font-size: 18px;
margin: 0px;
padding: 5px;
text-align: right;
margin: 0px;
}
#nav img {
width: 30px;
height: 30px;
display: inline;
padding: 5px;
margin: 0px;
}

Please use
<table align="right">
instead of just table tag.

Usually, the navigation menues are designed using lists instead of tables. Here a very very simple example:
HTML:
<div id="nav">
<ul>
<li>
<img src="Images/Home.png"/>
</li>
<li>
<img src="Images/About.png"/>
</li>
<li>
<img src="Images/Contact.png"/>
</li>
<li>
Donate
</li>
</ul>
</div>
CSS:
#nav ul {
list-style: none;
}
#nav ul li{
float:right;
margin-left: 10px;
}
The options using this method is endless, give it a try and let us know if you got stuck or have questions about it.
Heres the Fiddle: http://jsfiddle.net/Q5Vh3/

If you mean that you want the links on the right, within the div element, without changing the table cell rendering from the current one, just add the rule
#nav table { float: right; }

Use #Dave's suggestion next time. Lists are much more efficient and easier. But to answer your question you can use align=right on the table to fix it.
Look at this fiddle http://jsfiddle.net/uhLuh/

Awareness of current web standards is crucial. I recommend diving head into HTML 5 & CSS3.
I believe that you should be looking to follow HTML 5 standards with CSS3.
Here is how to ideally approach a HTML5 navigation element and the base CSS3 elements and attributes that should get you pointed in the right direction :)
HTML5
<nav>
<img src="Images/Home.png"/>
<img src="Images/Home.png"/>
<img src="Images/Home.png"/>
<img src="Images/Home.png"/>
</nav>
CSS3
ul { }
nav ul
{float: right; *Adjust to suit
text-align:right; *Adjust to suit
list-style: none;} *Adjust to suit
nav ul li { }
nav ul a { }
Hope this helps you!

Related

list items horizontally rather than vertical using <ul><li> tags

I have this web page
http://hashgurus.com/htmlpage7.html which lists items in
<li> </li>
vertically. But I need it to display horizontally. Which element in css should I use to display items horizontally rather than vertically?
this is the code:
<ul class="jobs">
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div></li>
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div></li>
</ul>
demo page:
http://hashgurus.com/htmlpage7.html
.jobs {
list-style-type: none;
padding:0;
margin:0;
}
.jobs > li {
display: inline-block;
}
Something like that perhaps?
You can make your list elements align horizontally by specifying the display property with inline.
An example of this below:
li{display:inline}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
use
li {
float: left;
}
for floating the list elements to the left.
You can use float but you need to clear after it or will have layout problems.
Example :
.jobs {
list-style: none;
}
.jobs li {
float: left;
margin-left: 12px;
}
.jobs::after {
content: "";
display: table;
clear: both;
}
<ul class="jobs">
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div>
</li>
<li>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div>
</li>
</ul>
You should not use floats for layout unless absolutely necessary. They are horribly buggy. Floats should be used for removing an element from the "normal" document flow while allowing content to flow around the element. A good example would be an image in a paragraph.
Instead set the font size: 0 on the container to remove unwanted white space between items, and white-space: nowrap to keep them inline when the container is bigger than the window. Reset the font and white-space in the child and set to display: inline-block.
Using inline-block instead of inline allows you to change the width and height of each element.
Note if you set the font for html to reference that font-size later you can use rem units which refer to the font size of the root element. In this example I use 1rem to reset the font size to that of the root element.
ul {
font-size: 0;
white-space: nowrap;
}
li {
display: inline-block;
font-size: 1rem;
white-space: initial;
}
You could use a table:
<table>
<tr>
<td>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc1</div></li>
</td>
<td>
<img height="80px" src="http://pbs.twimg.com/media/CEQnmWnWgAArgtf.jpg" />
<div class="company">desc2</div></li>
</td>
</tr>
</table>

CSS - Why can't I inline everything?

Here is the jsfiddle link please do take a look
http://jsfiddle.net/o9rf3thy/
There seems to be a problem with the html.
CSS
.taro{
display: inline;
margin-left: 200px;
}
I am still learning CSS so please do be patient with me.
I am trying to obtain this result
https://www.dropbox.com/s/lq80rkc4w5fqpki/Screenshot%202014-11-21%2017.36.51.png?dl=0
Items that have display:inline either by default or by setting are not affected by margins.
What I think you require is display:inline-block
JSfiddle Demo
This might be useful LearnLayout.com
Hope this is what you want http://jsfiddle.net/89f5o3jL/2/
CSS
.list-group {
list-style-type: none;
margin: 0;
padding: 0;
}
.list-group-item {
overflow: auto;
padding-top: 15px;
}
.img-circle {
float: left;
margin-right: 20px;
border-radius: 30px;
}
.info {
float: left;
width: 500px;
border-bottom: #ccc 1px solid;
padding: 0 0 15px 0;
}
.label {
background: #5390fc;
color: #fff;
border-radius: 4px;
display: inline-block;
padding: 2px 7px;
margin: 10px 0;
}
HTML
<ul class="list-group">
<li class="list-group-item">
<img src="http://placepic.me/profiles/60-60" width="60" height="60" class="img-circle">
<div class="info">
<strong>
Crondeau Viner, MD
<span>Nov 5th , 2014</span>
</strong>
<br />
<span class="label">Note</span>
<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum.</p>
</div>
</li>
</ul>
Your html contains several invalid tags:
you should use a self closing tag for img i.e. end it with /> instead of >
you should use <br /> instead of <br>
I would also consider changing the nesting of your tags so the spans don't contain br tags as it makes it easier to follow and style correctly.
Finally, if you want to make all the text display to the right of the image change display: inline to display: inline-block (jsfiddle)
<ul class="list-group">
<li class="list-group-item">
<img src="http://placepic.me/profiles/80-80" width="40" height="40" class="img-circle" />
<p class="taro">
<strong>
<b>Crondeau Viner, MD</b>
<label>
Nov 5th , 2014
</label>
</strong>
<br />Note
<br />
<span>hello Dr Jacqueline test - nov 5 </span>
<br />
</p>
</li>
</ul>
And your CSS would become
.taro{
display: inline-block;
margin-left: 200px;
}

CSS Footer - Left hand items are higher than right hand items

I am trying to make a CSS footer but have ran into some major problems.
Here is what my footer looks like
Logo Games Database
Home About Contact
Where the logo is an image at the far left. Games Database appears in text. Both appear about 1 line above
I would like my footer to look like this
Logo Games Database Home About Contact
Alright, I decided to post the full HTML output I received from the browser. I removed the data turbo links and a bunch of the rows in my table because I wanted to be as concise as possible.
<!DOCTYPE html>
<html>
<head>
<title>Games</title
</head>
<body>
<header class='navbar navbar-fixed-top navbar-inverse'>
<div class='navbar-inner'>
<div class='container'>
Games Database
<nav>
<ul class='nav pull-right'>
<li>Home</li>
<li>Help</li>
<li>Profile</li>
<li>Favorites</li>
<li><a data-method="delete" href="/signout" id="signout" rel="nofollow">Sign Out</a></li>
</ul>
</nav>
</div>
</div>
</header>
<h1>Games Database</h1>
<table>
<thead>
<tr>
<th id = 'title_id'><a class="current asc" href="/games?direction=desc&sort=title">Title</a></th>
<th id = 'console_id'>Console</th>
<th id = 'genre_id'>Genre</th>
<th id = 'release_id'>Release Date</th>
</tr>
</thead>
<tbody>
<tr>
<td id = 'title'>Animal Crossing</td>
<td id = 'console'>Gamecube</td>
<td id = 'genre'>Life Simulation</td>
<td id = 'released_on'>2001</td>
<div>
<td>Show</td>
<td>Edit</td>
<td><a data-method="delete" href="/games/36" id="delete" rel="nofollow">Delete</a></td>
</div>
</tr>
<tr>
<td id = 'title'>Donkey Kong Country</td>
<td id = 'console'>Super Nintendo</td>
<td id = 'genre'>Platform</td>
<td id = 'released_on'>1994</td>
<div>
<td>Show</td>
<td>Edit</td>
<td><a data-method="delete" href="/games/35" id="delete" rel="nofollow">Delete</a></td>
</div>
</tr>
</tbody>
</table>
<p>
Add a new game
</p>
<ul class = 'footer'>
<li><img alt="83ec69e47df392e6856aca4a7a276e9b" id="footer-logo" src="http://m1.behance.net/rendition/modules/59245571/disp/83ec69e47df392e6856aca4a7a276e9b.jpg" />
<li id = "footer-left">Games Database</li>
<div id = 'footer-center'>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</div>
</ul>
</body>
</html>
Here is my CSS file
.footer {
display: inline-block;
border-top: 1px solid #eaeaea;
color: black;
bottom: 0;
position: fixed;
li {
display: inline;
}
#footer-center {
float:right;
word-spacing: 20px;
margin-left: 980px;
color: black;
}
#footer-logo {
height: 30px;
width: 50px;
}
}
#logo {
float: left;
padding-top: 10px;
margin-right: 10px;
font-size: 1.5em;
text-transform: uppercase;
&:hover {
text-decoration: none;
}
}
#links {
color: black;
}
I've tried just about everything. I've tried setting the footer to fixed, relative and absolute. I tried setting the bottom property to 0, fiddling around with it, even in the negatives.
I tried margin-top and margin bottom on the left hand side, but just cannot figure this out.
I even tried to post it on jsfiddle, but I had no luck because I can't figure out how to get that site to work.
I'm using bootstrap.
Help is appreciated.
I finally got the CSS to show in CSSDesk, but I'm not sure I trust it, because it doesn't render bootstrap. Anyways, here goes
http://cssdesk.com/eL2J2
You can't wrap three of your list elements in a div the way you currently have it. Here is a potential solution:
-- the plain CSS --
.footer { position: relative; width: 100%; overflow: auto; }
#footer-left { float: left; }
#footer-right { float: right; }
.footer ul { margin: 0; padding: 0; }
.footer li { display: inline-block; list-style-type: none; margin: 0; padding: 0; }
.footer a { color: black; }
#footer-logo { height: 30px; width: 50px; }
#game { float: right; }
-- the HTML --
<div class="footer">
<ul id="footer-left">
<li><img alt="83ec69e47df392e6856aca4a7a276e9b" id="footer-logo" src="http://m1.behance.net/rendition/modules/59245571/disp/83ec69e47df392e6856aca4a7a276e9b.jpg" />
<li id="game">Games Database</li>
</ul>
<ul id="footer-right">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
No idea how this would be implemented in bootstrap, but this should give you a basic idea for how to structure your footer.

CSS <h> Margin help?

I have a margin used to space some headings down away from an image, but despite this method working on other pages, it does not in this instance.
I know there are plenty of alternative solutions, but am curious as to what is wrong with this one. Can anyone help?
<div class="column" style="width: 237px">
<img src="img.jpg" alt="" title="img" width="237" height="300" class="alignnone size-full wp-image-84" />
<h1 style="margin-top: 40px">VAL</h1>
<span class="detailhead">Heading 1</span> <span class="detail">Detail 1</span><br />
<span class="detailhead">Heading 2</span> <span class="detail">Detail 2</span>
</div>
These are all the additional class declarations:
The image class has no associated style (class was inserted by Wordpress).
h1 {
font-size: 17px;
}
span.detailhead{
font-size: 13px;
color:#000000;
}
span.detail {
position: relative;
top: 1.5px;
font-size: 14px;
color:#000000;
}
.column {
display: block;
float: left;
}
Here is the offending style i overlooked:
img {
display: block;
float:left;
margin-right:10px;
margin-bottom:10px;
border-style: solid;
border-width: 1px;
border-color: #ffffff;
z-index: 2;
}
A more specific selector fixed the issue.
Thanks to all for helping me with this seriously schoolboy error!
Could you try adding a style="display:block" to the img tag?
If your using chrome or safari for testing: use the element inspector to check wether your inline setting is not overruled by an !important; declaration in one of the classes.
Edit: To quickly test this you can also add " !important;" to your inline css.

IE7 - Floated Image Disappears!

Ok. Here's the situation. I am styling a comments section on one of my websites. Here's an example markup:
<ol class="comments">
<li>
<a href="/view/profile/id/2">
<img src="/images/photo-thumb.gif" alt="johndoe" />
</a>
<p class="pad-top"><em>written on Sunday 2nd of August 2009 12:12:54 AM by johndoe</em></p>
<p class="pad-top pad-bottom">One more comment :D:D:D</p>
<div class="clear"></div>
</li>
<li>
<a href="/view/profile/id/2">
<img src="/images/photo-thumb.gif" alt="johndoe" />
</a>
<p class="pad-top"><em>written on Thursday 30th of July 2009 02:59:48 AM by johndoe</em></p>
<p class="pad-top pad-bottom">Testing comments lalala<br />
<br />
Testing comments lalala<br />
<br />
Testing comments lalala</p>
<div class="clear"></div>
</li>
</ol>
And here is how I'm styling it:
.comments li {
margin-top: 1em;
padding: 0 1em;
background: #3a3a3a;
}
.comments img {
float: left;
margin: 1em 1em 1em 0;
border: 1px solid #4f5055;
}
.clear {
clear: both;
}
.pad-top {
padding-top: 1em;
}
.pad-bottom {
padding-bottom: 1em;
}
Everything works great in all browsers except IE7 where the floated image disappears. To demonstrate, here is how it looks in IE8, Firefox etc (that's how it's supposed to look):
http://richardknop.com/pic2.gif
And here is how it looks in IE7:
http://richardknop.com/pic1.gif
Anybody knows how to fix this? I have already tried floating the anchor instead and many other tricks but I can't get it to work correctly in IE7.
IE7 has some guillotine and BG color bugs, but they're usually associated with using :hover. I don't know if that's what's happening in this case, but the solution is a typical one: give an element layout; specifically, give layout to .comments li.
.comments li {
overflow: auto;
}
This has worked for me when I came across a similar problem:
img {position:relative;}
Not sure about best practices, but I would put the inside of a div block, then float that block.
I would also add clear:both to the .commments li section of the CSS.
Also encountered this problem and found this solution: http://css-class.com/articles/explorer/guillotine/

Resources