Add Internal Borders but not external - html

I have a grid of square images.
I want to put a border on the inside of each of these but not on the outside of the whole box, as in the image below:
Here's the html setup.
<div class="grid-wrapper">
<ul>
<li><img src="[image url]" /></li>
</ul>
</div>
And the CSS
.grid-wrapper {
margin: 0 auto;
}
.grid-wrapper ul {
list-style: none;
display: block;
}
.grid-wrapper ul li {
padding: 5px;
border: 1px solid #F1F1F1;
}
I've tried putting the border all the way round each of the li elements and then adding a white border on the grid-wrapper to put it over the outer borders but that didn't work.
How can I get this without manually setting each one's border-left/border-bottom etc. The squares are dynamically pulled from the database so each one doesn't have a particular class, they're all identical.
UPDATE
The grid is fluid. When you pull the browser window open, it adds more to the top row (if there's room) and less when you pull the browser window inward. There's no fixed number of icons.

You didn't specify what you want to happen when there's a ragged row at the bottom, so I'm not sure if this meets your requirement fully, but this example may accomplish what you need.
http://jsfiddle.net/52LRd/
It works by setting a border on the bottom and left each of each element, then by budging the ul inside the wrapper 1px up and left, making those edges invisible.
.grid-wrapper {
float: left;
margin: 0 auto;
overflow: hidden;
}
.grid-wrapper ul {
list-style: none;
display: block;
margin: 0;
padding: 0;
position: relative;
top: 1px;
right: 1px;
}
.grid-wrapper ul li {
float: left;
padding: 10px;
border-bottom: 1px solid #F1F1F1;
border-left: 1px solid #F1F1F1;
}
This gets you out of having to try to figure out which list items are in the top row, bottom row, left column, and right column, which would require JavaScript.

Related

how to insert a space in between horizontal unordered lists

I am trying to make the top of my website. I need more spacing in between the logo and the name in the border. My CSS:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.list {
border-style: ridge;
border-color: green;
border-width: 25px;
}
I want more of a space between the image and the name, now it is about a centimeter or two apart.
Use 'margin' properties to create space around elements, outside of any defined borders. There are properties for setting the margin for each side of an element (margin-top, margin-right, margin-bottom, and margin-left).
Sample Code
div {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 100px;
}
If you want to generate space around an element's content or inside of any defined borders, use 'padding'.
Sample Code
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
Refer the below link for more details.
https://www.w3schools.com/css/tryit.asp?filename=trycss_margin_sides
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_lists_menu
You can always use margin-right and apply that to your logo. Remember, however, to not have it mess up your layout on smaller screens.
use
margin : 0 15px; (for side margin) or,
margin : 15px 0: ( for top and bottom margin)
but if you want the space between border and content use padding instead.

I have to pull down list item element without moving down its background image (blue border)

I have problem in my navbar side borders. In the list item of navbar I have used the background image for border (the blue line). Is there any way so I can pull down my two list items little below as you can see in my screenshot. I have to pull down both this list "become a voice over" and "message" a little down.
If I use margin or position both doesn't work for me because border is background image of these list items.
So when I pull down background image border list items moves down too.
I recommend looking into box-sizing: border-box. If you remove that property from .li, .lastItem in the the snippet below you run into the issue you were describing.
It is hard to know for sure since you haven't posted your code. If this isn't the problem you are seeing, please update the snippet (or use jsfiddle) so we can help you further.
.navbar {
color: white;
box-sizing: border-box;
}
ul, li, div {
display: block;
background: blue;
color: white;
margin: 0;
padding: 0;
height: 40px;
}
ul {
float: left;
}
li, .lastItem {
box-sizing: border-box;
border: red solid 1px;
}
li {
float: left;
padding-top: 9px;
border: red solid 1px;
font-size: 20px;
}
.lastItem {
padding-top: 4px;
float: right;
font-size: 30px;
}
<div class="navbar">
<ul>
<li>Hello</li>
<li>World</li>
</ul>
<div class="lastItem">What a fine day</div>
</div>

How can i set height of my banner and vertically align its content to center?

I'm trying to make a banner on my webpage, the part on the top that is 700px wide and 80px high.
Code looks like:
<div class="container-narrow" style="heigth: 80px;">
<img src="#" width="52" height="52" alt="my logo" />
<ul>
<li>About</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
Css:
.container-narrow
{
margin: 0 auto;
max-width: 700px;
background: yellow;
}
ul
{
float: right;
width: 100%;
padding: 0;
margin: 0;
list-style-type: none;
}
a
{
float: right;
width: 6em;
color: black;
text-decoration: none;
padding: 0.2em 0.6em;
}
a:hover {color: #ccc; text-decoration: none;}
li {display: inline;}
What I want is the image and the horizontal menu to be vertically aligned in the center of the 80px. the logo to the left and the menu to the right.
I've tried to set the height and then padd/margin my way to get the job done but it feels rubbish...
Problem:
ul has a width:100%; if you give it a black border you will see that its occupying the width of the page, means it has no space to reside on the left of the logo inside the yellow header.
Removing this width will give the following result: http://jsfiddle.net/YBVe6/
Now since the header has a fixed max width, which is 700px, there's many ways to center the logo and the menu.
Fastest way I can think of is the following:
Give ul a display: inline-block;, (remove float: right;) then give the header a text-align: center;, here's the result : http://jsfiddle.net/YBVe6/1/
And if you want the menu to be displayed in the upper part, just add vertical-align: top;.
To start of, it's a good practice if you have an external CSS, don't put additional CSS in your HTML blocks:
<div class="container-narrow">
and put the height style in your css sheet, as you have a class setup for your div there anyway.
Second, making typo's is a pain if you want your CSS to work properly, so instead of heigth you should use height, will make you div actually 80px high.
Third of all: margins are there the position elements. Use them!
.container-narrow
{
height: 80px;
margin: 0 auto;
max-width: 700px;
background: yellow;
}
img
{
margin-top:14px;
}
ul
{
float: right;
padding: 0;
margin: 0;
list-style-type: none;
margin-top:25px;
}
a
{
width: 6em;
color: black;
text-decoration: none;
padding: 0.2em 0.6em;
}
a:hover {color: #ccc; text-decoration: none;}
li {display: inline;}
Edit
This is mostly applicable for vertical alignment. If you want to auto-center horizontally, you can make use of the margin:auto concept. This is possible because a page can't extend beyond the browser width (browser height can extend as you have scrolling available as default behavior).

Unwanted spacing below image

I'm trying to create a fixed-position footer at the bottom of my page. but there's an issue with spacing below the image and the bottom of the viewpoint that is unwanted:
Base Image:
The Issue:
The padding below the image is unwanted.
HTML:
<div id="containerBarKonge">
<ul>
<li><img src="./kongelogo.png" /></li>
</ul>
</div>
CSS:
#containerBarKonge {
position: fixed;
bottom: 0px;
width: 100%;
z-index:9999;
padding: 0px;
margin: 0px;
}
#containerBarKonge > ul {
position: relative;
list-style-type: none;
padding: 0px;
padding-left: 2px;
margin: 0px 20px;
min-width: 1053px;
background-color: #900;
}
#containerBarKonge > ul * {
padding: 0px;
margin: 0px;
}
Try setting the vertical align to bottom on the image:
#containerBarKonge img { vertical-align: bottom; }
The issue comes from the image having a default property of "display: inline;" - which is the equivalent to saying "have this image run along like text."
Images should rarely be employed as inline containers. Instead, an image should be defined as either display: block or inline-block. This gives you much precise control over your iamges versus - just align this to the top or bottom. What if you want the image 1px from the bottom? With vertical-align you can not.
So the solution is to do the following:
#containerBarKonge > ul li {
display: block;
height: 20px; /* or however tall it is */
}
#containerBarKong > ul li img {
display: inline-block;
/* Assuming it is 18px tall and you want it at the bottom: 20 - 18 = 2px */
margin: 2px 0 0 0;
}
there you go. You have PRECISe control of the positioning of the image while it retains its ability to run along like text.

