How to position nav element center under parent div? - css

I've added a second nav element to a view, under the site banner. But when the screen is expanded at it's default resolution, the menu is skewed to the left of the site banner.
My aim is to position the menu directly under in line with the site banner. I made a new JSFiddle link of the page setup to explain the current positioning issue.
I did inspect with Chrome dev tools and it look like a padding causing the positioning highlighted in orange:
The menu currently appears of center like this:
Whereas I want position it directly under the "Self Service" div like this:
I've tried reducing the right margin on the nav element's custom CSS in order to push in further right in line with the banner:
#chartNav {
background-color: #614767;
display: inline-block;
padding: 10px 20px 10px 20px;
margin: 0 5% 0 10%;
padding-bottom: 20px;
text-align: center;
}
But the nav menu is still pulling off center of the banner.
Question:
How can I position a nav element center under parent div?
This is a gist of the markup containing the banner site title div and it's containing nav menu:
<div class="container-fluid">
<div class="col-md-2 col-xs-2"></div>
<div class="col-md-10 col-xs-6">
<label class="main-title">Self Service</label>
</div>
<div class="row">
<div class="col">
<div class="col">
<nav>
<ul id="chartNav">
<li><a>Asset Selection:</a></li>
<li>
<a>All <span class="arrow">&#9660</span></a>
<ul class="sub-menu">
<li><input type="checkbox" /> Option 1</li>
<li><input type="checkbox" /> Option 2</li>
</ul>
</li>
<li><a>Date Range:</a></li>
<li>
<input class="input-sm" type="text" name="daterange" value="01/01/2015 - 01/31/2015" />
</li>
<li><a>Profile:</a></li>
<li>
<a>Default <span class="arrow">&#9660</span></a>
<ul class="sub-menu">
<li><input type="checkbox" /> Option 1</li>
<li><input type="checkbox" /> Option 2</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>

Adding this seems to solve the issue, the first two lines align the nav's container to the center, while the third removes that unnecessary left margin that you mentioned.
.col-md-10{
width: 100%;
text-align: center;
margin-left: 0px;
}
check it out https://jsfiddle.net/m7h541vb/3

Related

Responsive CSS - How to bring a li item to the bottom and in desktop have the li item on the top

I have a li item and then a div which follows after it. Inside this div its like a hr tag, just a line with contents to separate. This is the desktop version.
When viewing in mobile version, I want to bring this li item below the div.
I tried with margin-top, the li item moves, but the div also move along with it, to further down.
How to achieve this ?
<li class="ser" s><a href="javascript:void(0);" title="" alt="" ><img src="/con.svg">
</li>
<div class="hbar row row-no-gutters">
<div class="col-sm-4 visible-tablet visible-desktop"> Content1
</div>
<div class="col-sm-4 visible-tablet visible-desktop"> Content2
</div>
<div class="col-sm-4 visible-tablet visible-desktop"> Content3
</div>
</div>
You could try reversing the order of the outer container with flexbox.
<ul class="container">
<li>list item</li>
<div>some content</div>
</ul>
.container{
display: flex;
flex-direction: column-reverse;
}

Foundation - do not want to hide right button of navbar

