CSS - My border-bottom resizes when I resize my browser - css

I use a border-bottom on my navigation div, which is 100% wide. When I resize my browser window, the border-bottom suddenly gets cut off to te size that I just resized my browser to.
Does anyone know a solution to this?
my css:
#nav {
clear: both;
height: 40px;
width: 100%;
text-align: center;
border-bottom: 3px #ff6600 solid;
}
#nav ul {
margin: 0 0 0 670px;
white-space: nowrap;
}
#nav ul li {
display: inline-block;
list-style-type: none;
}
#nav ul li a {
display: inline-block;
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #000;
text-transform: uppercase;
letter-spacing: 3.5px;
}
My html:
<div id="nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio</li>
<li>Hobby's</li>
<li>Links</li>
<li>Contact</li>
</ul>
</div>

By assigning a margin left value of 670px, you are effectively setting a width to your page.
Thus, if the page resizes to something smaller than that (or that plus the text in the list items), it will appear that things get cut off because they extend beyond the frame of the window.
In order to have it be completely dynamic on width based on the window size, you'd need to have absolutely no hard-coded set values. You could try using a % for the margin, or you could use an alternate css style based on the width of the window.

I've found the answer!
By looking at other posts, someone said that the 100% width only applies to the 'viewport' of the screen. So thats why the div gets cut off.
To solve this you have to add a min-width in pixels to the body in css.
So in my case I changed it to:
body {
min-width: 1439px;
}

i think this way is better
change
#nav ul {
margin: 0 0 0 670px;
white-space: nowrap;
}
to
#nav ul {
float: right; // instead of margin: 0 0 0 670px;
margin: 0; //reset ul default properties
padding: 0; //reset ul default properties
}
also change this
#nav ul li a {
display: inline-block;
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #000;
text-transform: uppercase;
letter-spacing: 3.5px;
}
to
#nav ul li a {
display: inline-block;
padding: 0 20px; // padding only for left and right, just use line-height instead of padding-top and padding-bottom
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
text-decoration: none;
color: #000;
text-transform: uppercase;
letter-spacing: 3.5px;
line-height: 40px; // same value as navigation height (#nav) , no need to use padding for top and bottom
}

Related

Remove padding/margin between elements in shrink-to-fit container

