Box Model position and flow on menu (position absolute) - html

I'm trying to make a menu and i'm stuck.
I want to know if someone have some idea without make too much black magic (js and stuff).
Here is my CSS:
* {
margin: 0;
padding: 0;
list-style: none;
}
.wrap {
background: red;
}
.ul-one {
background: green;
position: static;
display: inline-block;
}
.ul-two {
background: gray;
position: absolute;
left: 50px;
top: 0;
}
and HTML:
<div class="wrap">
<ul class="ul-one">
<li>um</li>
<li>dois</li>
<li>tres</li>
<li>quatro</li>
<li>
<ul class="ul-two">
<li>__um</li>
<li>__dois</li>
<li>__tres</li>
<li>__quatro</li>
<li>__cinco</li>
<li>__seis</li>
<li>__sete</li>
<li>__oito</li>
<li>__nove</li>
<li>__dez</li>
<li>__once</li>
</ul>
</li>
</ul>
</div>
Here's the jfiddle:
http://jsfiddle.net/4m5g09Lb/
I want the parent (red div) grow with the children ul.
I'm reading on the web a lot and found some solution, but none of them work when use with position absolute.
This structure will be inside more divs, but i think if work for some levels, it will work with a lot of levels.
Thanks in advance.

you can use
ul:nth-child(even){
}
for all even children
ul:nth-child(odd){
}
for all odd children.

Related

How can I make my navigation bar links(About, Services, Projects) "stop running off the screen"-make it stop?

When I try to size down my desktop screen navigation size of 1440px(90em) to any lower width screen, my navigation bar links start dropping off the screen. I have tried using some media query combinations, but nothing to show for it.I haven't got much experience with frontend, so I am a little bit thin on this side. Any long-term fixes to this one?Any hint on this one will be highly appreciated.
HTML header code:
<!--header-->
<header>
<nav class="nav__bar">
<a href="#" class="logo">
<img src="./images/logo.svg" alt="Sunnyside logo">
</a>
<ul class="nav__links">
<li class="nav__item">
About
</li>
<li class="nav__item">
Services
</li>
<li class="nav__item">
Project
</li>
Contact
</ul>
<img src="./images/icon-hamburger.svg" alt="toggle menu icon" class="toggle__menu">
</nav>
</header>
CSS header styles:
header {
height: 5em;
position: absolute;
left: 0;
right: 0;
}
.nav__bar {
height: 100%;
width: 90em;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
flex: 1 1 auto;
padding: 0 2em;
}
.nav__links {
height: 100%;
display: flex;
justify-content: center;
align-items: center;
list-style: none;
}
.nav__item {
margin: 1em;
}
.nav__link {
text-decoration: none;
font-size: 1.125em;
color: hsl(0, 0%, 100%);
font-family: 'Barlow', sans-serif;
transition: all 350ms ease-in-out;
}
.nav__link:hover {
color: hsl(232, 10%, 55%);
}
.toggle__menu {
cursor: pointer;
display: none;
}
In your example code, you set the color of the link text to white... it's white on white. But that's not fully the problem... you should also remove width:90em from the .nav_bar... it's unnecessary. see this codepen https://codepen.io/aequalsb/pen/jOmyJNp
Just simply allow the <nav> to "be itself"... which is a block level element and naturally attempts to stretch out to fit available width.
padding in CSS Sizes the margin inside a button or element. Try using margin: (how many 'px' it's going off the screen); and I've had this problem before:
SOLUTION 1:
use margin-*left or top*: *px is going off screen*
<style>
#button {
width: 100px; /* the width of the button */
position: absolute;
left: 50%; /* always 50% when centering */
margin-left: -50px; /* minus half the size of the element */
}
</style>
<button id="button">Center of page</button>
SOLUTION 2
i've had this problem before, and in best situations, use position: absolute instead of relative if you are positioning the element.
<head>
<style>
.background {
position: relative;
}
.overlap {
position: absolute;
left: 30px;
}
</style>
</head>
</style>
</head>
<body>
<!-- background-element -->
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Circle_Rufous_Solid.svg/1200px-Circle_Rufous_Solid.svg.png" class="background" width="10.5%" />
<!-- Overlap element -->
<img src="https://cdn.onlinewebfonts.com/svg/img_24930.png" class="overlap" width="10%" />
</body>
SOLUTION 3
if none of the above works, consider using javascript: device tester command and redirect to an error page with unsupported devices.
This example will detect a handful of mobile-devices, and if so, it'll redirect to ๐˜ฉ๐˜ต๐˜ต๐˜ฑ://๐˜จ๐˜ฐ๐˜ฐ๐˜จ๐˜ญ๐˜ฆ.๐˜ค๐˜ฐ๐˜ฎ
<script>
if( /Android|webOS|iPhone|iPad|Mahc|Macintosh|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
window.location.href = "http://google.com";
} else {
}
</script>
NOTE: if there is big problem you cannot solve, and none of these work, its best to do research or find some articles to find your answer. Then consider using stackoverflow.

