CSS: Which property should I use here to break the line? - css

Take a lot at the fiddle below and you would observe that when the line is about to end, the li elements break abruptly. Like, in the first line, after 4 li elements, the next li element breaks and the red circle comes in the same line while the text part moves to the next line.
Here is how I have defined the list elements in CSS:
.popular ul li:before { // Its this part of the code which is making the things
content: "\2022 "; // happen like this. If I remove this part, everything
color:red; // works fine.
}
.popular ul li{
display: inline;
padding: 4px 7px 4px 5px;
background-color:#ededed;
border-radius:5px;
border:2px solid #dcdcdc;
}
Here is the JsFiddle Link http://jsfiddle.net/e7rjW/.
Could someone please tell me how to correct this thing?

Change the display:inline to inline-block
.popular ul li{
display: inline-block;
padding: 4px 7px 4px 5px;
background-color:#ededed;
border-radius:5px;
border:2px solid #dcdcdc;
}
Fiddle: http://jsfiddle.net/e7rjW/5/

Replacing .popular ul li:before with .popular ul li a:before in the CSS fixes your issue.
See the updated JSFiddle.
EDIT: This doesn't work correctly in Chrome, as pointed out by #Nagarjun:
http://img577.imageshack.us/img577/6770/o7g.png
So you'll probably want to use his answer.

try this
http://jsfiddle.net/e7rjW/6/
replace this classess
.popular ul li{
display: inline;
padding: 4px 7px 4px 5px;
background-color:#ededed;
border-radius:5px;
border:2px solid #dcdcdc;
text-wrap:none;
float:left;
}
.popular ul li a{
display: inline-block;
color:#777;
font-family:Arial;
font-size:15px;
font-weight:700;
text-decoration:none;
text-shadow:0 1px 7px #fff;
}

Related

menu layout altering, vertical instead of horizontal on initial load

I have been struggling with this problem for some time now mostly because, it only happens every now and then and I also do not know where to begin on narrowing down the cause of this problem. So occasionally, when my website page loads, the menu bar, which should be horizontal, will load vertically and aligned all the way to the right side of the header.
As I said before this only happens every now and then sometimes it loads just fine, and the menu layout usually corrects itself (horizontally) after refreshing or reloading the page once
here is the css code for the menu
div.hideSkiplink
{
margin:0px auto 0px 195px;
position:absolute;
bottom:0;
right:0;
}
div.menu
{
background-color:#080808;
padding: 0px auto 4px auto;
}
div.menu ul
{
background-color:#080808;
list-style:none;
margin: 0px;
padding: 0px;
width: auto;
}
div.menu ul li a, div.menu ul li a:visited
{
background-color: #080808;
/* border: 1px #585B5E solid; */
border-right:1px solid #585B5E;
color: #dde4ec;
display: block;
line-height: 2.15em;
padding: 4px 20px;
text-decoration: none;
white-space: nowrap;
}
div.menu ul li a:hover
{
background-color: #bfcbd6;
color: #465c71;
text-decoration: none;
}
div.menu ul li a:active
{
background-color: #465c71;
color: #cfdbe6;
text-decoration: none;
}
and below are pictures of what is happening vs. what it should look like.
Incorrect...
Correct...
Any Tips on how to figure out why this is happening are greatly appreciated.
I still haven't been able to figure this out, anyone have any thoughts?
I don't know if it would be some script thats loading before this that is haulting the menu loading or what. Any suggestions on how to figure out why it is doing this would be helpful.
I think you il have display: block property, may be from some parent element.
try to fix it like this:
div.menu > ul li{
float: left !important;
}
if this help this mean you have simple problem this display: block propery.

CSS Adding a triangle