On wider screens my login button is visible, but on smaller screens it is hidden.
JSBIN http://jsbin.com/nowubuseqeza/1/edit?html,js,output
Relevant code:
<div class="top-bar" data-topbar="" style="background:#074e68">
<ul class="title-area">
<li class="name">
<h1><img class="left" src="images/pluslogo.png" style="margin:2px 1em;height:40px;width:40px" alt="Pacific Medical Training"> Pacific Medical Training</h1>
</li>
</ul>
<div class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active">
Login
</li>
</ul>
</div>
</div>
Is it possible to have this visible in all circumstances? Otherwise my users cannot login.
Change your code to this DEMO
<div class="top-bar" data-topbar="" style="background:#074e68">
<div class="top-bar-section right">
<!-- Right Nav Section -->
<ul class="right show-for-small">
<li class="active">
Login
</li>
</ul>
</div>
<ul class="title-area">
<li class="name">
<h1><img class="left" src="images/pluslogo.png" style="margin:2px 1em;height:40px;width:40px" alt="Pacific Medical Training"> Pacific Medical Training</h1>
</li>
</ul>
<div class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
<li class="active">
Login
</li>
</ul>
</div>
</div>
In the smaller screen, a number of css properties are changing for the title-area and the links in the top-bar. If you add the following, it should bring the login button back on small screens:
//Only use it for screens under 40.063em, using the media query
#media only screen and (max-width: 40.063em) {
.top-bar .name h1 a {
width: auto;
}
.top-bar-section ul {
width: auto;
}
.top-bar-section ul li.active > a {
padding: 0px 15px;
line-height: 45px;
}
.top-bar .title-area {
float: left;
}
}
However, it may need a bit more refinement for very small screens where the "Pacific Medical Training" takes up the whole top-bar and pushes the login button down

Trying to place logo on top of CSS image slider

I am trying to make this website:
http://knightforged.com/stout/index5.html
I am trying to place a logo on top of the slider. It shows behind the slider. The navigation menu shows up on top just fine.
I have tried modifying z-indexes, and I have tried modifying the slider CSS (which comes from here: http://codepen.io/anon/pen/cImqB ) by changing position modifiers.
My professor tried several different things and we still couldn't figure it out.
I'm not sure if it's okay to omit the text since it can be viewed from source via the actual webpage; so if you prefer I can paste it on here.
Thank you.
Here is relevant code:
HTML:
<div class="grid_12">
<div class="grid_4 alpha">
<img src="images/logo.png" class="imgresponsive" />
</div>
<div class="grid_8 omega">
<ul id="nav" class="dropdown menu horizontal">
<li>About
<ul>
<li>Company History</li>
<li>Customer Testimonials</li>
</ul>
</li>
<li>Products
<ul>
<li>Tile</li>
<li>Metal</li>
<li>Shingle</li>
<li>Flat</li>
</ul>
</li>
<li>Project Gallery</li>
<li>Contact Us</li>
<li>Pay Invoice</li>
</ul>
</div>
</div>
<ul class="slides">
<input type="radio" name="radio-btn" id="img-1" checked />
<li class="slide-container">
<div class="slide">
<img src="images/tile_04big.jpg" class="slider_image" />
</div>
<div class="slider_nav">
<label for="img-2" class="prev">‹</label>
<label for="img-2" class="next">›</label>
</div>
</li>
<input type="radio" name="radio-btn" id="img-2" />
<li class="slide-container">
<div class="slide">
<img src="images/tile_13.jpg" />
</div>
<div class="slider_nav">
<label for="img-1" class="prev">‹</label>
<label for="img-1" class="next">›</label>
</div>
</li>
<li class="nav-dots">
<label for="img-1" class="nav-dot" id="img-dot-1"></label>
<label for="img-2" class="nav-dot" id="img-dot-2"></label>
</li>
</ul>
CSS (unworking code):
.imgresponsive {
width:100%;
height:auto;
}
CSS (working code):
.imgresponsive {
width:100%;
height:auto;
position: relative;
z-index: 597;
/* z-index: 10 !important; */
}
You have the z-index on the navigation ul set to 597 and it is showing up. Try setting the class .imgresponsive (which is the class for the logo not th parent div) z-index to 597 and set its position to relative.
You can do it for example by styling your logo with this:
#logo {
position: relative;
z-index: 1;
}
The logo id should be for the image of your logo
This is how it looks: screenshot
Can you try this one,
inline css:
<img style="z-index:10!important;position:relative;" src="images/logo.png" class="imgresponsive">
css:
.imgresponsive{
z-index:10!important;
position:relative;
}

css ul position in new line

