I am just starting to learn Foundation (from previous messy css experience). I am trying to do a full screen block grid of 4 col images per row. I have this to make the row full width:
.row
max-width: 100%
Here is the code:
<nav class='top-bar'>
<ul class='title-area'>
<li class='name'>
<h1>
<a href='#'>
My Website
</a>
</h1>
</li>
<li class='toggle-topbar menu-icon'>
<a href='#'>
<span>menu</span>
</a>
</li>
</ul>
<section class='top-bar-section'></section>
</nav>
<div class='row'>
<ul class='small-block-grid-2 large-block-grid-4'>
<li>
<img src='http://placehold.it/500x500&text=Thumbnail' />
</li>
<li>
<img src='http://placehold.it/500x500&text=Thumbnail' />
</li>
<li>
<img src='http://placehold.it/500x500&text=Thumbnail' />
</li>
<li>
<img src='http://placehold.it/500x500&text=Thumbnail' />
</li>
</ul>
</div>
I am getting annoying horizontal scroll bar. See below screenshot
I know it is the margin below:
#media only screen
[class*="block-grid-"]
margin: 0 -0.625em;
But do I suppose to override it? It doesn't feel right (seem like a hack). How do I use Foundation properly to display block grid with full screen? It's a simple layout requirement.
If you look at the docs explaining the Foundation grid they already use the box-sizing: border-box star hack
Since the .row containing your block-gridhas a set max-width of 100% it's overflowing the screen width. Typically, elements in the grid would be nested in .rows with defined max-widths and also contained within defined column sizes.
You can simply just do the hacky thing as you deeply fear and adjust the margin:
#media only screen
[class*="block-grid-"]
margin: 0 2em;
Or you can just contain your .block-grid with a container <div class="large-12 columns">.
Six of one half-a-dozen of the other I'd say. If you're afraid of screwing up the grid layout, you can use a conditional class on the body tag so that your customized block-grid only effects the pages that you want.
take a look of this demo by Paul Irish
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; }
this might be helpful else can you provide a fiddle?
For those who do not want to wrap their block grid within the standard row/column grid, simply hide the overflow on your block grid's parent element. Here's a superfluous code demonstration.
(html)
<div class="block-grid-parent">
<ul class="block-grid">
...
(css)
.block-grid-parent {
overflow: hidden;
}
Related
I would like to build a sample "webshop" project where I would like to list books as on the picture. How can I align text and pictures given this HTML code with CSS similarly as:
HTML code of one book (note this code is replicated the same way with different texts:
<li class="book">
<ul>
<li class="bookcover">
<a href="https://rads.stackoverflow.com/amzn/click/com/1118008189" rel="nofollow noreferrer">
<img src="https://books.google.com/books/content?id=aGjaBTbT0o0C&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
alt="Book Cover for HTML and CSS: Design and Build Websites"/>
</a>
</li>
<li class="author">Jon Duckett</li>
<li class="title">
HTML and CSS: Design and Build Websites
</li>
<li class="publisher">John Wiley & Sons</li>
<li class="date">November 2011</li>
<li class="isbn">ISBN: 1118008189</li>
</ul>
</li>
Is there a universal way with CSS to format this?
There are many ways to achieve this. I do want to mention before proceeding that #Tom Faltesek raises a good point. If you have any control over the HTML code, it would be best to approach this with more semantically accurate markup. If, for example, you had the freedom to arrange it this way...
<article class="book">
<div class="book__info">(...)</div>
<div class="book__thumbnail">(...)</div>
</article>
...then your CSS could be done in this way:
.book {
font-size: 0;
}
.book__info,
.book__thumbnail {
display: inline-block;
font-size: 1rem;
}
.book__info {
width: 75%;
}
.book__thumbnail {
width: 25%;
}
Explanation: Inline-block elements naturally follow each other because they are like block elements that display inline with the text. That in mind, setting font-size: 0; on the parent avoids the natural text space that would normally appear between the elements, so that 25% + 75% only spans 100% of the width without extra text spaces between. Remember to reset your font-size on the inner elements with this trick, though.
However, in the way that you are asking this question, I assume you may not have control over this HTML structure. #Gildas.Tambo 's answer will work, visually, but there are challenges that come with floats. The main issue is that float removes an element from the document's flow, so it does not contribute to the height of it's parent. That means the parent has the potential to be 0 pixels high even if its contents are 500+ pixels high. This can cause all sorts of weird buggy layout issues when you get into more involved css.
This seems like a good use case for CSS Grid. At this point, pretty much all the major browsers support it, and it's a hell of a good weapon to have in your arsenal.
Have a look at the code below. Use grid-template-areas to quite literally mock up your layout in the form of words to correspond with elements (in this case, each of your <li>s) and you can span across multiple rows with one element by assigning it to the entire grid area. In the example below, I provided 5 rows and marked the left column as "info" and the right column as "thumbnail", and then to take up all the available space for thumbnail, I just assign .bookcover to it with grid-area: thumbnail;. Don't worry too much about the fancy stuff I did with grid-template-rows, but know that you can use that property to distribute the height of each row.
ul, li {
list-style: none;
padding: 0;
margin: 0;
}
.book ul {
display: grid;
grid-template-areas:
"info thumbnail"
"info thumbnail"
"info thumbnail"
"info thumbnail"
"info thumbnail";
grid-template-rows: repeat(4, auto) 1fr;
}
.bookcover {
grid-area: thumbnail;
}
<li class="book">
<ul>
<li class="bookcover">
<a href="https://rads.stackoverflow.com/amzn/click/com/1118008189" rel="nofollow noreferrer">
<img src="https://books.google.com/books/content?id=aGjaBTbT0o0C&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
alt="Book Cover for HTML and CSS: Design and Build Websites"/>
</a>
</li>
<li class="author">Jon Duckett</li>
<li class="title">
HTML and CSS: Design and Build Websites
</li>
<li class="publisher">John Wiley & Sons</li>
<li class="date">November 2011</li>
<li class="isbn">ISBN: 1118008189</li>
</ul>
</li>
You can use float - CSS:left and display : block
.book li{
display: block
}
.bookcover{float:right}
<li class="book">
<ul>
<li class="bookcover">
<a href="https://rads.stackoverflow.com/amzn/click/com/1118008189" rel="nofollow noreferrer">
<img src="https://books.google.com/books/content?id=aGjaBTbT0o0C&printsec=frontcover&img=1&zoom=1&edge=curl&source=gbs_api"
alt="Book Cover for HTML and CSS: Design and Build Websites"/>
</a>
</li>
<li class="author">Jon Duckett</li>
<li class="title">
HTML and CSS: Design and Build Websites
</li>
<li class="publisher">John Wiley & Sons</li>
<li class="date">November 2011</li>
<li class="isbn">ISBN: 1118008189</li>
</ul>
</li>
Apologies, I have attempted to create a JS Fiddle replication, but the issue does not seem to occur in the JS Fiddle so I can only think it is a problem with the more general CSS on the page.
The JS Fiddle created does not show the error, but here it is anyway: https://jsfiddle.net/j2qxh9zg/
I am attempting to line up two elements side-by-side. They use display:inline-block; and have a width of 33.3% and 66.6%. The body has font-size:0 set in order to remove any whitespace issues so I do not believe this to be an issue with the whitespace between containers.
<div class="grid one-third">
<div class="logo">
<img src="assets/logo.png" alt="Something"/>
</div>
</div>
<div class="grid two-thirds menu">
<ul>
<li><a name="#home">Home</a></li>
<li><a name="#expertise">Our Expertise</a></li>
<li><a name="#portfolio">Portfolio</a></li>
<li><a name="#tech">New Technology</a></li>
<li><a name="#contact">Get In Touch</a></li>
<li>01483 746650</li>
</ul>
</div>
I cannot seem to get the .one-third and the .two-thirds divs to sit side by side, despite them both being display:inline-block;
.grid.one-third{width:33.3%}
.grid.two-thirds{width:66.6%}
.grid{display:inline-block;box-sizing:border-box;}
Live link, you can see the menu is at the bottom of the page (grey box) http://digitalshowcase.somethingbigdev.co.uk/
The nav container is 70px high. It should be 50px high. Both the inside elements are 50px high, yet the container expands. Why?
I think adding vertical-align: middle; to .grid will do it.
I have modified my bootstrap skeleton top nav to this: http://jsfiddle.net/55dTU/
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="/">SketchFemme</a>
<div class="brand slogan">
<span>pencial mileage</span><br>
<span>one curve at a time</span>
</div>
<div class="container nav-collapse">
<ul class="nav">
<li>Artists</li>
<li>Onion Skin</li>
<li>News</li>
<li>About</li>
</ul>
<ul class="nav" id="account_corner">
homonolocus
<span class="divider">|</span>
Settings
<span class="divider">|</span>
Sign out
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
Bootstrap .container sets the width to 1170px. Can someone please tell me why the .container.nav-collapse div can be nested inside .navbar-inner .container and somehow overlap the .brand and slogan? I would think since every instance of .container is the width of 1170px, that the .nav links would be forced into the next line instead of being on the same line as the brand and slogan.
My question isn't so much that I need something to be fixed. Rather I'm asking for an explanation of why this works. Why can one .container contain another .container, of the same width right on top of it. I was looking for a position:absolute which would allow that, but I don't find any. How does the ul.nav know where to indent?... there is no left padding and no left margin, and the containing element spans the entire width of the navbar. I want to know how this is being achieved.
I updated your fiddle ; I added
.navbar-static-top .container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
width: 940px;
height: 1px; /* These */
clear:left;
}
It makes the container act like a real block: its display is set to block by default, but as its height was 0px, it didn't act like a block but rather as an inline-block.
The clear:left; also cancel any floating conflict (I put both in the fiddle without thinking, but hey, it's 6:30 am here in France).
Since you are using a responsive navbar, is there a reason why you aren't also using a responsive CSS file so the navbar collapses? I replaced your CSS file with
#import url('http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css');
In the account_corner div you have ul but no list items. I replaced the ul with a plain div. Also, if you are following the example from http://twitter.github.io/bootstrap/components.html#navbar the div with your main links should have these classes
<div class="container nav-collapse">
Which partly answers your question.
This is the result http://jsfiddle.net/panchroma/ruAmz/ ?
Hope his helps get you closer to what you want!
I feel like a moron having to ask this, but I have always evaded CSS at all costs, and as I now find myself needing it again, I have been scavenging Google for an example with no luck.
Basically I have icons specific to each category, and would like to create a horizontal nav bar in CSS/HTML using these, but also displaying a text link under them as well. I have found snippets for doing one or the other, but every time I try and combine the two together, the entire page seems to breakdown.
Can anyone provide an example of how this can be done? If it helps, it would basically look like...
[-IMAGE-] [-IMAGE-] [-IMAGE-]
[-TEXT-] [-TEXT-] [-TEXT-]
The effect can be easily get through background-position in CSS with proper padding-top applied to the li elements:
background-position: top;
padding-top: 50px; /* Height of image */
Here is an example fiddle.
Update:
Here is the more descriptive fiddle with different images on different li elements.
http://jsfiddle.net/LajUZ/2/
HTML:
<ul class="nav">
<li class="navitem">
<div class="icon">
[icon]
</div>
<div class="text">
[text]
</div>
</li>
<li class="navitem">
<div class="icon">
[icon]
</div>
<div class="text">
[text]
</div>
</li>
</ul>
CSS:
.navitem
{
float: left;
}
I am trying the Blueprint CSS framework, and am having a hard time figuring out how to do the overall layout.
It seems Blueprint (as far as I have understood it so far) makes you use a set page width at 950px. I guess you could change that with some modification, but in any case there has to be some width, so that's fine. The problem is, even if I want the main content of the page to be 950px wide, I want 100% wide headers and footers.
So I have placed a header and a footer outside the main "container" div that's 950px wide. I set the header div to 100%. And then I have a "headerContent" div inside it (containing menu, logo, etc), which has a 950px width (span-24 in Blueprint terms). But I want the headerContent div to be centered within the header div.
I have always used the "margin: 0 auto" trick to do this, but for some reason it doesn't work at all now.
Here's the html:
<div id="header" class="blueheader">
<div id="headerContent" class="span-24">
<div id="logo" class="span-6">
<a href="/">
<img src="/images/expertinfo.png" width="230" height="62" />
</a>
</div>
<div id="menucontainer" class="span-14"><ul id="menu"><li>
<a href='/Services/Index'>TJÄNSTER</a></li>
<li>
<a href='/About/References'>KUNDER</a></li>
<li>
<a href='/About'>OM OSS</a></li>
<li>
<a href='/About/Contact'>KONTAKT</a></li>
</ul></div>
<div id="logindisplay" class="span-2">
Logga in
</div>
</div>
</div>
And here's the css for header and headercontent:
#headerContent
{
overflow: auto;
zoom: 1;
margin: 0 auto;
}
#header
{
width: 100%;
position: relative;
margin-bottom: 0px;
color: #000;
margin-bottom: 0px;
overflow: auto;
zoom: 1;
}
The overflow and zoom part is just another trick I read about to avoid having to use empty divs to clear containing divs, and I tried without them with no luck, so they have nothing to do with the problem.
Any ideas what I'm doing wrong?
You need to set a width the the #headerContent because without it defaults to width:100% if you place a 950px width to the div, you should be fine.
Found the answer: you shouldn't use span-24 on the headerContent apparently in the Blueprint framework, but rather the container class. Here's what worked:
<div id="header" class="blueheader">
<div id="headerContent" class="container">
<div id="logo" class="span-6">
<a href="#Url.Action("Index", "Home")">
<img src="/images/expertinfo.png" width="230" height="62" />
</a>
</div>
<div id="menucontainer" class="span-14">#Html.Raw(Html.Menu())</div>
<div id="logindisplay" class="span-2">
#Html.Partial("_LogOnPartial")
</div>
</div>
</div>
I cannot say I understand exactly why it didn't work before, and that worries me, because I am trying this framework to simplify layout, but this made it harder to understand. As far as I could see it should have worked with the first code too...