I want the yellow div to just be tall enough and only reach the very bottom part of the letter g.
After adding a list it seems to not work despite having 0 padding or margin and displaying as an inline-block.
Also there shouldn’t be a gap between the green list and ‘get a quote’ orange section.
To summarise, I want to get rid of the yellow (well still be there but behind the other colours), and shift the green up to be just under the orange.
#footer-right {
float: left;
width: 360px;
height: 200px;
background: #96F;
}
.footer-text-section-wrap {
background: #ff0;
width: auto;
height: auto;
display: inline-block;
}
f1 {
color: #333;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times, serif, georgia, serif, helvetica;
font-size: 20px;
border-bottom: 1px solid #ccc;
padding: 0 0 10px 0px;
background: #FCC;
}
ul.footer {
list-style-type: none;
padding: 0px;
color: #666;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times, serif, georgia, serif, helvetica;
font-size: 20px;
background: #0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
Add a margin reset to remove unwanted gaps between elements. Something like this: * {margin:0}. This rule resets the margins applied by the browser to all properties. Or you could simply target the ul with ul.footer {margin:0}.
Then add padding-top: 10px to the ul to compensate for the padding-bottom: 10px on the f1 above. OR, add display: block to the f1.
The reason the padding-bottom on the f1 doesn't simply push down the ul is because the f1 is a custom element. As such, it has no basic styles applied by the browser and CSS properties fallback to initial values. The initial value of the display property is inline.
An inline box cannot grow in height. Hence, the padding-bottom:10px simply overlaps the line box, intruding into the element below. By changing the display to block, the f1 will act like a normal block element and push away the ul.
* { margin: 0; }
f1 { display: block; }
#footer-right {
float: left;
width: 360px;
height: 200px;
background: #96F;
}
.footer-text-section-wrap {
background: #ff0;
width: auto;
height: auto;
display: inline-block;
}
f1 {
color: #333;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times;
font-size: 20px;
border-bottom: 1px solid #ccc;
padding: 0 0 10px 0px;
background: #FCC;
}
ul.footer {
padding: 0;
list-style-type: none;
color: #666;
font-weight: 100;
font-family: verdana, arial, "Times New Roman", Times;
font-size: 20px;
background: #0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
More information: Proper way to apply CSS to HTML5 custom elements
This is a quick resolution using margin changes to remove the yellow space like you asked. Remember you can inspect elements and see where space is being created by highlighting the element's markup then viewing the diagram shown normally on the bottom left of the window.
#footer-right{
float:left;
width:360px;
height:200px;
background:#96F;
}
.footer-text-section-wrap{
background:#ff0;
width:auto;
height:auto;
display: inline-block;
}
f1{
color:#333;
font-weight:100;
font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
font-size:20px;
border-bottom:1px solid #ccc;
padding:0 0 10px 0px;
margin: 0 0 10px 0px;
background:#FCC;
}
ul.footer {
list-style-type:none;
padding: 0px;
margin: 10px 0 0 0; /*This is all that I added or changed*/
color:#666;
font-weight:100;
font-family:verdana,arial,"Times New Roman", Times, serif,georgia,serif,helvetica;
font-size:20px;
background:#0CC;
}
<div id="footer-right">
<div class="footer-text-section-wrap">
<f1>Get a Quote</f1>
<ul class="footer">
<li>About</li>
<li>Contact</li>
<li>Outsourcing</li>
</ul>
</div>
</div>
<ul> have default margins (20px on top and bottom), you should add margin: 0; to your ul.footer styles to remove the extra yellow created by the margins.
You have no margin in your ul.footer..
First Option.. You can just do margin:0px; in your ul.footer.
Second Option.. You can take out the yellow background, and do margin-top:-10px; in your ul.footer.
(Not the actual negative number.. That is just guesstimating.)
Either one works, but the first option is easiest and less painful.

CSS hide first li separator on each line - responsive horizontal css menu

Is there a way to hide the separator in the first element on each line?
I have a responsive horizontal menu that adds extra lines when the window becomes smaller.
To make matters worse, the end user can add and remove items from this menu, or just change the order of the menu items.
Using first-child is not an option, because that only works for the first line. When the screen becomes too small the following lines will have the separator on their first li element.
#block-views-solutions-block{
box-sizing: border-box;
text-transform: uppercase;
font-weight: bold;
width: 92%;
max-width: $maxWidth;
margin: 20px auto 0 auto;
padding: 15px 0 0 0;
background-color: $colorBlue;
.content{
box-sizing: border-box;
width: 100%;
overflow: hidden;
}
ul{
margin: 0 !important;
padding: 0 40px;
text-align: center;
}
li{
display: inline-block;
padding: 0 !important;
&:before {
position: relative;
top: 0.125em;
display: inline-block;
width: 1px;
height: 1em;
border-left: solid 2px #fff;
content: " ";
}
&:first-child{
&:before{ border-left: none; }
}
}
a{
display: inline-block;
padding: 0 10px;
color: #fff;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
h2{
color: #fff;
font-size: smaller;
padding-bottom: 5px;
}
}
Looks fine here:
Does not work for the 2nd or following lines:
Looks horrible on very small screens:
I've been trying out solutions on here and other websites, but none seem to do the trick.
I found a solution to this issue, with a couple of caveats:
The solution requires that the list be left- or right-aligned, and won't work with a centered list.
The solution requires that the ul element's overflow be hidden, which could pose a problem if you're also hoping to have dropdown menus.
The solution itself is very simple:
Use ::before or ::after to add the separator, depending on whether your nav is left- or right-aligned.
Position the separator relative to its initial position such that it sits outside its list item.
Use padding on the opposite side of the list item to create the space for its adjacent list item's separator.
Set overflow: hidden; on the ul element so that any separators which fall outside the container are hidden.
Here it is in action:
ul {
font-size: 0;
overflow: hidden;
padding: 0;
}
li {
font-size: 16px;
display: inline-block;
margin: 0;
padding: 0;
color: gray;
position: relative;
padding-right: 2rem;
}
li::before {
content: "|";
position: relative;
left: -1rem;
font-weight: bold;
color: black;
}
<ul>
<li>Item 1</li>
<li>Another Item</li>
<li>This Is Nice</li>
<li>Another</li>
<li>And Another</li>
<li>And Yet Another</li>
</ul>

