increase a value in a css class in twig - symfony

I have a css class to which the layout in html5 and css3 you have enclosed a :hover background-color, this color is stored in the database and pick it up at the controller, now do not know how to make this :hover background-color on-screen display. What I thought is to include html code in the middle of a label with that style and tell the class that suffers the html tag :hover to increase one, in this way would go picking the value increases
This is kind of my idea in code:
<ul class="sub">
{% for key, c in categorias %}
<li class="hover">
<a href="elemento.html">{{ c.nombre }}
<div class="icon" style="background-color: #{{c.color}}">
<img src="{{ asset('images/iconoportada/' ~ c.iconoNombre)}}" alt="elemento" />
</div>
</a>
</li>
{% endfor %}
each list item has a :hover background different, like the current background catch it from the database, the problem is that I could not capture the: hover css here so I thought Twig

I would use something like this:
{% for key, c in categorias %}
<li class="hover">
<a href="elemento.html">{{ c.nombre }}
<div class="icon" rel="#{{c.color}}">
<img src="{{ asset('images/iconoportada/' ~ c.iconoNombre)}}" alt="elemento" />
</div>
</a>
</li>
{% endfor %}
and Jquery
<script>
$(document).ready(function(){
var oldbg = "";
$(".icon").hover(function(){
oldbg = $(this).css("background-colod");
$(this).css("background-colod", $(this).attr("rel"));
}, function(){ $(this).css("background-colod", oldbg); } );
}
</script>
not tested... just from the top of my head.

Related

truncate in twig on html content

I would like to truncate a long string, who content html tag.
From my controller php.
content="<div>
<h1>my title</h1>
<p>para 1 ...</p>
</div>";
I would like to truncate this, so i did this in twig :
{{ content|raw|truncate(15) }}
But the html are broken, see bellow :
<div>
<h1>my ti...
I want to keep the end of tag, like this :
<div>
<h1>my titl...</h1>
</div>
Anyone have an idea ?
You can use the Twig Truncation Extension. As you can read in the doc:
{% set html %}
<h1>Test heading!</h1>
<ul>
<li>Hello world</li>
<li>Foo bar</li>
<li>Lorem Ipsum</li>
</ul>
{% endset html %}
{{ html|truncate_letters(20) }}
will output:
<h1>Test heading!</h1>
<ul>
<li>Hello wo</li>
</ul>
Hope this help
You can solve this with the text-truncate class of bootstrap.
<h1 class="text-truncate">my title</h1>
If you don't want to use bootstrap, you can do it directly in css with the property text-overflow:ellipsis as it is the case in bootstrap.
Here is an example in css.
I hope it will help you.

CSS selector not selecting h1 element

I am going to include the full code, since I am not sure where the problem is but the element I'm trying to target is the <h1>PC Lee</h1>, I am trying to change the font color to white but it is not working:
{% extends 'core/base.html' %}
{% load static %}
{% block head %}
<link rel="stylesheet" type="text/css" href="{% static 'core/style/index2.css' %}" />
<!--links specific to style sheet 2 -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" rel="stylesheet">{% endblock %}
{% block body %}
<div id="jumbotron">
<ul>
<li class="align_left">PCLee</li>
<li class="align_right">Repairs/Upgrades</li>
<li class="align_right">Networking</li>
<li class="align_right">Remote Backups</li>
<li class="align_right">Data Recovery</li>
</ul>
<div id="h1_div"><h1>PC Lee</h1>
<img id="image" src="{% static "core/images/logo.png" %}" alt="My image" height="400" width="200"/>
</div>
</div>
<h1>dafs</h1>
<div id="grid">
<div id="content">
<h1>About Us</h1>
<img src="{% static "core/images/first_img.jpeg" %}" alt="My image"/>
<p>PCLee Computer has been dedicated to providing outstanding technical support to the New York Tri-State area for over 10 years. Specializing in computer sales, repair services, and networking. We have grown our business with individualized attention, honest diagnosis and fast turn-around. PCLee Computer prides itself on customer satisfaction. </p>
<p>Our technicians can assist your home or office computer repairs, computer setup, software and operating system upgrades, internet connection problems, wireless networking, peripherals (cameras, scanners, printers, iPods,), spyware and virus removal, and all other frustrating computer problems.</p>
</div>
<div id="contact_form">
<h2>Contact Us</h2>
<form role="form" action="" method="post">
{% csrf_token %}
<p>Full Name: <input type="text"></p>
<p>Email:<input type="text"></p>
Inquiry:<textarea></textarea>
<button type="submit">Submit</button>
</form>
</div>
</div>
{% endblock %}
and the css:
h1{
font-family: 'Open Sans Condensed', sans-serif;
color: white !important;
font-size: 1em;
}
none of these css statements are effecting the h1 element, but the css file is properly linked because all of the other css statements are working. Thanks for any help
Have you tried this
#h1_div h1 {
color: white;
}
Make sure your CSS file loaded. If it is loaded it can be overwritten by below CSS file.
Keep your custom CSS file below the CSS file you referenced.
You may have a CSS file being loaded after your custom one, overriding the desired properties.

