align div's to bottom with margin applied - html

how can we align all the list items to the bottom of the parent separated by a margin.
If I apply position: absolute; bottom: 0, all elements align to the bottom but margins are discarded.
#bars0 {
width: 472px;
height: 258px;
position: relative;
}
#bars0 li {
border: solid red 1px;
width: 30px;
height: 50px;
margin-right: 95px;
position: absolute;
bottom: 0
}
<div id="bars0">
<ul><!-- update: added ul -->
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>

Any reason why you can't surround the <li> with a <ul> tag and absolutely position the <ul>? That way you could control the margin of internal <li>??
The HTML:
<div id="bars0">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
The CSS:
#bars0 {
width: 472px;
height: 258px;
position: relative;
}
#bars0 ul {
position: absolute;
bottom: 0;
}
#bars0 li {
border: solid red 1px;
width: 30px;
height: 50px;
margin-right: 95px;
vertical-align: bottom;
display: block;
float: left;
}
#bars0 li:last-child {
margin-right: 0;
}
Thusly: http://jsfiddle.net/RYBFF/1/
To address your recent request on the comments: Just remove the margin from the last item in the list using :last-child on the <li> as shown above.

I think you're trying to do something like this:
<style type="text/css">
#container {
position: relative;
height:200px;
border:1px solid red;
}
#bars{
position:absolute;
bottom: 5px;
}
#bars ul li {
float: left;
min-width:100px;
}
</style>
<div id="container">
<div id="bars">
<ul>
<li>Test</li>
<li>Test 2</li>
</ul>
</div>
</div>
Here's a jsFiddle to demonstrate: http://jsfiddle.net/YYCZc/2/

Related

After pseudo elements to display contents in another div

I have two div(s), one contains a list e.g. About, partners and so forth. In another divs i want to insert another list. I cant figure out how use the after pseudo element to display the contents of the second div when i hover on About (which is inside the first div) i have tried various things and still cant figure out. Thank you for any help
<div class="firstscreen">
<div class="header">
<div id="trademark">
<img src="images/coin.png" id="logo">
<h2 id="logoName">Test</h2>
</div>
<div id="divList">
<ul id="list">
<li id="About">About</li>
<li>Test</li>
<li>Partners</li>
<li>Contact</li>
</ul>
<div id="abouthover">
<p>Testing</p>
</div>
</div>
</div>
***** css code below *****
html body {
margin: 0px;
padding: 0px;
background-color:#F4F6FF;
}
.firstscreen{
height: 63em;
background: url("images/shopping.jpeg");
}
/* header is a first main div on the first page that contains two divs trademark and divList */
.header {
width: 100%;
position: fixed;
display: flex;
background-color: white;
top:0px;
border: solid red;
}
/* travemark is a div containing the logo plus logoName*/
#trademark {
width: 15%;
display: flex;
}
#logo {
width: 70px;
height: 70px;
object-fit: contain;
}
#logoName {
float: right;
font-size: 24px;
padding-left: 10px;
color: #1a237e;
}
/* divList is a div containing <ul> lists*/
#divList {
width: 30%;
text-align: center;
margin-left: 20%;
padding-top: 10px;
border: solid purple;
}
#list li {
display: inline;
margin: 20px;
font-size: 20px;
color: #1a237e;
}
#About::after {
}
#abouthover {
border: solid green;
position: relative;
border: solid green;
display: block;
position: absolute;
}
Below is the code to show and hide list on About :hover inside same div under about.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="divList">
<ul id="list">
<li id="About">About</li>
<li>Test</li>
<li>Partners</li>
<li>Contact</li>
</ul>
<div id="abouthover" style="display: none;">
<p>Testing</p>
</div>
</div>
</body>
<script src = "https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function() {
$("#About").hover(function() {
$("#abouthover").show();
});
$("#About").mouseout(function() {
$("#abouthover").hide();
});
});
</script>
</html>

a href not working and not resizing