How to align items in second (and further) column, so that the changing value (increasing characters) do not push

I have a pretty specific question: I'm building something like a simple flat table (I don't use table itself because of rounded borders issue).
I'm using unordered list here and the problem is that I can't figure out how to align items in the second column, taking into account that the content should be dynamic (e.g. changing numbers).
Here's the markup for one row:
<section class="ktbl_head">
<ul>
<li>VALUE</li>
<li>VALIDITY</li>
</ul>
</section>
<section class="ktbl_mid_wht">
<ul>
<li>500 units</li>
<li>15 days</li>
<button class="btn btn-sm getdramz pull-right">GET</button>
</ul>
</section>
And CSS:
.ktbl_head {
padding: 15px 0 0 0;
height: 100%;
background-color: #ebe7e7;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.ktbl_head ul li {
display: inline;
padding-right: 135px;
font-family: "Open Sans", sans-serif;
font-size: 14px;
font-weight: 300;
color: #888888;
}
.ktbl_mid_wht {
background-color: #ffffff;
height: 100%;
padding: 20px 0 0 0;
}
.ktbl_mid_wht ul li {
display: inline;
text-align: left;
padding-right: 90px;
font-family: "Open Sans", sans-serif;
font-size: 18px;
font-weight: 400;
color: #888888;
}
Thanks for your attention!
here is my implementation on aligning the table without the table tag:
HTML
<div class="container">
<section class="ktbl_head">
<ul>
<li>VALUE</li>
<li>VALIDITY</li>
</ul>
</section>
<section class="ktbl_mid_wht">
<ul>
<li>500 units</li>
<li>15 days</li>
<button class="btn btn-sm getdramz pull-right">GET</button>
</ul>
</section>
CSS
.container {
border-radius: 10px;
border: 1px solid rgb(200,200,200);
overflow: hidden;
}
section {
font-family: "Open Sans", sans-serif;
width: 100%;
}
section:nth-child(2n+1) {
background-color: #ebe7e7;
}
section ul {
padding: 0;
margin: 0;
height: 65px;
}
section ul li {
width: 45%;
line-height: 65px;
display: inline-block;
}
section ul li:first-child {
padding-left: 35px;
}
Result
Explanation
You see, in the HTML, I added a new div as a container to create the curved corner with border-radius (the overflow: hidden needs to be used so that the content is encapsulated by the container).
For the CSS, section maintains general property such as font-family. Furthermore, section:nth-child(2n+1) is used to create background-color every other element starting with 1st,3rd,5th,... element. The selectors section ul, section ul li, and section ul li:first-child are used to make the CSS selectors more semantic (it makes clean code and easy to maintain in the future). Please see the code below for the demo. Happy coding!
PLAYGROUND
Give all the li's a width in which all of the content-length will fit..

I need to center the navigation bar