i need
at this moment code look
Css
ul#content {height:1%;overflow:hidden;list-style:none;margin:0;padding:0;max-width: 1020px;}
ul#content li{vertical-align:top;display:inline-block;margin:0 2% 26px 0;width:auto;}
* html ul#content li{display:inline;}
*+ html ul#content li{display:inline;}
Html
<ul id="content" >
<li>
<div style="height: 420px;width: 740px;" ></div>
</li>
<li>
<ul>
<li>
<div style="min-width: 220px;">
text
</div>
</li>
<li>
<div style="min-width: 220px;">
text
</div>
</li>
<li>
<div style="min-width: 220px;">
text
</div>
</li>
</ul>
</li>
</ul>
Maybe css media queries are something you want to look in to:
http://css-tricks.com/6731-css-media-queries/
This specific tutorial explains how to make changes to the layout/styles based on screen width.
Basically it allows to conditionally set styles on elements, in this case you could make seperate styles for the ul depending on screen width. Browser support is pretty decent, and as a fallback you could supply some pretty simple js code to handle the not supporting browsers.
I'm guessing you need something like the following for it to look like the second image...
html:
<div id="content"></div>
<ul id="contentList">
<li>Text</li>
<li>Text</li>
...
</ul>
css:
#content {width:740px; height:420px}
#contentList {margin:10px 0; overflow:hidden}
#contentList li {min-width:220px; float:left; list-style:none}

<li> styling with css (chrome problems)

Hello I've got this weird problem with css.
I'm displaying an unordered list
<ul>
<li>
<div class='align-left'>
PMI
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='19' class="elim" name="19">
</div>
</li>
<li>
<div class='align-left'>
GRANDS COMPTES
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='21' class="elim" name="21">
</div>
</li>
<li>
<div class='align-left'>
associations
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='22' class="elim" name="22">
</div>
</li>
<li>
<div class='align-left'>
PME
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='25' class="elim" name="25">
</div>
</li>
<li>
<div class='align-left'>
ecoles privees
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='28' class="elim" name="28">
</div>
</li>
<li>
<div class='align-left'>
organisme
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='32' class="elim" name="32">
</div>
</li>
<li>
<div class='align-left'>
test
</div>
<div class='align-right'>
<img src="/img/delete_icon2.png" id='34' class="elim" name="34">
</div>
</li>
</ul>
now this is accompanied by these css rules:
.align-right{
float: right;
}
.align-left{
float: left;
}
On chrome, the bullet point from the list is actually UNDER the text for the bullet point.
Why did I do this, I want the images to be aligned from top down.
here are screenshots of the problem
thanks in advance.
the code you provided won't cause this problem.
Depending on what you want to do, adding
ul { list-style-type:none; }
or
ul li { padding-left:40px; }
may achieve desired effect.
edit
try adding overflow:hidden; to the li elements
I'd also personally do it like this:
li {
background:url(/img/delete_icon2.png) no-repeat center right;
padding-right:25px; /*might need to adjust */
}
<ul>
<li>PMI</li>
<li>Bla bla</li>
</ul>
no need to over-complicate things.
If you want the DIVS clickable you can just do
<li>PMI</li>
and CSS:
li a { display:block; width:xxx; height:xxx; }
as required.
Try playing with the list-style-position property. Options are inside and outside.
I had the same problem and it seems that you do not have exact control over the position of the default bullet point.
For me the following was working in Firefox and in IE, but in Chrome it is positioned inside the text:
<ul style="list-style-position: outside; margin:0; padding:0;">
<li />
<li />
</ul>
I needed to set margins and paddings for both the list and the list items to get the bullet point(disk) outside the text
<ul style="list-style-position: outside; margin:10px; padding:10px;">
<li style="padding: 10px 0 0 3px; margin-bottom: 8px;" />
<li style="padding: 10px 0 0 3px; margin-bottom: 8px;" />
</ul>
The strange part is, that if I set those bottom margins to anything less than 7 pixel, the bullets jump inside. 8px is the smallest working value, although there is lots of space around and between the elements (they move closer to each other fluently, only the bullet points start to jump).

Resources