Positioning 6 elements in two rows evenly - having trouble (CSS)

I've been trying a few different ways to position 6 different elements in this way:
I've tried using two separate unordered lists stacked on top of each other but I couldn't get them to scale with page stretch properly. I also tried using a table but I can't seem to get the elements to all position in the center of their individual tds.
Here is my css from my unordered lists:
.button ul {
height: auto;
list-style: none;
}
.button li {
display: inline-block;
list-style: none;
margin: 0 18% 0 0;
padding: 0;
vertical-align: top;
}
and these are contained within this:
.newfooterright {
float: left;
width: 33.333333%;
top: 0%;
left: 0%;
height: 250px;
padding: 0 0 0 0;
margin: 0;
font-family: RobotoLight;
text-decoration: none;
text-transform: none;
font-size: 1.5em;
text-align: center;
color: #ffffff;
vertical-align: middle;
}
here's a jsfiddle with this method:
jsFiddle for unordered list
I think an unordered list is probably the way to go... I'm just not sure how to get all of the elements to align in the center of each li. The elements on the bottom seemed to be stuck in the bottom right corner of the li. The bottom elements are also widgets from google+, twitter, and facebook, so I'm not sure if that is affecting their position.
Basically the elements need to be able to do this:
Scale with window width in terms of their spacing (to a point, I don't need an uber small phone layout or something. Something like padding-right or margin-right?)
When the elements scale the bottom element needs to stay aligned with the top element in the center
positioned like in the picture!
Any suggestions on how to get this positioned cleanly would be appreciated!
Thank you so much!
Here is one way you might do it, I am proposing the following HTML scaffolding:
<div class="newfooterleft">
<ul class="button">
<li><a class="twitterbutton" href="#"></a></li>
<li><a class="facebookbutton" href="#"></a></li>
<li><a class="googleplusbutton" href="#"></a></li>
</ul>
<ul class="widget">
<li>(I put the corresponding widget here)</li>
<li>(I put the corresponding widget here)</li>
<li>(I put the corresponding widget here)</li>
</ul>
</div>
and the following CSS:
.newfooterleft {
width: 40%;
border: 1px solid red;
overflow: auto;
}
.twitterbutton {
background: url("http://www.placekitten.com/100/100") no-repeat;
background-size: 100%;
}
.twitterbutton:hover {
}
.facebookbutton {
background: url("http://www.placekitten.com/100/100") no-repeat;
background-size: 100%;
}
.facebookbutton:hover {
}
.googleplusbutton {
background-image: url("http://www.placekitten.com/100/100");
background-size: 100%;
}
.googleplusbutton:hover {
}
.newfooterleft ul {
display: table;
width: 100%;
margin: 0;
padding: 0;
}
.newfooterleft ul li {
display: table-cell;
width: 33.3333%;
margin: 0;
padding: 0;
text-align: center;
vertical-align: middle;
border-left: 1px solid red;
}
.newfooterleft ul li:first-child {
border-left: none;
}
ul.button li {
height: 100px;
}
.button li a {
display: inline-block;
width: 62px;
height: 62px;
}
.button {
border-bottom: 1px solid red;
}
ul.widget li {
background-color: white;
height: 150px;
}
In this case, I am adjusting the unordered lists to behave like tables and table cells.
It works reasonably well except if the width gets too narrow, but this may be okay depending on your application.
You could use a min-width to constrain it.
You could also try some variations with display: table-row.
Demo Fiddle: http://jsfiddle.net/audetwebdesign/2U3D9/
In general, if you want to select every 3 elements, you have to use :nth-child(). In the parenthesis, you can put any combination of n and a digit. There are also some keywords, such as odd and even. So in this case, you are going to have 3 different :nth-child() selectors. It will look like this
li:nth-child(6n+1), li:nth-child(6n+2), li:nth-child(6n+3) {
color:red;
}
The 6n selects every sixth element, and the +1 adds that number. So if you plug in 1, you will get back 7 for the first selector, 8 for the second, and 9 for the third.
Here is a fiddle demonstrating this in use
Here is an article explaining nth-child in more depth
It looks like your li's should be all ready to collapse.You could give your li's a fixed height and width (creating boxes if you will), then add a style for each image to have a relative position and use top and left to get them into position (remember, percentages can scale for you). I've dropped hints on how to accomplish this as you wanted to learn by doing, but let me know if you need the CSS!