I have an tag, with the following markup:
#leftMenu ul li a {color: #111; text-decoration: none; display: block;}
And I want to be able to hover over it, and display a triangular end. Similar to this shape:
http://www.promotionalpromo.com/Upfiles/Prod_v/1-7-8-x-2-7-8--Long-Arrow_2010017055476.jpg
But not with the same dimensions, more along the lines of:
width: 200px; height: 20px;
Either I chop the two ends, (border-top-right and border-bottom-right) or I add css on with :after, however I need all this to happen when the user hovers of the tag.
How can I achieve this?
I found this site very usefull :
http://apps.eky.hk/css-triangle-generator/
when i needed to create triangles.
it generates a triangle for you.
Now after u generate the triangle, all u need to do is use :before or :after on your desired element to make it work, in your case hover as well.
Just for reference this is how I did it:
#leftMenu ul li a {color: #111; text-decoration: none; display: block; position: relative;}
#leftMenu ul li a:hover {color: #555; text-decoration: underline; background: #EEE; }
#leftMenu ul li a:hover:after
{
content:"";
float:right;
position:absolute; top:0; right:-12px; width:0; height:0;
border-style: solid;
border-width: 13px 0 12px 12px;
border-color: transparent transparent transparent #EEE;
}

jQuery tabs need shifting

I am having trouble with aligning jQuery tags, I've used a bit of a code and changed it and styled it myself, however the align seems to be leaving a space on the left, which I don't want, and I'm not sure how to get rid of it. Here's what I mean...
http://postimage.org/image/8k5rcz941/
This is the CSS code:
.usual {
color:#111;
padding:15px 20px;
margin:8px auto;
}
.usual li { list-style:none; float:left; }
.usual ul a {
display:block;
padding:6px 10px;
text-decoration:none!important;
margin:1px;
margin-left:0;
font:10pt Verdana;
color:#FFF;
background:#444;
}
.usual ul a:hover {
color:#FFF;
background:#111;
}
.usual ul a.selected {
margin-bottom:0;
color:#fff;
background:#003663;
border-bottom:1px solid snow;
cursor:default;
}
.usual div {
padding:10px 10px 8px 10px;
*padding-top:3px;
*margin-top:-15px;
clear:left;
background:snow;
font:8pt Verdana;
border: 1px solid #d0d0d0;
}
.usual div a { color:#000; font-weight:bold; }
Hope you can help me shift this to the left, I've been trying to figure out what it is, and just can't :(
Thanks and regards.
I'm guessing that the ul has a margin or padding applied. Remove it:
.usual > ul {
margin: 0;
padding: 0;
}
.usual has a left padding of 20px. Is that what you're trying to get rid of?
Inspect your elements in either Google Chrome or using the Web Developer add-on for FireFox. Find the element and check all it's inherited styles; chances are likely, like icktoofay says, you probably have inheritance somewhere. If doing like he said, adding margin & padding = 0 for the UL, you can try the hack !important
.usual ul {
margin: 0 !important;
padding: 0 !important;
}
But note that if you have any other margin/padding that is used on the UL element, you will lose those, either using !important or not because margin: 0 sets all 4 sides. To target just the left side:
.usual ul {
margin-left: 0 !important;
padding-left: 0 !important;
}
Sometimes the hack won't work, that's why it's important to check your inheritance by inspecting the elements in the browser first.

CSS Block Position Question

I'm pretty new to CSS but I'm hoping this is just something obvious I'm missing.
On www.sonogenics.co.uk, the Twitter block appears to be floated to the right or have 40px left margin. I have explicity set the margins to be 0px and cleared the floats etc but there has been no effect. From the Firefox WebDeveloper addon, it appears to be a problem with the .tweet ul but I can't seem to fix it. Can someone explain to me what is going on?
Cheers
Chris
It actually has left-padding and not margin. This is the default styling of a ul element. To cancel it, you should put padding:0; in the #tweet ul style declaration.
A couple of suggestions:
Use Firebug for development, it is far superior to the WebDeveloper add-on. I was able to immediately spot the problem using it
Use a CSS reset stylesheet, to remove those default style declarations and normalize it across browsers (the defaults are not consistent between browsers). The best known is the CSS reset by Eric Meyer, which I personally use on every site I develop.
#chris robinson; i checked your twitter/style.css your main problem is that you declare css wrongly that why the properties are not working.
wrong css declaration :
.twitter #tweets {
background: #111;
padding: 0 0px;
padding-bottom:20px;
text-align:left;
-moz-border-radius: 5px;
border-radius: 5px;
border-color:#AAA;
border-style:solid;
border-width:2px;
margin:0px;
}
.twitter ul, li {
list-style-type: none;
background: #222;
-moz-border-radius: 5px;
border-radius: 5px;
border-color:#AAA;
border-style:solid;
border-width:1px;
padding-left:0px;
padding-right:0px;
padding-bottom:0px;
margin:0px;
-webkit-padding-start:10x;
}
.twitter #tweets a {
color: #AAA;
text-decoration:none;
}
.twitter #tweets a:hover {
color: #AAA;
}
if you check your html your twitter class is inside #tweets not outside of it . So, first correct your css .
Correct css:
#tweets .twitter {
background: #111;
padding: 0 0px;
padding-bottom:20px;
text-align:left;
-moz-border-radius: 5px;
border-radius: 5px;
border-color:#AAA;
border-style:solid;
border-width:2px;
margin:0px;
}
#tweets ul.twitter li {
list-style-type: none;
background: #222;
-moz-border-radius: 5px;
border-radius: 5px;
border-color:#AAA;
border-style:solid;
border-width:1px;
padding-left:0px;
padding-right:0px;
padding-bottom:0px;
margin:0px;
-webkit-padding-start:10x;
}
#tweets .twitter a {
color: #AAA;
text-decoration:none;
}
#tweets .twitter a:hover {
color: #AAA;
}
This should fix it
#tweets ul { padding: 0px; }
uls have a left padding by default in most browsers (i.e. WebKit 40px).
Your styling isn't being applied because of your css selector. Your selector is
.twitter ul, li {}
while your html for the elements are
<div id="tweets">
<ul class="twitter">...</ul>
</div>
Your css selector says "style all ul and li that are descendents of any element with the 'twitter' class". Since the ul isn't contained in an ancestor element with the "twitter" class, it isn't being styled with that rule.
If you want the rule to actually apply, you can either just use the selector
.twitter {...}
or you can re-class the parent div with "twitter",
<div id="tweets" class="twitter">
<ul class="twitter">...</ul>
</div>
or you can use this selector instead,
#tweets ul, li {...}
which more closely matches your original selector.