Changing the background-color of a jumbotron from bootstrap in django

I am very new to web development and Django. I am following a tutorial called "Try Django 1.8".
In this code I am supposed to change the background-color of jumbotron to #155A1E.
If I press shift + refresh in google chrome, the color shows up then it changes back to gray. When I inspect the code in google chrome, I can see in the styles tab that the background-color in the .jumbotron{} has a strike-through. Also there is another verion of .jumbotron{} in the styles tab that has a background-color and has a check. If I uncheck the box, the color gets fixed.
How can I fix this in Django?
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block head_title %}Welcome | {{ block.super}}{% endblock %}
<style>
{% block style %}
.jumbotron {
background-color: #155A1E;
}
{% endblock %}
</style>
{% block jumbotron %}
<div class="jumbotron">
<div class='container'>
<div class="row">
<div class='col-sm-6'>
<h1>Try Django 1.8</h1>
<p>Some text here!!! This text should be long so that we can test the columns in the webpage. So here we go. We are trying to make this line as long as possible.</p>
<p>
<a class="btn btn-lg btn-primary" href="" role="button">Join us »</a>
</p>
</div>
<div class='col-sm-6' style="background-color:black;height:300px">
</div>
</div>
</div>
</div>
{% endblock %}
{% block content %}
<div class="row">
<div class="row">
</div>
<div class="col-xs-3 pull-right">
<p class='lead text-align-center'>{{ title}}</p>
<!--{{ user }}-->
<!--<!–{{ request.user }}–>-->
<!--abc is = {{ abc }}-->
<form method='POST' action=''>{% csrf_token %}
{{ form|crispy }}
<input class='btn btn-primary' type="submit" value="Signup" />
</form>
</div>
<div class='col-sm-3'>
<p class='lead text-align-center'>Built with Django & Bootstrap</p>
</div>
<div class='col-sm-3'>
<p class='lead text-align-center'>created for starters of all kinds.</p>
</div>
<div class='col-sm-3'>
<p class='lead text-align-center'>Always open source.</p>
</div>
</div>
{% endblock %}
You can add do important to your css attribute.
Just like that:
.jumbotron {
background-color: #155A1E!important;
}
It will be taken instead of the default one
It may be very late to answer the question but could help someone who is doing the tutorial now as myself.
Problem is your style should come under the
{% block jumbotron %}
otherwise its never been executed.
Here it is
{% block jumbotron %}
<style>
{% block style %}
.jumbotron {
background-color : #1e78d2 !important;
}
{% endblock %}
</style>
<div class="jumbotron">
<div class="container">....... {% endblock %}
Hope it helps someone
Makesure source of bootstrap is before your style source, and example:
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" media="all">
<link href="{% static 'css/your_style.css' %}" rel="stylesheet" media="all">

Align cart icon next to main logo - Shopify

I am trying to align the logo and cart icon in same line. Also there should be some space between the logo and the cart icon. Check the part //...moved this code here - start. That is the code I have added. It was earlier residing in a ul tag. Moved it here.
<div class="row">
<div id="logo" class="desktop-12 mobile-3">
{% if settings.use_logo_image %}
<img src="{{ 'logo.png' | asset_url }}" alt="{{ shop.name }}" style="border: 0;"/>
{% else %}
{{ shop.name }}
{% endif %}
//...moved this code here - start
<ul id="cart" class="{% if settings.enable-hello %}desktop-3 {% else %}desktop-6{% endif %} tablet-6 mobile-3">
<li class="cart-overview"><i class="icon-shopping-cart icon-2x"></i><span id="item_count">{{ cart.item_count }}</span>
<div id="crt">
{% include 'shopping-cart' %}
{% if cart.item_count != 0 %}
<a class="checkout-link" href="/cart">{{ 'cart.general.checkout' | t }}</a>
{% endif %}
</div>
</li>
</ul>
//...moved this code here - end
</div>
</div>
This is the output I am getting now.
And this is the output I am expecting.
Yes so under the div named logo; both logo image and then cart comes. So inorder to align in same line
for example below:
<div class="logo">
<div class="logoimg"></div>
<div class="cartimg"></div>
</div>
Style becomes like eg:
<style>
.logo{display:inline-block;width:900px}
.logoimg{float:left;width:400px;}
.cartimg{float:right;width:400px;}
</style>
Let me know for more details if needed.

twitter bootstrap blocks displaying

I am using twitter bootstrap for my website mywebsite.
I created four category blocks using col-md-3. When a block is heigher than the other, the other blocks don't dispay correctly. Here is my code:
<div class="row">
{% for category in categoriesActivities %}
<div class="col-md-3 col-sm-6">
<ul class="classifieds-category">
<li><i class="fa fa-bullhorn"></i>{{ category.name }}
<ul class="sub-category">
{% for activity in category.activities %}
<li>
{{ activity.principal }}
</li>
{% endfor %}
</ul>
</li>
</ul>
</div><!-- End grid layout -->
{% endfor %}
</div> <!-- End .row -->
Image of the blocks:
How can i fix it?
you need to add
<div class="clearfix"></div>
After the Informatiqe div.
That clears the col-- float.

Resources