My a href inside a div is not working I saw that the width and height was 0px, so I tried to increase size, but it doesn't get increased.
Each dot is supposed to send you to another page in the onepage scroller I'm making
.dotstyle-scaleup{
float: right;
margin-right: 3%;
}
.dotstyle-scaleup li{
background-color: #eeeeee;
width: 15px;
height: 15px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
.dotstyle-scaleup #current1{
background-color: #54a59f;
width: 20px;
height: 20px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
<div id="wrapper">
<!-- Landings -->
<div class="section" data-anchor="page1" style="background-color: red">
<div class="dotstyle-scaleup">
<ul>
<li id="current1"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>
As the elements in question contain no content, declaring height and width properties won't be enough.
Consider declaring a display property, in addition to specifying a height and width property for the nested anchor elements (a) e.g:
.dotstyle-scaleup li a {
width: 100%;
height: 100%;
display: block;
}
Code Snippet Demonstration:
.dotstyle-scaleup {
float: right;
margin-right: 3%;
}
.dotstyle-scaleup li {
background-color: #eeeeee;
width: 15px;
height: 15px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
.dotstyle-scaleup #current1 {
background-color: #54a59f;
width: 20px;
height: 20px;
border-radius: 50%;
margin: 80px 0 0 0;
list-style: none;
}
/* Additional */
.dotstyle-scaleup li a {
width: 100%;
height: 100%;
display: block;
}
<div id="wrapper">
<!-- Landings -->
<div class="section" data-anchor="page1" style="background-color: red">
<div class="dotstyle-scaleup">
<ul>
<li id="current1">
</li>
<li>
</li>
<li>
</li>
<li>
</li>
<li>
</li>
</ul>
</div>
</div>

Center align Logo and align UL horizontally around it

I am trying to capture a layout that I have seen a few different places. The layout has a fixed header with an image centered, and then a horizontal UL that is split around the logo. Attached is the image that I feel represents this.
I need a suggestion to achieve splitting the UL around logo. Right now the UL is always under and not split.
http://jsfiddle.net/jgac8/1/
Here is some markup that I have been attempting:
HTML
<header>
<h1 id="logo"></h1>
<nav>
<ul>
<li>about</li>
<li>services</li>
<li>location</li>
<li>contact</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(../img/PP_Logo_Vert_White.png) center no-repeat;
}
nav {
padding: 0px;
margin: 0px;
font-size:16px;
font-weight: 100;
clear:left;
}
nav ul {
padding: 0px;
margin: 0px;
list-style: none;
}
nav li {
display: inline-block;
padding: 0 50px;
}
You might have to do a bit of tweaking but I believe it is what you want.
HTML
<header>
<h1 id="logo"></h1>
<nav id="left">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
<nav id="right">
<a href="#" ></a>
<ul>
<li>about</li>
<li>services</li>
</ul>
</nav>
</header>
CSS
header {
width: 100%;
height: 150px;
text-align:center;
position: fixed;
top: 0;
left: 0;
background:#FF7D0D;
border-bottom: 1px solid #CCC;
z-index:100;
}
#logo {
display: inline-block;
padding:5px 0 0 0;
width: 80px;
height: 150px;
background: url(http://findicons.com/files/icons/2141/web_design_creatives/128/small_smile.png) center no-repeat;
}
#left{position:absolute; left:10%; top:5px; list-style:none}
#right{position:absolute; right:10%; top:5px; list-style:none}
li{list-style:none}
There are many ways to go about this. Depending on how dynamic your site will be. If you are creating it with static html and css I would simply create a container, put three divs inside the container splitting it up how you want. In the first and third div create two separate menus. In the center put the logo. Something like the code below. At a certain width you can create some css media queries to bring it down and make it one navigation.
The very basic idea:
Example of html:
<div class="container">
<div class="left-nav">
</div>
<div class="logo">
</div>
<div class="right-nav">
</div>
</div>
Example CSS:
.container {
float: left;
width: 100%;
margin: 0;
padding: 0;
}
.left-nav {
float: left;
width: 400px;
}
.right-nav {
float: left;
width: 400px;
}
.logo {
float: left;
width: 200px;
}

HTML/CSS - How can I position these nested unordered lists correctly?

