On Rails 4. I am building a site where you can search graphics/products according to their assigned color scheme. Relevant models:
class Product < ActiveRecord::Base
belongs_to :color_scheme
end
class ColorScheme < ActiveRecord::Base
has_many :products
end
Each color scheme has five color hexadecimal values as columns. Using Bootstrap, here's what the code looks like as a dropdown, without being a collection_select:
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1"
data-toggle="dropdown" aria-expanded="true" style="width:100%; margin-bottom:20px;">
<%= t('template.scheme')%> <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<% #color_schemes.where(enabled: true).each do |scheme| %>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#">
<div style="width:30px; height: 20px; display: inline-block;
background-color:#<%=scheme.color1%>;"></div>
<div style="width:30px; height: 20px; display: inline-block;
background-color:#<%=scheme.color2%>;"></div>
<div style="width:30px; height: 20px; display: inline-block;
background-color:#<%=scheme.color3%>;"></div>
<div style="width:30px; height: 20px; display: inline-block;
background-color:#<%=scheme.color4%>;"></div>
<div style="width:30px; height: 20px; display: inline-block;
background-color:#<%=scheme.color5%>;"></div>
</li>
<% end %>
</ul>
</div>
And this is the visual result:
Since I'm using Ransack and this is a dropdown for search, I converted this into a collection_select but can't figure out how to get that same visual effect.
<%= f.collection_select :color_scheme_id_eq, ColorScheme.order('created_at DESC').all, :id,
:name, {include_blank: t('template.scheme')}, {class: 'form-control select-scheme',
style: 'width:100%; margin-bottom:20px;'} %>
So instead of just displaying the color scheme's text name, I'd like to show the colors like above. I understand this is probably outside the scope of what a collection select should be, but I feel the colors make more sense, visually, than the name. Is this possible, either through collection_select or some other tag that would work with Ransack? Thanks! Edit: I should also add that I'll probably still have the color scheme's name to the right of the colors, for people who are color-blind, etc.
I have another suggestion:
create a div which has color scheme above select field
then use to javascript click event on each color scheme to set value in select field
Here is my code sample to solve this issue:
.col-sm-3
#color-label-project{style: 'text-align: center;'}
- t('labels.project.label_color_hashes').map do |k, v|
%span{style: "width:30px; height: 20px; display: inline-block; background-color: #{v};", id: "#{k}", 'data-value': "#{k}"}
= f.input :label_color, collection: Project::LABEL_COLOR_NAME, prompt: true, disabled: false, label: false
:javascript
$("#color-label-project span").bind('click', function(){
$('select[name="project[label_color]"]').val($(this).data("value"));
})
here is my way:
Related
I am trying to use flex box with bootstrap columns so that all the columns are always horizontally centered. The markup mentioned below works fine for firefox, chrome and Android but fails on iOS and safari. I haven't tested IE yet.
HTML:
<!-- The fourth column falls down -->
<div class='row row-1 text-center'>
<div class="col-xs-3 red">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
</div>
<!-- Works Fine and centers the columns -->
<div class='row text-center'>
<div class="col-xs-3 red">Hi</div>
<div class="col-xs-3 blue">Hi</div>
<div class="col-xs-3 blue">Hi</div>
</div>
CSS:
.row {
display: flex;
display: -webkit-flex;
flex-wrap:wrap;
-webkit-flex-wrap: wrap;
-webkit-justify-content: center;
justify-content: center;
}
div[class^=col-] {
float: none;
display: inline-block;
vertical-align: top;
}
On Chrome, Firefox and Android
On Safari and iOS
JSFIDDLE
Is there anything that I should be adding to the columns so that they appear in one line.
It's pseudo-element in the .row causing the problem.
This happens because Safari browser treats :before and :after
pseudo-elements as if they were real elements.
Try
.row:before, .row:after{
display: none;
}
or better create a class say, .flex-row and do this
<div class="row flex-row">
{{contents here..}}
</div>
.flex-row{
display: flex;
display: -webkit-flex;
flex-wrap:wrap;
-webkit-flex-wrap: wrap;
-webkit-justify-content: center;
justify-content: center;
}
.flex-row:before, .flex-row:after{
display: none;
}
FIDDLE
If anyone is still lost for a solution, I had an issue where my columns were TALL in Safari:
To solve this, I simply added this CSS selector (I know !important isn't best practice, but I tried several solutions and eventually landed on this):
.d-flex {
display: block !important;
}
Now, my columns looks like this, which is how it originally looked in Chrome, Firefox, etc.:
Please help me with this simple question. I did not found any answer.
I have this text_field_tag:
<div class="col-xs-4"><i class="fa fa-map-marker fa-2x"></i><%= text_field_tag 'ip', "", maxlength: 15, class: "form-control" %></div>
I want to place font awesome inside my text_field_tag, but..
What happen is, the icon is display outside from the text_field_tag
Actually I know why this happen, because the font awesome is outside form the text_field_tag. I try to place font awesome inside the text_field_tag but get an error.
What is the right way to place the font awesome inside the text_field_tag?
Hope anyone can answer this simple question.
Thank you !
Try this
<div class="input-group">
<%= text_field_tag 'ip', "", maxlength: 15, class: "form-control" %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-map-marker"></span>
</span>
</div>
The problem is that form-control width is set as 100%. You will have to change that manually and set its display to inline.
<div class="col-xs-4 someclass"><i class="fa fa-map-marker fa-2x"></i><%= text_field_tag 'ip', "", maxlength: 15, class: "form-control" %></div>
CSS
.someclass i {
display: inline;
}
.someclass .form-control {
display: inline;
width: 95%;
}
These CSS should be given in application.css where you import bootstrap. Otherwise you will have top give important! to each attribute in the form-control css.
Add an Icon to the Right Side of a Bootstrap Search Bar
I had a similar problem where I wanted to add a search icon into the right side of a Bootstrap 4.1 search bar.
I had this:
But I wanted this:
I was able to resolve it by adding positioning to the icon via a new class I'm calling search_icon.
Add a search_icon class to your <i> element:
<div class="col-xs-4">
<i class="fa fa-map-marker fa-2x search_icon"></i>
<%= text_field_tag 'ip', "", maxlength: 15, class: "form-control" %>
</div>
Style the new class:
.search_icon{
position: relative;
float: right;
top: 25px;
right: 14px;
color: #CCC;
}
Credit goes to Rafi Benkual whose CodePen tipped me off for the icon styles.
I am using Materializecss for my website and I'd like to display tooltips on the smaller action buttons whenever the user presses the big action button. Materializecss shows tooltips only on hover by default.
Is there a way to change this?
Thank you
<li> <!-- Small button -->
<a class="btn-floating green tooltipped" data-position="left" data-delay="50" data-tooltip="Add friends">
<i class="material-icons">add</i>
</a>
</li>
Check out this github issue
Github user philipraets created a nice codepen to demonstrate his soluton.
Edit (For the Lazy):
philipraets created a simple css style:
.mobile-fab-tip {
position: fixed;
right: 85px;
padding:0px 0.5rem;
text-align: right;
background-color: #323232;
border-radius: 2px;
color: #FFF;
width:auto;
}
then wrapped the tooltip within another link element using that style:
<div class="fixed-action-btn click-to-toggle" style="bottom:24px; right:24px;">
<a class="btn-floating btn-large red"><i class="large material-icons">settings</i></a>
<ul>
<li>
<i class="material-icons">create</i>
Edit <!--tooltip-->
</li>
<li>
<i class="material-icons">event</i>
Save to calendar <!--tooltip-->
</li>
<li>
<i class="material-icons">supervisor_account</i>
Switch responsible <!--tooltip-->
</li>
</ul>
</div>
So this seems like a dumb problem to have. I may be going about it wrong so if anyone could suggest another way of doing this i would love to try it out.
I have a FIXED Navigation bar built with Zurb Foundation 4
<div class="fixed">
<nav class= "top-bar">
<ul class="title-area">
<li>
<h2><%= link_to image_tag("officialLogo-100x197.png", :size => "100x197", :class => "logo" ) + "AppDomum", root_path, :class => "textlogo" %></h2>
</li>
<li class="toggle-topbar menu-icon"><span>Menu</span></li>
</ul>
<section class="top-bar-section">
<ul class="right">
#links .....
</ul>
The image that is displayed for the title is larger than the navigation bar. I actually like it hanging down from the nav bar and i have a media query setup to remove it on smaller screens so it is not hanging over content.
Problem: The <div class= "fixed"> wraps the navigation bar and the image all the way across the page. Because the image hangs below the nav bar anything behind it is not clickable. the entire top part of the page is unclickable. For a form i am unable to select a text box to edit. Because the navbar is fixed it affects the entire page depending on how far you have scrolled. Is there a way to have them fixed but without having the fixed tag grab all the empty space? Is there another way to do this?
Try adding position: relative; to your image.
I did Solve this after much research.
here is the code to solve the issue or at least what i hacked together to get what i want.
This is the navigation bar.
<div class="fixed">
<nav class= "top-bar">
<ul class="title-area">
<li>
<h2><%= link_to "AppDomum", root_path, :class => "textlogo" %></h2>
</li>
<li class="toggle-topbar menu-icon"><span>Menu</span></li>
</ul>
<section class="top-bar-section">
<ul class="right">
#links .....
</ul>
</section
</nav>
</div>
<div class= "fixed-icon">
<%=link_to image_tag("officialLogo-100x197.png", :size => "100x197", :class => "logo" ), root_path %>
</div>
I separated the icon and the Text but kept both of them as links to the home page. Giving the illusion that they are both part of the title. There is a media query that hides the image and removes the margin on the title.
And Here is the CSS. I basically searched around the html and css files of the site until i found the "fixed" class and stole the css modification and then changed the width to be small so it does not mask everything else.
#media only screen and (min-width: 768px) {
.title-area {
margin-left: 6em;
}
}
.fixed-icon {
#extend .hide-for-small;
width: 10%;
left: 0;
position: fixed;
top: 0;
z-index: 99;
}
.title-area {
padding: 5px 5px;
font-weight: bold;
letter-spacing: -1px;
}
Okay so I am working on making a site for my previous boss who runs an animal control business. My index.html.erb consists of code like this:
<div id="bats"><img alt="Big brown bat" src="/images/bigbrown.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to #animals[0].name, animal_path(#animals[0]) %></p></div>
<div id="squirrel"><img alt="Grey Squirrel" src="/images/grey_squirrel.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to #animals[1].name, animal_path(#animals[1]) %></p></div>
<div id="flying"><img alt="Flying Squirrel" src="/images/flying-squirrel.png" style="position: relative; border: 0.25em outset;"/>
<p class="text_center"><%= link_to #animals[2].name, animal_path(#animals[2]) %></p></div>
<div id ="groundhog"><img alt="Groundhog" src="/images/groundhog.png" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to #animals[3].name, animal_path(#animals[3]) %></p></div>
The pages are mostly static with a lot of text, so I guess my two questions are, should I even have the animals in a database (which just consists of their name)?
And if I do keep them in a database, how should I format my show.html.erb which is going to go into greater detail about the animal selected from my index.html.erb page? Use if, else if, etc... or make a page specific to each animal and just redirect there when the animal is selected?
Thanks in advance!
If I were to redo your example page, I'd add a short_description, long_description, and image_url for each animal in the database and do something like this:
<% #animals.each do |animal| %>
<div id="animal_<%= animal.id %>"><img alt="<%= animal.short_description %>" src="<%= animal.image_url %>" style="position: relative; border: 0.25em outset;" />
<p class="text_center"><%= link_to animal.name, animal_path(animal) %></p></div>
<% end %>
to generate it.
The long_description would be to give more detail. If there is enough information to fill a page about each animal, I would use a separate show page.