I am working on the list of artists page of my lyrics website (a side project of mine). Here is what I currently have:
Notice how some artist names are long and so wrap onto two lines, and pushing my artist name block (the black background) up.
CODE
Here is the HTML markup:
<div class="row artists">
<div class="col-md-2 col-6">
<div class="artist-card">
<div class="artist-image">
<img src="http://placehold.it/200x200" alt="Rihanna" />
</div>
<div class="artist-info">
<div class="artist-name">
<h2>Rihanna</h2>
</div>
</div>
</div>
</div><!-- .artist-card -->
<!-- more artist cards go here -->
</div><!-- .artists -->
And here is the Sass styles:
$artist-card-background-color: #bdbbb0;
.artist-card {
position: relative;
background-color: $artist-card-background-color;
border: none;
border-radius: 2px;
margin-bottom: 15px;
cursor: pointer;
.artist-image {
img {
width: 100%;
}
}
.artist-info {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: rgba(0, 0, 0, 0.8);
.artist-name {
h2 {
margin: 0;
color: #fff;
padding: 10px 15px;
}
}
}
}
I have also created a Codepen to allow you guys to experiment with the cards and how they currently behave across various viewports.
Question
What is the cleanest way I can make the titles legible (readable), but also have the same height no matter what the viewport size is?
Alternative 1
Truncate the text if it exceeds the width.
Add this css to the H2:
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Alternative 2
Use something like http://fittextjs.com/ or http://simplefocus.com/flowtype to change the font-size dynamically based on its length.
Alternative 3
Combine the 2 above, truncate the text only when the text gets to small to read.
Related
I would like to ask if this kind of column stacking is possible on Bootstrap without using Javascript or JQuery.
This One
instead of This.
I used
col-md-6
to style my columns at the moment, however I cannot figure out how to prioritize the stacking to fill vertical space first until it reaches the end (height) of the parent <div> followed by filling the neighboring horizontal space going down, and so on.
I could not find any topics about this anywhere in Google. So, I came here to see if it is actually possible or it isn't.
Thanks.
Yes, it's possible. But you need two wrappers. One for 1 ~ 4 second for 5 and 6.
jQuery is only used to demonstrate view-port change
$(document).ready(function() {
$('button').click(function() {
$('.wrapper').toggleClass('v2')
});
});
div div div {
border: 1px solid #ddd;
text-align: center;
font-weight: bold;
float: left;
padding: 20px 20px;
}
div {
box-sizing: border-box;
}
.wrapper {
width: 100px;
height: 250px;
}
.w-1,
.w-2 {
width: 50%;
float: left;
}
.v2 .w-1,
.v2 .w-2 {
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<div class="w-1">
<div class="col-xs-6">1</div>
<div class="col-xs-6">2</div>
<div class="col-xs-6">3</div>
<div class="col-xs-6">4</div>
</div>
<div class="w-2">
<div class="col-xs-6">5</div>
<div class="col-xs-6">6</div>
</div>
</div>
<hr/>Only for demo:
<button>Toggle layout</button>
first time user of Foundation framework, I've developed all my previous websites with Bootstrap but now I'm forced to built one website with foundation. I noticed they are pretty similar but somehow different frameworks.
I've encountered a problem and hope you can help me with this.
I need to add a banner to a website which is full width and text which is within the grid and has a bg which is also full width, see what I mean here:
Here is my html:
<div class="fullWidth">
<div class="banner">
<div class="logo">
<img src="images/logo.svg"/>
</div>
<div class="row">
<div class="bg-tagline">
<h1 class="tagline">some text here</h1>
</div>
</div>
</div>
</div>
and the css:
.fullWidth {
width: 100%;
margin-left: auto;
margin-right: auto;
max-width: initial;
}
.banner {
background: white url("images/baner.jpg") no-repeat center;
height: 590px;
background-size: cover;
position: relative;
}
.logo {
position: relative;
padding: 1%;
height: 5em;
width: 5em;
}
.bg-tagline {
color: #fff !important;
background-color: white;
width: 100%;
margin: 0px auto;
}
.bg-tagline h1 {
color: #fff !important;
font-size: 1.2em;
text-align: center;
}
As far as I know, there's no a "full width" class in foundation framework; Normally, in those layout types, I'd just use the elements off the framework, for instance:
<header id="banner">
<div class="slogan">Your text banner here</div>
</div>
And of course some CSS like you have already. If you need something elaborated (like a layout using foundation's classes), I'd put inside div.slogan a div.row, and start building layout from there, of course that row would be restricted to the max width from the framework.
BTW, if you need to have the entire framework having a wider width for the rows, you can change the framework settings and re-compile.
Personally, I like to make utility class for rows:
.row.fullwidth {
max-width:100em; // set your override width here
margin: 0 auto;
}
That way whenever I need a full width section I just do:
<div class="row fullwidth">
<!--- content --->
</div>
How can I make all divs with different heights bunch together vertically whilst having them in columns? Each of the divs in my website float left with a 5px margin on the right and bottom so that two columns are made but with them all different heights the bottom margins are different depending on the tallest div in that row, how can I make them bunch up like on this Google Now page?
I have made a basic version of my website in JSFiddle.
<div id="container">
<div id="tile" class="tile-1"></div>
<div id="tile" class="tile-2"></div>
<div id="tile" class="tile-3"></div>
<div id="tile" class="tile-4"></div>
<div id="tile" class="tile-5"></div>
<div id="tile" class="tile-6"></div>
</div>
#container {
width: 210px;
height: auto;
overflow: auto;
}
#tile {
width: 100px;
margin: 0 5px 5px 0;
background-color: #333;
float: left;
}
.tile-1 { height: 100px; }
.tile-2 { height: 130px; }
.tile-3 { height: 80px; }
.tile-4 { height: 100px; }
.tile-5 { height: 110px; }
.tile-6 { height: 150px; }
I have done it previously by making each column have their own container but when the browser window shrinks I need the 'tiles' to merge but keep their order, going from reading the page like a book to reading it like a list for smaller screens.
Thanks in advance.
Matt
Use one of these
Isotope (probably most popular)
Masonry
jQuery.waterfall
Wookmark jQuery plugin
See examples and you will achieve this easily.
Quite a weird problem here. I don't know if it's related, but I am using Shopify - which has been the cause of weird problems in the past.
Okay, so here is the page on which I am coding (not the final place it will be for the record) - http://stonedclassy.com/pages/page2
As you can see, there are 6 divs on the page. I am using Bootstrap, and they are all span6 (meaning they take up half the width of the page on a an averaged sized desktop). The first "row" of divs is perfectly fine, but starting on the second row, there is an indent that I cannot get rid of. It's causing all of the subsequent divs after the first row to be forced onto their own row since they can't fit two to one row.
If I change all the divs size to span5, they are able to fit two to a row, but there is still an indent starting on the second row.
Here is the html:
Please note that to save space, I am including just ONE of the SIX divs I am referring to. The full code is literally just this code repeated six times
<div class="span6 majorimgtesting">
<a href="">
<div class="ghostrowforcategories span6"> <button class="ghostbuttonforcategories">TESTING</button> </div>
<img src="//cdn.shopify.com/s/files/1/0654/2811/products/clear-hammer-bubbler-water-pipe-stonedclassy_large.jpg?v=1422320684" class="imgtesting" />
<img src="//cdn.shopify.com/s/files/1/0654/2811/products/Micro-Mini-Water-Pipe-Stonedclassy_5571a18d-b3ed-457d-b180-f36cf3acb2b3_large.jpg?v=1423018550" class="imgtesting" />
</a>
Here is the CSS:
.majorimgtesting
{
max-height:250px;
overflow:hidden;
border-left: 1px solid black;
border-right: 1px solid black;
margin-bottom: 50px;
opacity: .9;
transition: .5s ease;
float: left;
}
.majorimgtesting:hover
{
transition: .5s ease;
opacity: 1;
}
.imgtesting
{
max-width: 50%;
display: block;
float: left;
z-index:-1;
}
.ghostrowforcategories
{
width: 100%;
position: absolute;
display: inline-block;
padding-bottom: 10px;
text-align: center;
}
.ghostbuttonforcategories
{
display: inline-block;
border-radius: 2px;
border: none;
height: 45px;
padding-left: 15px;
padding-right: 15px;
width: 100%;
background-color: #666105;
color: white;
border: 1px solid #666105;
float: middle;
z-index: 5;
opacity: .8;
}
.ghostbuttonforcategories:hover
{
background-color: #666105;
color: white;
z-index: 5;
}
All of your divs are contained in a single <div class='row-fluid'> parent. The first child of every row-fluid gets a margin-left: 0 which is pulling the first element out of line. Each subsequent element gets the regular margin-left value so they all line up appropriately.
bootstrap removes the margin of the first span in a sections of spans so if you place the items like this(as it's on the page)
<div class="row-fluid">
<div class="span-12">
<div class="sapn-6">...
</div>
<div class="span-12">...</div>
<div class="span-12">...</div>
</div>
it would only remove the margin of the first span-12 and the first span-6 and due that the next span-6 within a span-12 that's not the firstone it'll have that margin, so there's why you have that margin problem. Now, to fix it you could remove the class span-12 form the "frame like" divs and your problem will be solved, and the responsive items should still work. Example:
<div class="row-fluid">
<div>
<div class="sapn-6">...
</div>
<div>...</div>
<div>...</div>
</div>
For a project of mine, I'm using Skeleton Boilerplate for the first time. And I'm looking for the best practice of centring a div in Skeleton without bashing into the rules of Skeleton.
At the moment, I've the following structure for a login page.
HTML:
<div class="container">
<div class="sixteen columns vertical-offset-by-one">
<div id="loginBox">
<img src="images/yeditepeLogo.png" alt="Yeditepe Logo" class="yeditepeLogo" />
<form action="" id="loginForm">
<input type="text" name="username" required placeholder="username" class="loginTextField">
<input type="password" name="password" required placeholder="password" class="loginTextField">
<input type="submit" value="Log In" class="loginButton" />
</form>
</div><!-- loginBox -->
</div><!-- sixteen columns -->
<div class="sixteen columns">
<p align="center">Click here to register</p>
</div>
</div><!-- container -->
CSS:
#loginBox, #registrationBox {
width: 470px;
height: 450px;
background-color: white;
left: 245px; */
top: 20px; */
position: relative;
margin: 0px auto; }
#registrationBox {
height: 500px; }
.yeditepeLogo {
position: relative;
left: 40px;
top: 33px; }
#loginForm, #registrationForm {
position: relative;
top: 45px; }
.loginTextField, .registrationTextField {
position: relative;
height: 40px;
width: 388px;
left: 40px;
border-color: #dedede;
border-style: solid;
border-width: 1px;
margin-bottom: 10px;
text-align: left;
font-size: 18px;
text-indent: 10px;
-webkit-appearance: none; }
.loginTextField:focus, .registrationTextField:focus {
outline-color: #ff9800;
outline-style: solid;
outline-width: 1px;
border-color: white; }
.loginTextField:nth-child(2), .registrationTextField:nth-child(3) {
margin-bottom: 40px; }
.loginButton, .registrationButton {
background-color: #77a942;
position: relative;
border: none;
width: 390px;
height: 60px;
left: 40px;
color: white;
font-size: 24px;
text-align: center;
opacity: 0.8; }
.loginButton:hover, .registrationButton:hover {
opacity: 1; }
As you can see, that #loginBox has a fixed width/height and it should always be on the centre of the page. margin: 0px auto code gives it the horizontal centring. But is it the best practice in Skeleton? Does Skeleton provide a better way?
Also how can I provide it's vertical centring?
There's actually a built in way of centering divs in Skeleton.
<div class="sixteen columns">
<div class="four columns offset-by-six">
<p>Lorem ipsum dolor sit amet.</p>
</div>
</div>
The offset-by-six in this case can be altered from one to fifteen, and offsets the column at hand by as many columns as entered. As a neat feature, the offsetting is not affecting alignment when smaller screens are used.
To clarify: This doesn't center the actual content in the div, but centers the div itself.
I know it has been a while since this question was asked, but maybe somebody else can use the answer.
I was able to accomplish centering with Skeleton by filling one-third column class with a space, then the next one-third column class with content, then another one-third column class with a space again.
<div class="one-third column"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column"> </div>
You can set the container to
.container {
position: absolute;
top: 50%;
left: 50%;
margin-left: -43 //replace with half of the width of the container
margin-top: -52 //replace with half of the height of the container
}
set the parent container or element to position: relative;
Here's a good article about How to Center Anything With CSS
Asus3000's answer is good as that is what I do and it works well. I would only add that on mobile, it adds quite a bit of unwanted vertical space. To avoid mobile vertical space, I use a class .filler and hide it on mobile.
HTML
<div class="one-third column filler"> </div>
<div class="one-third column"><p>Center of the screen.</p></div>
<div class="one-third column filler"> </div>
CSS
/* or whatever mobile viewport */
#media only screen and (max-width: 960px) {
.filler { display: none}
}
A way I believe works pretty good is:
<div class="container">
<div class="row">
<div class="two-half column">
centered div content
</div>
</div>
</div>
This makes the div centered and responsive. You can change margin-top to make it all the way in the middle, however changing width will (of course) not make it centered anymore.
Correct me if I'm wrong but this works for me! :)