CSS: Positioning items with top-margin

ETA: Thanks for all the help, everyone! These all worked beautifully. Thanks so much for your time!
I'm coding a newsletter (live preview here and my goal for it here) and am trying to get the navigation buttons ('Join Meet Learn Support') to sit about halfway down the logo. When I try top-margin in the navButtons class I'm not seeing any success. I suspect it's a display issue, but I'm not sure --- changing from inline to inline-block didn't really help.
<!DOCTYPE html>
<html>
<head>
<title>The Leaflet</title>
<style>
div
{
display: inline;
}
a
{
text-decoration: none;
}
p
{
text-align:left;
margin-left: 130px;
margin-right: 130px;
max-width: 600px;
}
#logo /* This sets the width for the New Leaf logo at the top. This should not change.*/
{
position:relative;
}
#navButtons
{
position:relative;
right:-240px;
}
#announcementImage
{
margin-left: 120px;
margin-right: 120px;
}
a.joinButton
{
margin-left:40%;
color:white;
background-color: #f7853e;
font-size: 30px;
}
a.navButton
{
color:#494541;
font-size: 22px;
}
</style>
</head>
<body>
<div id="logo"> <! --- Sets up the logo --->
<img src ="images/NLNewsletterLogo.png">
</div>
<div id="nav buttons"> <! --- Navigation Bar--->
<a class = "joinButton" href="url">Join</a>
<a class = "navButton" href="url"> Meet </a>
<a class = "navButton" href="url">Learn </a>
<a class = "navButton" href="url">Support </a>
</div>
<br>
<br>
<br>
<br>
<br>
<div id ="announcementImage"><! --- Lead Image-->
<img src="images/announcementGraphic.png">
</div>
<div id = "announcementText">
<p>Thrive Week is in full swing here at the Leaf. So far, we've had Sharon Perry, head of the State
College Area School District Career Center, help participants identify which of 34 traits,
including the special quality of woo, are strengths they employ in various settings so they can
work smarter. Then Anna Gokieli, owner of Tru Meditation and Yoga, got us staying present and
peaceful even in situations that often trigger stress. Will Snyder brought it home last night by
showing how making art and making money don't have to conflict.
Have a comment on a workshop you've attended or a session you'd like to see in our remaining
Design and Launch weeks? Galen would love to hear from you!</p>
</div>
</body>
Try this
#logo {
display: inline-block;
vertical-align: middle;
}
#nav {
display: inline-block;
vertical-align: middle;
width: 100%;
}
I think what your looking for is:
#logo {
vertical-align: middle;
}
Try adding bottom of something like 60px to div with id nav buttons.
Since this element is position: relative, it's placement can be controlled with left, right, top, bottom, like so:
#nav#buttons {
bottom: 50px;
}
Floating the logo left, and adding margin to the #nav will do the trick.
#logo { float: left; }
#nav {margin-top: 80px; width: 100%; display: inline-block; }
h1.title { clear: left; }
You're almost there. Inline-Block is what I'd use with absolute positioned nav, but you have a generic div {position:inline;} that applies to everything on the page inside of a div. You should be more specific for your logo and nav and just get rid of the generic styling by giving each a class like <div class="WHATEVER"> so you can target the div you want to work on.
Then try this:
#logo {
width: 240px;
display: inline-block;
#nav buttons {
margin: 0px 0px 0px 80px;
display: inline-block;
position: absolute;
top: 80px;}

Hover effect is affecting them all at once, not individually

I have been looking through for the cause of my problem and I haven't had any luck finding anything. I'm not entirely sure if this is my own stupidity or just purely lack of knowledge.
I don't know a lot about coding and I've had a super long day so I may have over looked something. Here is a basic idea of what I'm trying to do.
I want a list of 5 options, and they all have a block under the window so when rolled over it shows this block. (indicated by colour)
Now what I've created when rolled over they all show up, why is this?
Here is the example of what I've created
HTML
<div id="nature">
<a class="sound">
<h4>Forest</h4>
<div class="preview" style="background:red;">
</div>
</a>
<a class="sound">
<h4>Storm</h4>
<div class="preview"style="background:blue;" >
</div>
</a>
<a class="sound">
<h4>Winter</h4>
<div class="preview"style="background:lightblue;" >
</div>
</a>
<a class="sound">
<h4>Dusk</h4>
<div class="preview"style="background:pink;" >
</div>
</a>
<a class="sound">
<h4>ocean</h4>
<div class="preview"style="background:yellow;" >
</div>
</a>
</div>
CSS
#nature {
width: 100%;
position: absolute;
margin: 0;
padding: 0;
bottom: 0;
left: 0;
}
.sound {
margin: 0;
padding: 0;
width: 20%;
height: 130px;
display: inline-block;
float: left;
background: green;
cursor: pointer;
transition: .5s;
-webkit-transition: .5s;
margin-bottom: -50px;
}
.sound:hover {
margin-bottom: 0;
}
.sound .preview {
height: 50px;
width: 100%;
overflow: hidden;
clear: both;
margin: 50px 0 0 0;
}
JSFiddle
easiest way;
#nature > a {
position: relative;
}
.sound {
bottom:-50px;
}
.sound:hover {
bottom:0;
}
fiddle: http://jsfiddle.net/u3ssV/
p.s. also, You can wrap Your content in container with overflow set to hidden..
or i still dont get the point (?) :)
You are applying the :hover effect to .sound, which is the class that is applied to all of the blocks. Therefore when it triggers on any one of those items, the entire class is affected, and all blocks using that class change.
Try id's (identified by #idName in the css) to handle them individually. There may also be a better way to do this with classes to isolate the change that I'm not aware of.

