justified all images in div without any space - html

How to justify all images inside a div so that there is no any space left in the left-side and the right-side of the div.
Here is my HTML:
<ul class="thumnails">
<li class="img-thum">
<img src="broward.jpg"/>
<p class="thum-capt">How a Squad of Ex-Cops Fights Police Abuses</p>
</li>
<li class="img-thum">
<img src="honey.jpg"/>
<p class="thum-capt">The Men's Rights Movement and the Women Who Love It</p>
</li>
<li class="img-thum">
<img src="bottles.jpg"/>
<p class="thum-capt">Bottled Water Comes From the Most Drought-Ridden Places in the Country</p>
</li>
<li class="img-thum">
<img src="snyder.jpg"/>
<p class="thum-capt">6 Dumb Things Dan Snyder Has Said About the Name of His Football Team</p>
</li>
</ul>
And here my CSS
If I am setting the padding-right with value, then there will be a space in the right-side.
.thumnails {
width: 100%;
display: block;
float: left;
overflow: hidden;
padding: 0;
margin: 12px auto;
position: relative;
list-style: none;
}
.thumnails .img-thum {
width: 23%;
display: inline-block;
padding: 0;
padding-right: 1.5%;
margin: 0 auto;
}
.thumnails .img-thum img {
width: 100%;
padding: 0;
margin: 0;
}
.thumnails .img-thum .thum-capt {
width: 100%;
float: left;
overflow: hidden;
display: block;
position: relative;
padding: 0;
margin: 0;
font-weight: bold;
font-size: 14px;
font-family: serif;
}
My Fiddle

Try to read this article by Chris Coyer:
http://css-tricks.com/equidistant-objects-with-css/
Your css should be like this:
.thumnails {
width: 100%;
display: block;
float: left;
overflow: hidden;
padding: 0;
margin: 12px auto;
position: relative;
list-style: none;
text-align: justify; /* <== add this */
}
.thumnails .img-thum {
width: 23%;
display: inline-block;
padding: 0;
margin: 0 auto;
}
.thumnails .img-thum img {
display: inline-block; /* <== and this */
width: 100%;
padding: 0;
margin: 0;
}
.thumnails .img-thum .thum-capt {
width: 100%;
float: left;
overflow: hidden;
display: block;
position: relative;
padding: 0;
margin: 0;
font-weight: bold;
font-size: 14px;
font-family: serif;
}
/*and this*/
.thumnails:after {
content: '';
width: 100%; /* Ensures there are at least 2 lines of text, so justification works */
display: inline-block;
}
please see this demo

To ensure proper sizing it's nearly always worth using box-sizing:border-box so that padding and borders are included in width calculations.
Then the are two simple methods (based on your current code) although there are other options available.
JSfiddle (Inline-block)
Jsfiddle (Floats)
CSS re Inline Block
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.thumnails {
width: 100%;
display: block;
float: left;
overflow: hidden;
padding: 0;
margin: 12px auto;
position: relative;
list-style: none;
background:black;
font-size:0; /* required to remove white space */
}
.thumnails .img-thum {
width: 25%;
display: inline-block; /* change to float:left for float version */
padding: 0;
margin: 0 auto;
}
.thumnails .img-thum img {
width: 100%;
padding: 0;
margin: 0;
}
.thumnails .img-thum .thum-capt {
width: 100%;
float: left;
overflow: hidden;
display: block;
position: relative;
padding: 0;
margin: 0;
font-weight: bold;
font-size: 14px;
font-family: serif;
}

try like this: Demo
Just update this css to solve this problem.
CSS:
.thumnails .img-thum {
width: 23%;
display: inline-block;
padding: 0;
margin: 0;
float:left;
}
Updated fiddle Link
Space between images: Link. Hope you need like this

Solved Your Problem >> Images Without Space and justified in middle
Test in Full Screen >> FullScreen Fiddle
Modified css
.thumnails {
width: 100%;
display: block;
float: left;
overflow: hidden;
padding: 0;
margin:1%;
position: relative;
list-style: none;
white-space:no-wrap;
}
.thumnails .img-thum {
width: 22.5%;
display: inline-block;
padding: 1%;
margin: 0 auto;
}
.thumnails .img-thum img {
width: 100%;
padding: 0;
margin: 0;
}
.thumnails .img-thum .thum-capt {
width: 100%;
float: left;
overflow: hidden;
display: block;
position: relative;
padding: 0;
margin: 0;
font-weight: bold;
font-size: 14px;
font-family: serif;
}

Related

How do I align the bullets to middle in a <li> tag?