css - horizontal menu - background-color

I have a horizontal menu. I want to have a border around the menu (not the entire-row, only the space menu is covering). When I put border on ul, it covers the entire row, when I put border on li, it has border between menu items as well.
<ul id="menu" style = "text-align:left;">
<li>...anchor stuff...
</li><li>...anchor stuff...
</li><li>...anchor stuff...
</li><li>...anchor stuff...
</li><li>...anchor stuff...</li>
</ul>
Here is the CSS:
ul#menu
{
padding: 0 0 0px;
position: relative;
margin: 0 0 0;
text-align: right;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
ul#menu li
{
display: inline;
list-style: none;
}
ul#menu li a
{
padding: 0px 0px;
margin-right:20px;
font-weight: bold;
text-decoration: none;
line-height: 2.8em;
}
Kill display: inline on the list items and float them left instead. Float the container as well, which will ensure that it's only as wiide as its contents. Finally, set overflow: hidden on the ul.
Declare ul with display:inline-block. It'll cause ul to take only space necessary to display its contents, not 100% of it.
An example
Use display: inline-block on the ul and add the border to the ul.
If you need IE6 compatibility:
#menu li {
border-top: 1px solid #000;
border-bottom: 1px solid #00;
}
You might be able to use li:first-child (I can't remember, and don't have a copy of IE6 to test with) to apply:
#menu li:first-child {
border-left: 1px solid #000;
}
But you'll likely have to add either a class-name, or id, to the first and last li elements to give them the appropriate border-left and border-right.

Resources