image dishonors z-index and overlays shadow of pseudo-element

I want to cast additional shadows with pseudo-elements ::after and ::before to create sort of a page curl effect. But whenever an <img> is involved its src keeps overlaying the shadow. Is that a general limitation or is there a workaround?
<ul>
<li class="imgContainer"><img class="imgFake" /><br><span class="imageTag">some Title</span></li>
<li class="imgContainer"><img class="imgFake" src="http://wallpaperstock.net/maggie-grace-portrait_wallpapers_14105_1600x1200.jpg"/><br><span class="imageTag">some Title</span></li>
<li class="imgContainer" style="margin-bottom:50px;"><img class="imgFake" src="http://wallpaperstock.net/maggie-grace-portrait_wallpapers_14105_1600x1200.jpg"/><br><span class="imageTag" style="top:auto; bottom:27px;">some Title</span></li>
</ul>โ€‹
http://jsfiddle.net/BpgXC/7/
Please, take a look: http://jsfiddle.net/BpgXC/12/
I've changed img.imgFake z-index:
img.imgFake {
position: relative;
display: block;
width: 400px;
height: 250px;
background: rgba(135,195,235,.5);
padding: 5px;
font: 12px/12px sans-serif;
z-index: -2;
}

Problem with CSS, on position: absolute

I don't know what kind of position shall I announce if the parent has a position: absolute.
Here's the code,
<div id="new_map">
<div id="map_nbc_pop">
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg">
<ul class="nm_left">
<li>Chetwynd</li>
<li>Fort St James</li>
<li>Fort St John</li>
</ul>
<ul class="nm_right">
<li>McBride</li>
<li>Prince George</li>
<li>Prince Rupert</li>
</ul>
</div>
<div class="nm_bubblebelow1"></div>
</div>
</div>
here's the sample CSS, I just remove the other for viewing...
#new_map { position: static }
#map_nbc_pop { position: absolute }
The problem for me is in .nm_bubbletop1, #nm_bubblebg, .nm_bubblebelow1
What position shall I use? Because they are not properly layered on the browser.
<div class="nm_bubblebelow1"></div>
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>
What I want is this,
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg"></div>
<div class="nm_bubblebelow1"></div>
Thank you!
If you need to change how the <div>'s appear without changing the code, position: absolute is your best option:
.nm_bubbletop1, #nm_bubblebg, .nm_bubblebelow1 [
position: absolute;
left: 0;
}
.nm_bubbletop1 {
top: 0;
}
#nm_bubblebg {
top: 100px; /* this is .nm_bubbletop1's height */
}
.nm_bubblebelow1 {
top: 200px; /* this is .nm_bubbletop1's height + #nm_bubblebg's height */
}
That being said, it's hacky. If there's anyway you can just order them the way you want in the HTML, it'll make your life easier.
if you give #new_map a position of relative and then the children you want to arrange a position of absolute this will make the position of those children relative to the parent #new_map ie your origin for coordinates will be the top left corner of #new_map. You can then change the stacking order (z-index) or positioning (top, left, right, bottom) of the children as you like based on where #new_map is.
This is what you mean i think >
<div id="new_map">
<div id="map_nbc_pop">
<div class="nm_bubbletop1"></div>
<div id="nm_bubblebg">
<ul class="nm_left" >
<li>Chetwynd</li>
<li>Fort St James</li>
<li>Fort St John</li>
</ul>
<ul class="nm_right">
<li>McBride</li>
<li>Prince George</li>
<li>Prince Rupert</li>
</ul>
</div>
<div class="nm_bubblebelow1"></div>
</div>
โ€‹
And css:
#new_map { position: static }
#map_nbc_pop { position: absolute }
.nm_bubbletop1, .nm_bubblebelow1 { position:absolute; height:15px; background-color:#ccc; width:100%; }
.nm_bubbletop1 { top:0px; }
.nm_bubblebelow1 { bottom:0px; }
#nm_bubblebg { margin:15px 0px; }
โ€‹This makes the menu flexible, and the top and bottom are always in place. The margin of the middle makes it seamlessly connect.
The fiddle: http://jsfiddle.net/fmDhn/1/