So I want to create a bar like that. I found a code about it and I modified it a little bit, originally it was a timeline. So my problem is that I can't align the bullets to middle in the li tag. How could I achive that?
ul.language-bar {
max-width: 29em;
width: 100%;
padding: 0 18px;
height: 2em;
margin: 0;
padding: 0;
font-size: 10px;
/* change font size only to scale*/
}
ul.language-bar li {
width: 15%;
float: left;
height: 100%;
list-style: none;
position: relative;
margin: 0;
}
ul.language-bar li.empty:before {
background: #fff;
border: 0.3em solid #f98d9c;
box-sizing: border-box;
}
ul.language-bar li:before {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
background: #f98d9c;
width: 2em;
height: 2em;
border-radius: 2em;
z-index: 2;
}
.language-container .language-bar {
justify-content: center;
display: flex;
}
<div class="language-container">
<ul class="language-bar">
<li></li>
<li></li>
<li></li>
<li class="empty"></li>
<li class="empty"></li>
</ul>
</div>
You need to add these three lines to your ul.language-bar li:before class
position: absolute;
left: 50%;
margin-left: -1em;
This will
unbind bullets to make it possible to position them directly
move every bullet to the center of its parent li (since it is the first parent element having positions:relative)
shift every bullet 1em (half of bullet's width) to the left to make it perfectly centred.
ul.language-bar {
max-width: 29em;
width: 100%;
padding: 0 18px;
height: 2em;
margin: 0;
padding: 0;
font-size: 10px;
/* change font size only to scale*/
}
ul.language-bar li {
width: 15%;
float: left;
height: 100%;
list-style: none;
position: relative;
margin: 0;
}
ul.language-bar li.empty:before {
background: #fff;
border: 0.3em solid #f98d9c;
box-sizing: border-box;
}
ul.language-bar li:before {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
background: #f98d9c;
width: 2em;
height: 2em;
border-radius: 2em;
z-index: 2;
position: absolute;
left: 50%;
margin-left: -1em;
}
.language-container .language-bar {
justify-content: center;
display: flex;
}
<div class="language-container">
<ul class="language-bar">
<li></li>
<li></li>
<li></li>
<li class="empty"></li>
<li class="empty"></li>
</ul>
</div>
By not trying to center an absolutely positioned pseudo element, like you're currently doing.
You will have to nest a block element inside of the li element and center that.
Like so:
ul.language-bar {
max-width: 29em;
width: 100%;
padding: 0 18px;
height: 2em;
margin: 0;
padding: 0;
font-size: 10px;
/* change font size only to scale*/
}
ul.language-bar li {
width: 15%;
float: left;
height: 100%;
list-style: none;
position: relative;
margin: 0;
}
ul.language-bar li.empty span {
content: '';
display: block;
position: relative;
margin: 0 auto;
background: #fff;
border: 0.3em solid #f98d9c;
box-sizing: border-box;
width: 2em;
height: 2em;
border-radius: 2em;
z-index: 2;
}
ul.language-bar li span {
content: '';
display: block;
position: relative;
margin: 0 auto;
background: #f98d9c;
width: 2em;
height: 2em;
border-radius: 2em;
z-index: 2;
}
.language-container .language-bar {
justify-content: center;
display: flex;
}
<div class="language-container">
<ul class="language-bar">
<li><span></span></li>
<li><span></span></li>
<li><span></span></li>
<li class="empty"><span></span></li>
<li class="empty"><span></span></li>
</ul>
</div>
This is obviously quick and dirty to illustrate the point and would need to be optimized.
Another possibility would be to use Flexbox for the layout. Still, it needs a separate element inside of the li elements to work.
With some changes for a shorter CSS...
:root {
--scale: 20px;
}
.language-container {
display: table;
margin: 0 auto;
}
.language-container ul {
list-style : none;
font-size : var(--scale);
}
.language-container ul li {
display: inline-block;
position: relative;
background: #f98d9b;
width: 2em;
height: 2em;
border-radius: 2em;
}
.language-container ul li.empty:after {
position: absolute;
left: 0.3em;
top: 0.3em;
content: '';
display: block;
width: 1.4em;
height: 1.4em;
border-radius: 1.4em;
box-sizing: border-box;
background: #fff;
}
<div class="language-container">
<ul>
<li></li>
<li></li>
<li></li>
<li class="empty"></li>
<li class="empty"></li>
</ul>
</div>

Space <li> evenly?

I have OCD and the following needs to be fixed (the spacing of word's in my navigation bar).
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: left;
width: 20%;
max-width: 80px;
display: block;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
All I need is the words to be evenly spread out with the image still intact in the middle like the picture dictates.
Notice how the word art is unevenly spread compared to the right side?
I am the first one to say that I am building my own website and I am new to CSS/HTML scripting.
Appreciate the help,
Thanks.
Use display: table / table-cell for the list / list items.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
Removing the float: left and the display: block from the nav ul li CSS selector and then adding
display: flex;
flex-flow: row wrap;
justify-content: space-between;
to the nav ul CSS selector will change the display from block to flexible boxes, allowing for the text to be more evenly spread out throughout the entire element
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
// float: left;
width: 20%;
max-width: 80px;
// display: block;
flex: 1;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 90%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 5%;
left: 5%;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>
EDIT:
I added a few characters around the word art in the link to give it some spacing to resemble the other links.
is how you create whitespace in HTML
Something like this (with slightly changed markup)?
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
max-width: 400px;
background-color: #333;
padding: 0;
margin: 1em auto;
display: flex;
height: 30px;
}
nav ul {
display: flex;
height: 30px;
margin: 0;
padding: 0;
}
nav ul:nth-child(1), nav ul:nth-child(3) {
flex: 1;
justify-content: space-between;
}
nav ul:nth-child(1)::before, nav ul:nth-child(3)::before,
nav ul:nth-child(1)::after, nav ul:nth-child(3)::after{
content: '';
}
nav ul:nth-child(2) {
width: 18%;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
max-width: 80px;
display: block;
}
nav ul:nth-child(2) li {
width: 100%;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
left: 0%;
}
<div class="navContainer">
<nav>
<ul>
<li> art </li>
<li> download </li>
</ul>
<ul>
<li><img src="http://www.pd4pic.com/images/eye-black-fan-symbol-design-sun-flower-circle.png"></li>
</ul>
<ul>
<li> portfolio </li>
<li> product </li>
</ul>
</nav>
</div>
Try this, just change the nav percentage as per your requirement. Also for more accurate results you can add media query.
body {
width: 100%;
background-color: #e6e6e6;
font-family: Miramonte;
margin: auto;
}
.navContainer {
height: 30px;
width: 100%;
margin: auto;
padding-top: 30px;
}
nav {
width: 100%;
list-style: none;
max-width: 75%;
background-color: #333;
padding: 0;
margin: 1em auto;
overflow: visible;
height: 30px;
}
nav ul:before {
display: table;
content: " ";
}
nav ul {
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
}
nav ul li {
text-align: center;
overflow: visible;
height: 30px;
margin: 0;
padding: 0;
list-style-type: none;
float: none;
width: 1%;
max-width: 80px;
display: table-cell;
position: relative;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
color: #d9d9d9;
overflow: visible;
line-height: 30px;
display: block;
position: relative;
}
a:hover {
color: #e6e6e6;
}
a img {
width: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
position: absolute;
bottom: -30px;
right: 0;
left: 0;
}
<body>
<div class="navContainer">
<nav>
<ul>
<li> art
</li>
<li> download
</li>
<li>
<a href="home.html">
<img src="image/symbol.png">
</a>
</li>
<li> portfolio
</li>
<li> product
</li>
</ul>
</nav>
</div>
</body>

What is wrong with my nav?

Everything else on the page expands or shrinks as the page is resized, except the list that makes up the nav. What am I doing wrong? It's as though the first item is anchored to the left.
codepen: http://codepen.io/kiddigit/pen/mEPENJ?editors=1100
<header>
<img src="images/m_and_m_logo.png" />
<ul id="nav">
<li>Gift Baskets and Catering</li>
<li>Tasting Calendar</li>
<li>Membership</li>
<li>Special Events</li>
</ul>
</header>
*{
width:100%;
border:0px solid black;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
header {
width: 100%;
margin: 0 auto;
}
#nav, li {
display: inline;
margin-right: 10%;
}
header img {
width: 50%;
display: block;
margin: 0 auto;
}
footer li {
padding: 15px;
margin-top: 100px;
display: inline;
}
.social_icons {
width: 5%;
margin: 20px;
}
#body {
padding-top: 20px;
padding-bottom: 20px;
width: 90%;
margin: 0 auto;
height: 900px;
}
#box_left {
float: left;
width: 48%;
height: 100%;
}
#box_left, p {
text-align: center;
}
#box_right {
float: right;
width: 48%;
height: 100%;
}
#box_right, p {
text-align: center;
}
#store {
font-size: 22px;
font-weight: 800;
}
footer {
text-align: center;
margin: 0 auto;
width: 90%;
height: 100px;
}
Not sure what you are after, but you might want to change this selector:
#nav, li {
display: inline;
margin-right: 10%;
}
to this:
#nav li {
display: inline;
margin-right: 10%;
}
(no comma after #nav- otherwise those settings apply both to #nav AND to all li elements on that page)

list items not displaying correctly

hey guys i am using bourbon neat framework to create a responsive thumbnail gallery. Now it generated the css and somehow when i resize the thumbs seem to be out of position.
here the code i used
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; }
body {
margin: 0;
padding: 0;
background-color: #f4f4f4; }
.galleryContainer {
*zoom: 1;
max-width: 77.0625em;
margin-left: auto;
margin-right: auto;
max-width: 1200px !important; }
.galleryContainer:before, .galleryContainer:after {
content: " ";
display: table; }
.galleryContainer:after {
clear: both; }
.galleryContainer .galleryList {
float: left;
display: block;
margin-right: 2.35765%;
width: 100%;
border: 2px solid red; }
.galleryContainer .galleryList:last-child {
margin-right: 0; }
.galleryContainer .galleryList ul {
list-style: none;
margin: 0;
padding: 0; }
.galleryContainer .galleryList li {
float: left;
padding: 0;
margin: 0;
width: 20%;
padding: 0px; }
#media screen and (min-width: 1338px) {
.galleryContainer .galleryList li {
width: 10%; } }
.galleryContainer .galleryList img {
width: 100%;
height: 100%; }
you can check out the problem here in my demo page here DEMO
Please tell me where i am doing it wrong.
thanks.
It would appear that the float: left that you have set is causing the issue when resizing. Using li elements in this instance I would adopt a display-inline block approach. You will need to add three declarations to the parent in order to remove the margin associated with inline-block elements.
You CSS
.galleryContainer .galleryList li {
float: left; <-- remove this
display: inline-block;
padding: 0;
margin: 0;
width: 20%;
padding: 0px;
font-size: 0px;
}
.galleryContainer .galleryList ul {
list-style: none;
margin: 0;
padding: 0;
font-size: 0px; <-- add this
letter-spacing: 0px; <-- add this
word-spacing: 0px; <-- add this
}

