How to remove space above and below the in-line block elements? - html

I can't seem to figure out how to remove space above and below my inline block elements as shown in the image.
P.S line-height doesn't remove the space.
Here is the CSS for all the elements.
nav ul li {
font-size:16px;
display:inline-block;
padding:20px;
border: 3px solid black;
}
Image:
JsFiddle

ul has by default margin and padding, so reset it
body {
padding: 0;
margin: 0;
font-family: sans-serif;
}
header {
background: #00795f;
width: 100%;
padding: 40px 0;
/* 40px top and bottom, 0px left and right */
color: white;
text-align: center;
}
nav {
background-color: #43a286;
color: white;
overflow: hidden;
padding: 0px;
text-align: center;
margin: 0;
}
ul {
/* padding: 0; you may need only the margin */
margin: 0
}
a {
text-decoration: none;
color: inherit;
}
nav ul li {
font-size: 16px;
display: inline-block;
padding: 20px;
border: 3px solid black;
}
ul li:hover {
background-color: #399077;
}
section {
line-height: 1.5em;
font-size: 1.5em;
padding: 40px;
width: 75%;
margin: 0 auto;
}
<header>
<h1>Loving it more everyday</h1>
</header>
<nav>
<ul>
<li> Home
</li>
<li> About
</li>
<li> Blog
</li>
<li> Shop
</li>
<li> Gallery
</li>
<li> Contact
</li>
</ul>
</nav>
<section>
When you try your best, but you don't succeed. When you get what you want, but not what you need. When you feel so tired, but you can't sleep. Stuck in reverse. And the tears come streaming down your face. When you lose something you can't replace.When
you love someone, but it goes to waste. Could it be worse? Lights will guide you home. And ignite your bones. And I will try to fix you. And high up above or down below. When you're too in love to let it go. But if you never try you'll never know.
Just what you're worth. When you try your best, but you don't succeed. When you get what you want, but not what you need. When you feel so tired, but you can't sleep. Stuck in reverse. And the tears come streaming down your face. When you lose something
you can't replace.When you love someone, but it goes to waste. Could it be worse? Lights will guide you home. And ignite your bones. And I will try to fix you. And high up above or down below. When you're too in love to let it go. But if you never
try you'll never know. Just what you're worth
</section>

Related

Gaps at the top and side of navigation bar buttons

I'm creating a website and have run into a minor but incredibly infuriating problem.
I'm creating a Navigation bar and the buttons of the navigation bar have a gap between the far left, and top of the screen. In other words, all buttons have a gap from the top and the leftmost button has a gap from the left of the screen.
The relevant parts of my Stylesheet are shown below.
body {
margin: 0px;
padding: 0px;
font-family: Arial;
}
.navbar_base {
width: 100%;
overflow: hidden;
background-color: rgb(0, 21, 144);
top: 0px;
color: white;
display: block;
}
.navbar_button {
float: left;
padding: 10px;
margin: 0px;
border-radius: 3px;
list-style-type: none;
}
.navbar_button:hover {
background-color: rgb(50, 64, 147);
}
I suspect it's because I have assigned the class to the list rather then the links, but I'm using MVC5 and adding classes to the Html.Actionlink() is cumbersome. I'd like to avoid this solution if possible.
Furthermore I've tried assigning margin: 0px and padding: 0px on ul like so:
ul .navbar_button {
margin: 0px;
padding: 0px;
}
to no avail
Also I am not interested in using Bootstrap at the moment because this is a sort of side project for a specific person and I would like to create something unique for him.
Here is the HTML portion of my code:
<div class= "navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
</div>
I've looked at the following questions as well, but the answers didn't help me.
Gap at top of page despite margin:0 and padding: 0
Why does this div have gaps at top and bottom
How do I get rid of the two gaps?
Note: I do realize I am still a beginner and MVC may be out of my scope but I have job to do soon and I reckoned the fastest way to learn about how to do MVC is to actually do MVC
<div class= "navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
By default ul has some margin left properties , you can remove it by
.navbar_base > ul{ margin-left:0px; }
You need to remove the margin and padding from the ul too (your attempt to do so removed it from the li)
body, ul {
margin: 0px;
padding: 0px;
font-family: Arial;
}
.navbar_base {
width: 100%;
overflow: hidden;
background-color: rgb(0, 21, 144);
top: 0px;
color: white;
display: block;
}
.navbar_button {
float: left;
padding: 10px;
margin: 0px;
border-radius: 3px;
list-style-type: none;
}
.navbar_button:hover {
background-color: rgb(50, 64, 147);
}
<div class="navbar_base">
<ul>
<li class="navbar_button"> #Html.ActionLink("MainPage","MainPage") </li>
<li class="navbar_button"> #Html.ActionLink("About","AboutPage") </li>
</ul>
</div>

Creating a CSS border around custom li bullet