I'm lost... I tried the other answers given in the questions with no results.
Here, my CCS:
ul.nav { padding-top: 5px; font-family: 'OFL Sorts Mill Goudy TT', Georgia, serif; float: left; }
ul.nav li { margin-left: 7px; }
ul.nav a { font-size: 17px; color: #918f8f; text-decoration: none; text-shadow: 1px 1px 0px #fff; padding: 15px 6px 18px; }
ul.nav a:hover { color: #000000; text-shadow: 1px 1px 0px #fff; }
How can i center my navigation bar?
You can give your UL a fixed width and center like this:
ul.nav {
width: 200px;
margin: 0 auto;
}
If this navigation isn't supposed to be a sidebar, then remove the float: left;
Try this
body{ text-align:center;}
{And rest of your code...}
and it will be in center.
Remove float:left;
add a width.
add margin:0 auto;
`
css
ul.nav {
padding-top: 5px;
font-family: 'OFL Sorts Mill Goudy TT', Georgia, serif;
width: 300px;
margin: 0 auto;
}
Remove the float first of all - it will throw your list over to the left of the screen. Then, you have two options:
Give the List a fixed width, then use margin:0 auto.
ul.nav {
width: 40em;
margin: 0 auto;
}
This if fine if you will always have a set amount of links in your nav bar. Not so useful if this changes frequently, or even dynamically. I would prefer the following solution, although an additional bit of markup is required
Use a wrapping element, styled display:table
The HTML:
<nav class="my-class" role="navigation">
<ul>
...
</ul>
</nav>
Then your CSS:
.my-class {
display: table; /*centers its contents*/
width: 100%; /*make sure it doesn't collapse*/
margin: 0 auto;
}
ul {
whatever /*just don't use text align!*/
}
Now it doesnt matter how much you put in that list, it will always center for you.

Titles in css menu change width while hovering

I am implementing a very simple css menu. However, if I select a menu title in the menu bar (and thus open the menu associated with it) the width of the title extends to the width of the menu, which is not desired (i.e. the width of the title should not change). Check out the JSFiddle, or have a look at the markup:
<div id="menu">
<ul>
<li>you
<ul>
<li>register...</li>
<li>login...</li>
<li>forgot password...</li>
</ul>
</li>
<li>.</li>
<li>qan</li>
<li>.</li>
<li style="width: 20px"><a class="site">be</a>
<ul>
<li>be</li>
<li>do</li>
</ul>
</li>
</ul>
</div>
and the css definitions:
#menu {
font-family: Arial, Helvetica, sans-serif;
padding: 0px 5px;
font-size: 12px;
line-height: 18px;
color: darkgrey;
position: absolute;
top: 0px;
left: 0px;
height: 20px;
background-color: black;
z-index: 3;
/*opacity: 0;*/
white-space: nowrap;
}
#menu ul {
margin: 0px;
padding: 0px;
list-style-type: none;
list-style-image: none;
}
#menu>ul>li {
font-weight: bold;
display: inline-block;
float: left;
padding: 2px 1px 0px 1px;
width: auto;
/*width: 10px;*/
}
#menu a { color: inherit; text-decoration: none;}
#menu>ul>li>a:hover { background-color: grey;}
#menu>ul ul {
display: none;
background-color: lightgrey;
padding: 2px 5px;
line-height: 14px;
min-width: 100px;
}
#menu>ul ul>li {
color: black;
padding: 2px 8px 2px 5px;
margin: 0px -3px;
}
#menu>ul ul>li:hover { color: lightgrey; background-color: grey;}
#menu>ul>li:hover ul { display: block;}
Since the menus are generated dynamically and contents meant to change on the fly and the font used is proportional, I cannot just set the widths of a title to a constant value which suppresses the resize. The width of the title should be determinded solely by the width of the text.
It used to work when I had implemented yuimenus, but that did all kinds of stuff to my CSS, the ramifications of which I found hard to control, so now I cooked up the menu by myself and am quite happy with it, save for the width change, and I haven't figured out which part of yui suppressed that. Any suggestions?
I don't agree with max-width.. this will make the link's width content-independent
use position:absolute; for the submenu: jsFiddle
Set width in li
Your updated example :- http://jsfiddle.net/8U5An/8/
Css:-
#menu ul li {
width: 25px;
}
See some useful example as well , how they handle same case by using width only :-
http://www.diy.com/diy/jsp/index.jsp?noCookies=false
http://www.puregrips.com/

Resources