html/css header and footer not filling the whole space

Hello I'm having a problem with my layout, when I'm resizing it, it's not filling the whole space. Please check it out here
My sample code:
html, body {
margin: 0;
padding: 0;
height: 100%;
}
p, a, h1 {
font-family: "Trebuchet MS", Helvetica, sans-serif;
}
.container {
width: 100%;
min-height: 100%;
position: relative;
}
.content {
width: 96%;
max-width: 720px;
min-width: 600px;
margin: 0 auto;
padding: 10px;
padding-bottom: 245px; /* Height of the footer element */
}
.headerWrapper {
position: absolute;
height: 85px;
background: #19A347;
z-index: 9000;
width: 100%;
}
#header {
width: 960px;
margin: 0 auto;
position: relative;
}
.logo {
position: absolute;
}
.logoimg {
display: block;
width: 155px;
height: 85px;
text-indent: -9999px;
}
.globalnav {
float: right;
clear: right;
padding: 8px 8px 0 0;
display: block;
}
.nav-menu {
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.nav-menu li {
display: inline;
}
.nav-menu a {
display: inline-block;
padding: 15px;
margin: 5px;
color: #fff;
font-size: 20px;
text-decoration: none;
}
.nav-menu a:hover {
color: #66C285;
}
#footer {
height: 245px;
background: #1c1c1c;
position: absolute;
bottom:0;
left:0;
width: 100%;
}
.cols-container {
margin: 0 auto;
max-width: 960px;
min-width: 900px;
overflow: hidden;
}
.cols-container div {
width: 20%;
float: left;
padding: 5px;
margin: 15px;
}
.heading {
font-size: 20px;
color: #fff;
background: #009933;
padding: 5px 0 5px 10px;
}
#footer li, a {
color: #fff;
text-decoration: none;
}
#footer a:hover {
color: #999;
};
I don't know what's making it act like this way. Help is truly appreciated.
You should change the width between header and headerWrapper:
.headerWrapper {
position: absolute;
height: 85px;
background: #19A347;
z-index: 9000;
width: 960px;
}
#header {
width: 100%;
margin: 0 auto;
position: relative;
}
You also should change these rules:
.cols-container {
margin: 0 auto;
max-width: 960px;
min-width: 900px;
overflow: hidden;
}
.content {
width: 96%;
max-width: 720px;
min-width: 600px;
margin: 0 auto;
padding: 10px;
padding-bottom: 245px; /* Height of the footer element */
}
to the min-width you want:
.cols-container {
margin: 0 auto;
max-width: 960px;
min-width: 400px;
overflow: hidden;
}
.content {
width: 96%;
max-width: 720px;
min-width: 400px;
margin: 0 auto;
padding: 10px;
padding-bottom: 245px; /* Height of the footer element */
}
JSFIDDLE