I'm trying to figure out if it's possible to incorporate a css border around an image I imported as a custom bullet for my li's:
ul {
list-style: none;
margin-right: 0;
padding-left: 0;
list-style-position: inside;
}
ul > li {
align-content: center;
display: flex;
margin: 5px 0;
padding-left: 1em;
text-indent: -1em;
}
ul li:before {
/* I'm a different image but found a similar
sized one online for demonstration
purposes seen below */
content: url("https://www.dicentral.com/css/assets/imgs/Flag_Nation_france.png");
border: 1px solid grey;
}
<ul>
<li>Get to know the business</li>
<li>Get to know people (stakeholders, key players, cross-functional partners, etc.)</li>
<li>Learn how the team's priorities impact our mission</li>
<li>Get to know your projects, the team's projects, who's involved, and your onboarding goals</li>
</ul>
The results in the embedded code editor mirror that of the image I'm using.
This is the desired output:
Any ideas? I'm thinking unfortunately I might have to import the icon with border, but am seeing if I can manage without.
Thanks!
Yes, it is quite easy to do, please take a look at the example below. You just mess up things a bit.
You have align-content instead of align-items that makes line positioning incorrect. text-indent results into incorrect offset. I've removed these small issues.
About image itself - I've used em as example because of emoji, but for image it will be better to use px and re-calculate values that are currently defined as em.
ul {
margin-right: 0;
padding-left: 0;
list-style: none;
}
ul > li {
align-items: center;
display: flex;
margin: 5px 0;
}
ul li:before {
/* I'm using the url method to fetch an icon, but
inserted a emoji for demonstration
purposes seen below */
/*content: url("path/to/icon");*/
content: '🚩';
border: 1px solid #808080;
border-radius: 100%;
width: 1em;
height: 1em;
display: inline-block;
padding: 0.25em;
line-height: 1.0;
margin-right: 0.5em;
}
<ul>
<li>Get to know the business</li>
<li>Get to know people (stakeholders, key players, cross-functional partners, etc.)</li>
<li>Learn how the team's priorities impact our mission</li>
<li>Get to know your projects, the team's projects, who's involved, and your onboarding goals</li>
</ul>
there are many ways to achieve result.
1) use image with rounded border as background on "li". background should be no-repeat left center and some padding-left on li.
2) give height, width, inline-block and border-radius to li:before.
You should remove "display:flex" from ul > li
ul {
list-style: none;
margin-right: 0;
padding-left: 0;
}
ul > li {
align-items: center;
display: flex;
margin: 5px 0;
}
ul li:before {
/* I'm using the url method to fetch an icon, but
inserted a emoji for demonstration
purposes seen below */
content: '🚩';
border: 1px solid #808080;
border-radius: 100%;
width: 1em;
height: 1em;
display: inline-block;
padding: 0.25em;
line-height: 1.0;
margin-right: 0.5em;
}

alignment of links in footer