I am looking for some help resolving an issue im having with positioning the following unordered list elements that are contained in a div which has relative positioning:
The html structure of the UL:
<div id="accountBox" class="account_settings_box">
<ul>
<ul>
<li class="profileImage">
<img src="images/profileimage.jpg" alt="Profile Image" />
</li>
<li class="profileName">Your name</li>
<li class="profileEmail">Your email</li>
</ul>
<li>Messages</li>
<li>Settings</li>
<li>Password</li>
<li>Sign out</li>
</ul>
</div>
and the CSS for this list:
.account_settings_box ul ul {
display: inline-block;
margin: 0;
padding: 0;
width: 100%;
height: 150px;
outline: 1px solid blue;
}
.account_settings_box ul ul li {
display: inline-block;
border: none; /* Reset the border */
}
.profileImage {
float: right;
display: block;
width: 150px;
height: 150px;
outline: 1px solid purple;
}
.profileName, .profileEmail {
width: auto;
height: auto;
width: 150px;
height: 150px;
}
.account_settings_box ul ul li:hover {
outline: 1px solid red;
}
.profileImage img {
width: 150px;
height: 150px;
}
I am having difficultly with the embedded ul, i.e, .account_settings_box ul ul element.
The image below shows what it currently looks like.
I am trying to achieve the follow:
Have the image floating to the right, and have the "your name" and "your email" positioned to the left of the image (basically where they are currently).
Thanks for your help in advance.
Sam :)
Half of your struggles are likely around your first child <ul> element nested below the parent one, which should be contained within its own <li>:
<div id="accountBox" class="account_settings_box">
<ul>
<li>
<ul>
<li class="profileImage"><img src="images/profileimage.jpg" alt="Profile Image" /></li>
<li class="profileName">Your name</li>
<li class="profileEmail">Your email</li>
</ul>
</li>
<li>Messages</li>
<li>Settings</li>
<li>Password</li>
<li>Sign out</li>
</ul>
</div>
From there, I think you want to update your CSS as follows:
.account_settings_box ul {
margin: 0;
padding: 0;
width: 100%;
outline: 1px solid blue;
}
.account_settings_box ul li ul { display: block; }
.account_settings_box ul > li {
display: block;
overflow: hidden;
border: none; /* Reset the border */
}
.profileImage {
float: right;
width: 150px;
height: 150px;
outline: 1px solid purple;
}
.profileName, .profileEmail {
overflow: hidden;
width: 150px;
height: 150px;
}
.account_settings_box ul ul li:hover {
outline: 1px solid red;
}
.profileImage img {
width: 150px;
height: 150px;
}

I need to position my navbar within a div

I've tried everything from text-align to setting margins. I want the nav bar to be centered horizontally and at the bottom of the div vertically.
html: http://www.joekellywebdesign.com/businesssample/index.html
<div id="navbar">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li><a class="MenuBarItemSubmenu" href="projects.html">Projects</a>
<ul>
<li>Restaurant</li>
<li>House</li>
<li>Mall</li>
</ul>
</li>
<li>About</li>
<li><a class="MenuBarItemSubmenu" href="services.html">Services</a>
<ul>
<li><a class="MenuBarItemSubmenu" href="residential.html">Residential</a>
<ul>
<li>Housing</li>
<li>Storage</li>
</ul>
</li>
<li>Business</li>
<li>Government</li>
</ul>
</li>
<li>Contact</li>
</ul>
</div>
css: http://www.joekellywebdesign.com/businesssample/css/styles.css
/* CSS Document */
* {
margin:0px;
padding:0px;
}
body {
background-color:#FF0;
}
#wrapper {
width:900px;
margin:10px auto;
background-color:#FFF;
}
#logo {
float:left;
width:200px;
background-color:#FFF;
}
#navbar {
float:right;
text-align:center;
width:700px;
margin: auto;
background-color:#FFF;
}
You could do something like this:
<style type="text/css">
div#container {
position:relative;
width: 500px;
height: 300px;
border: 1px solid black;
}
div#menu-container {
position: absolute;
bottom: 0;
width: 100%;
}
div#menu {
position: relative;
text-align: center;
}
</style>
<div id="container">
<div id="menu-container">
<div id="menu">
Hello World!
</div>
</div>
</div>
Check out this jsFiddle for a demonstration.
Using an absolute position would easily get it to the bottom:
You'd apply this to the #navbar: position: absolute; bottom: 0px;
Then you'd apply this to the parent: position: relative;
However, now that you've applied an absolute position, you should use a similar technique to center it horizontally. Since your navbar is 700px, we can use some math to center it using the same absolute position.
You'd apply this to the #navbar: left: 50%; margin-left: -350px;
Working example: http://jsfiddle.net/ky9av/
You can try this.
ul.MenuBarHorizontal {
margin-top: 8%;
float: right;
}
You can try with this,
ul.MenuBarHorizontal {
cursor: default;
font-size: 100%;
list-style-type: none;
margin: auto;
padding: 0;
width: 512px;
}
Secondly, as per your design, the navbar ends exactly where you ul ends,
so you might try this
#navbar {
background-color: #FFFFFF;
float: right;
margin: auto;
margin-top: 49px;
text-align: center;
width: 700px;
}