I am trying to clone google's home page.I Started from the footer of the page and got stuck at the alignment of the links in the footer.
my html code:
<div class="footer">
<hr >
<footer >
Advertising
Business
About
Privacy
Terms
Settings
</footer>
</div>
my css code :
.footer{
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
footer{
background-color: #F4F6F7;
height: 45px;
}
hr{
border-color: #CCD1D1;
margin-bottom: 0px;
}
.advertising, .business, .about, .privacy, .terms, .settings{
color: #909497;
font-size: 1.2em;
margin-top: 11px; //THIS LINE.
}
.advertising, .business, .about{
margin-left: 40px;
}
.privacy, .terms, .settings{
margin-right: 40px;
float: right;
}
can anyone tell me, why the line "margin-top : 11px" is not applied to the first 3 links in the footer(advertising,business,about). Screenshot of footer:
Although the above answer will work, a better solution is this:
.footer {
position: absolute;
bottom: 0;
left: 0;
width: 100%
}
footer {
background-color: #F4F6F7;
height: 45px;
}
hr {
border-color: #CCD1D1;
margin-bottom: 0px;
}
.align-left {
float: left;
}
.align-right {
float: right;
}
.footer-links {
list-style-type: none;
}
.footer-links li {
display: inline;
}
.footer-links li a {
color: #909497;
font-size: 1.2em;
margin: 11px 20px 0px;
}
<div class="footer">
<hr/>
<footer>
<ul class="footer-links align-left">
<li>Advertising</li>
<li>Business</li>
<li>About</li>
</ul>
<ul class="footer-links align-right">
<li>Privacy</li>
<li>Terms</li>
<li>Settings</li>
</ul>
</footer>
</div>
By putting the links into separate menus, it allows you to very quickly add and remove links in the future without messing around with CSS classes.
This fixes any margin errors you are having as well, as we're declaring that every anchor tag has a margin-top of 11px. You'll also notice instead of having 40px margin-left and margin-right, I've set each side to 20px which will give the same effect.
You can also use the .align-left and .align-right classes elsewhere in your HTML instead of declaring it in CSS for every class.
There's no need to give each link it's own class when they all have the same style. But if you wanted to highlight a particular link you'd naturally just add a .highlight class onto one of the anchor tags and specify the styling in CSS.
This method also gives full browser support. Flexbox is a little temperamental on IE as I write this.
Hope this helps!
You need to add float:left to your first three links, as you have applied float:right on the last three.
.advertising, .business, .about{
margin-left: 40px;
float:left;
}
I ran it through codepen,it worked when I applied the margin 11px to all elements using the footer as a selector
I also would recommend using flexbox, its alot easier to use, here is an example
`http://codepen.io/HTMLanto/pen/gmNedQ`
Cheers !

How to get rid of space between navbar and picture? [duplicate]

This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 6 years ago.
I can't figure out how to remove this space from my navbar and the picture..
The CSS code I have for the navbar and the image is:
a {
text-decoration: none;
color: white;
padding-right: 5px;
padding-left: 5px;
padding-top: 0;
}
a:hover {
color: black;
}
header {
background-color: #C0C0C0;
margin: 3px 60px 0;
}
li {
display: inline;
border-right: 1px solid black;
border-left: 1px solid black;
border-bottom: 1px solid black;
border-top-left-radius: 0px;
border-top-right-radius: 0px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
nav {
position: relative;
text-align: center;
}
ul {
list-style-type: none;
}
#bikebanner {
position: relative;
left: 65px;
}
#bikebanner is the image id.
And the html goes like so:
<header>
<img src="images/bicyclebanner.jpg" id="bikebanner" alt="People riding bikes." title="Biking">
<h1 id="pagetitle">Cycling Tours</h1>
<nav>
<ul>
<li>About Us</li>
<li>Ask Us</li>
<li>Destinations</li>
<li>FAQ</li>
<li>Reviews</li>
<li>Seminars</li>
<li>Trip Prep</li>
</ul>
</nav>
</header>
Looking for a universal fit as I have other things with white space between them as well.
Thanks.
Try adding this to your css:
img{
display:block;
}
img is of type inline-block which adds a little space which is hard to find.
setting it to block should fix it.
what space you are talking about ?
Keep in mind h1 by default has white space around it
every h1-h6 tag has a margin top and bottom by default. i think if you overwrite this in your css you have what you want.
h1 {
margin: 0;
padding: 0;
}
look at this jsfiddle https://jsfiddle.net/zn7wtdLp/
This drives a lot of people crazy initially and the solution is not obvious, but images, lists and list items end up with a small space like this due to the font size inherited by or set on the img or ul. If you do nothing, the img and ul inherit the body font size (often 14px - 16px) with results in this 0.25rem (or 3.5px - 4px) space issue.
Nav Items
There are two popular solutions:
Float your list items left and make sure that you add a clearfix to your ul or its container, or
My preferred solution: Set the font-size on the ul to 0 and then the font-size on the li to 1rem (or whatever).
So my CSS would look something like this:
ul {
font-size: 0;
list-style: none;
margin: 0;
padding: 0;
}
li {
display: inline-block;
font-size: 1rem;
}
Images
If you set the image to display: block, this would kill the space below the image. This comes with its own caveats as well. For example, if you want it centered after you switch it to display: block;, you'll need to set the side margins to auto. Something like this:
header img {
display: block;
margin: 0 auto;
}
The problem is display:inline. This treats the elements like text, so if you have
<li>...</li>
<li>...</li>
you have the problem you mentioned, because the linebreaks cause a space.
Try to put your list elements like this:
<li>...</li><li>...</li>
For other solutions see here

How to correctly display image in a <li> element?

Ok this is simple thing. I firstly created a usual "Home" Button linking to the Home Page of the website, but the word "Home" looked too obvious. Hence I tried to insert an icon in place of that word, but its not fitting properly. I have tried some things in my css but its messing up the whole (used to create the navigation menu). The screenshot is attached. Please if someone can see whats wrong.
CSS:-
ul#menu
{
padding: 0px;
position: relative;
margin: 0;
}
ul#menu li
{
display: inline;
text-decoration:solid;
}
ul#menu li a
{
color: black;
background-color: #f5b45a;
padding: 10px 20px;
text-decoration: none;
line-height: 2.8em;
/*CSS3 properties*/
border-radius: 4px 4px 0 0;
}
HTML:-
<ul id="menu">
<li id="Home_Link"><img src="../../Image_Data/Home_Icon.ico" id="Home_Icon"/></li>
<li>MEN</li>
<li>WOMEN</li>
<li>KIDS</li>
<li>DESIGN!!</li>
With your current styles you will need to play around with the vertical-alignment and margins for the image, something like:
ul#menu li#Home_Link a img {
vertical-align: text-bottom;
margin-bottom: -5px;
}
As a side note, your use of ID's for elements is not recommended - use classes if needed. And reduce the specificity of your style declarations, e.g. .home-link img