Place border around multiple cells in a gridview - asp.net

So I have a Gridview that I would like to modify the look of for only certain cells, and I would like to treat those cells as one (if possible).
So first I am changing some of the cells background color on RowDataBound:
if (e.Row.RowIndex > 1 && e.Row.RowIndex < 7)
{
e.Row.Cells[1].BackColor = Color.Red;
e.Row.Cells[2].BackColor = Color.Red;
e.Row.Cells[3].BackColor = Color.Red;
e.Row.Cells[4].BackColor = Color.Red;
e.Row.Cells[5].BackColor = Color.Red;
}
This will change a 5x5 area of cells to red. Now what I would like to do next is put a border around the outside of that 5x5 area. I found the borderStyle and BorderColor for a cell, but is there a way for me to only turn on a border for one side of a cell so I can create my border?
Thanks

I'd advise you to use classes instead, don't hard-code it like this. It will be easier to maintain etc.

I just thought I would post this as a solution, in case anyone else is looking to do this.
Here is my CSS
<style type="text/css">
.LeftUpperCorner
{
border-left:5px solid black;
border-top:5px solid black;
}
.Top
{
border-top:5px solid black;
}
.RightUpperCorner
{
border-right:5px solid black;
border-top:5px solid black;
}
.Left
{
border-left:5px solid black;
}
.Right
{
border-right:5px solid black;
}
.LeftLowerCorner
{
border-left:5px solid black;
border-bottom:5px solid black;
}
.Bottom
{
border-bottom:5px solid black;
}
.RightLowerCorner
{
border-right:5px solid black;
border-bottom:5px solid black;
}
and my code behind:
if (e.Row.RowIndex == 2)
{
e.Row.Cells[1].CssClass = "LeftUpperCorner";
e.Row.Cells[2].CssClass = "Top";
e.Row.Cells[3].CssClass = "Top";
e.Row.Cells[4].CssClass = "Top";
e.Row.Cells[5].CssClass = "RightUpperCorner";
}
if (e.Row.RowIndex == 3 || e.Row.RowIndex == 4 || e.Row.RowIndex == 5)
{
e.Row.Cells[1].CssClass = "Left";
e.Row.Cells[5].CssClass = "Right";
}
if (e.Row.RowIndex == 6)
{
e.Row.Cells[1].CssClass = "LeftLowerCorner";
e.Row.Cells[2].CssClass = "Bottom";
e.Row.Cells[3].CssClass = "Bottom";
e.Row.Cells[4].CssClass = "Bottom";
e.Row.Cells[5].CssClass = "RightLowerCorner";
}
It may not be the prettiest, but this has not real need to change, and will always be in the same location, so it fits my simple needs.

Related

Dynamic Text with surrounding line, whose container has a background image

I need to implement something like this..
-------------------------
| |
| |
|---- dynamic text --- |
| |
-------------------------
I want the line surrounding the "dynamic text" in css.
I tried using &::before and &::after css, but still when the dynamic text changes i need to stretch/decrease that one. Any ideas?
You could use JavaScript to set the width of :before and :after :pseudo-elements dynamically.
function foo() {
var ss = document.styleSheets;
var text = document.getElementById('text');
var box = document.getElementById('box');
var totalWidth = getComputedStyle(box).width.slice(0, -2);
var textWidth = text.offsetWidth;
var lineWidth;
var margin = 4; // Set the margin between text and line.
for (i = 0; i < ss.length; i++) {
var rules = ss[i];
for (j = 0; j < rules.cssRules.length; j++) {
var r = rules.cssRules[j];
if (r.selectorText == "#text:before") {
// If you want the margin to be set on both sides of the line,
// replace 'margin' with '(margin * 2)' in the next line.
lineWidth = ((totalWidth / 2) - (textWidth / 2) - margin);
r.style.width = lineWidth + 'px';
r.style.left = -(lineWidth + margin) + 'px';
} else if (r.selectorText == "#text:after") {
r.style.width = lineWidth + 'px';
r.style.right = -(lineWidth + margin) + 'px';
}
}
}
}
foo();
#box {
width: 300px;
height: 200px;
background-color: #FF0000;
line-height: 200px;
text-align: center;
}
#text {
position: relative;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 10px;
padding: 4px;
color: white;
}
#text:before {
content: "";
position: absolute;
border-bottom: 1px solid black;
height: 100px;
}
#text:after {
content: "";
position: absolute;
border-bottom: 1px solid black;
height: 100px;
}
<div id="box"><span id="text">This is the text which is dynamic</span>
</div>
<div id="divWithBackground">
<div id="divActsAsLine">
<span id="DynamicText">Your text here </span>
</div>
</div>
Now the CSS
#divActsAsLine{
border-botton:1px solid #00;
text-align:center;
}
#DynamicText{
position:relative;
background-color: #fff;
margin-bottom:-20px /*Adjust this based on your requirements*/
z-index:1 /* optional */
}
The logic is to make a div margin as background line and make the span overlap this line, to do this we need to either decrease or increase margin property. you might need to use z-index if necessary

AngularJS - how to refactoring a CSS code style

I have an angular function like this:
$scope.colorValidator = function () {
$scope.token_style = "";
$scope.expdate_style = "";
if (!$scope.$$childHead.billingblock.accountID.$valid) {
$scope.token_style = {border: "1px solid #ff0000"}
}
if (!$scope.$$childHead.billingblock.expDate.$valid) {
$scope.expdate_style = {border: "1px solid #ff0000"}
}
};
How can i set the {border: "1px solid #ff0000"} in a constant variable (maybe like red), and set it in each validation ?
Edit: I'm setting ng-style (in the view) for each input.
You do not need to do that.
Check you markup when fields are not valid, they have ng-dirty and ng-invalid classes applied
Use them to style your controls
.my-special-form .ng-invalid {
border: 1px solid #ff0000
}
Please see here: http://jsbin.com/hekaz/3/edit?css,output
ie:
input.ng-invalid[ng-model="username"] {
border: 5px solid red;
}
input.ng-valid[ng-model="username"] {
border: 5px solid green;
}
I solved it setting it a variable:
var redColor = {border: "1px solid #ff0000"};
if (!$scope.$$childHead.billingblock.accountID.$valid) {
$scope.token_style = redColor;
}
Thank you to everyone for each answer.

How to generate classes in LESS?

I need to generate all combinations the following classes:
.b-1-1-1-1 {
border:1px solid #000;
}
.b-0-1-1-1 {
border-right: 1px solid #000;
border-bottom: 1px solid #000;
border-left: 1px solid #000;
}
.
.
.
I need to use class names as border style likes, is it possible to make it in LESS automatically?
You could also just loop through binary numbers instead of a nested loop (makes everything a bit shorter) ... something like this perhaps:
.set-top() when (#t > 0) {
border-top: 1px solid #000;
}
.set-left() when (#l > 0) {
border-left: 1px solid #000;
}
.set-right() when (#r > 0) {
border-right: 1px solid #000;
}
.set-bottom() when (#b > 0) {
border-bottom: 1px solid #000;
}
.borders(#t:0, #r:0, #b:0, #l:1){
.b-#{t}-#{r}-#{b}-#{l} {
.set-top;
.set-right;
.set-bottom;
.set-left;
}
}
.loop(#i:16) when (#i < 32) {
.borders(~`(#{i}).toString(2)[1]`,
~`(#{i}).toString(2)[2]`,
~`(#{i}).toString(2)[3]`,
~`(#{i}).toString(2)[4]`);
.loop((#i + 1));
}
.loop();
In addition you can again add a check for which properties are set/same and combine them under a combined border property and set the border width/style/color like ScottS shows in his example.
(Update: I've been asked to rework my example to a complete snippet - so here we go).
Variant 1
Basically it's the same as in Martin Turjak answer but without inline javascript and with some further makeup:
// usage:
.borders(1px dashed wheat);
div {
.borders(3px, dotted, red);
}
// implementation:
.borders(#values...) {
.values(t, 1) {border-top: #values}
.values(r, 1) {border-right: #values}
.values(b, 1) {border-bottom: #values}
.values(l, 1) {border-left: #values}
.values(... ) {}
.trbl-(#t, #r, #b, #l) {
.b-#{t}-#{r}-#{b}-#{l} {
.values(t, #t);
.values(r, #r);
.values(b, #b);
.values(l, #l);
}
}
.-(#i: 15) when (#i > 0) {
.-((#i - 1));
.trbl-(mod(floor((#i / 8)), 2),
mod(floor((#i / 4)), 2),
mod(floor((#i / 2)), 2),
mod(floor((#i / 1)), 2));
}.-;
}
Variant 2
The magic one, no loops, minified CSS output:
// usage:
.borders(1px, dashed, wheat);
// implementation:
.borders(#values...) {
0, 1 {
.b-1-&-&-& {border-top: #values}
.b-&-1-&-& {border-right: #values}
.b-&-&-1-& {border-bottom: #values}
.b-&-&-&-1 {border-left: #values}
}
}
Doable
This code allows flexibility in setting style and color to the border, the unit value of the width, and defaults to max width of 1 unit (which is px by default). Note that setting the border width values to anything more than 1, the output CSS code is going to begin increasing at a dramatic rate (try running them at just 2, i.e. calling .generateBorderClasses(#t: 2, #r: 2, #b: 2, #l: 2);, and see the results);
.generateBorderClasses(#unit: px, #style: solid, #color: #000, #t: 1, #r: 1, #b: 1, #l: 1) {
.b() when (#check) {
border: unit(#t,#unit) #style #color;
}
.b() when (#sum = 0) {}
.b() when (#t > 0) and (#sum > 0) and not (#check) {
border-top: unit(#t, #unit) #style #color;
}
.b() when (#r > 0) and (#sum > 0) and not (#check) {
border-right: unit(#r, #unit) #style #color;
}
.b() when (#b > 0) and (#sum > 0) and not (#check) {
border-bottom: unit(#b, #unit) #style #color;
}
.b() when (#l > 0) and (#sum > 0) and not (#check) {
border-left: unit(#l, #unit) #style #color;
}
.t-loop (#t) when (#t > -1) {
.r-loop (#r) when (#r > -1) {
.b-loop (#b) when (#b > -1) {
.l-loop (#l) when (#l > -1) {
#sum: (#t + #r + #b + #l);
#check: e(`(#{t} == #{r}) && (#{t} == #{b}) && (#{t} == #{l}) ? "true" : "false"`);
.b-#{t}-#{r}-#{b}-#{l} {
.b();
}
.l-loop(#l - 1);
}
.l-loop (-1) {}
.l-loop(#l);
.b-loop(#b - 1);
}
.b-loop (-1) {}
.b-loop(#b);
.r-loop(#r - 1);
}
.r-loop (-1) {}
.r-loop(#r);
.t-loop(#t - 1);
}
.t-loop(-1) {}
.t-loop(#t);
}
.generateBorderClasses();
Still Not Recommended
Personally, I would just have four classes controlling the html (so something like class="bt br bb bl") and then do this:
.bt {
border-top: 1px solid #000;
}
.br {
border-right: 1px solid #000;
}
.bb {
border-bottom: 1px solid #000;
}
.bl {
border-left: 1px solid #000;
}
MUCH less (pun intended) css code and essentially the same control value in the class assigning of the html.

Hghlighted field with red border in Wordpress Contact Form 7

I want to get this effect http://jquery.bassistance.de/validate/demo/ by Wordpress Contact Form 7.
I set in css
.wpcf7-not-valid{
border:1px solid #d73333!important;
}
But when I insert value into the field the red border do not disappear.
Got a good solution. In wp-content\plugins\contact-form-7\includes\js\scripts.js
Changed
$.fn.wpcf7NotValidTip = function(message) {
return this.each(function() {
var into = $(this);
into.append('<span class="wpcf7-not-valid-tip">' + message + '</span>');
$('span.wpcf7-not-valid-tip').mouseover(function() {
$(this).fadeOut('fast');
});
into.find(':input').mouseover(function() {
into.find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
});
into.find(':input').focus(function() {
into.find('.wpcf7-not-valid-tip').not(':hidden').fadeOut('fast');
});
});
};
to this code
$.fn.wpcf7NotValidTip = function(message) {
return this.each(function() {
var into = $(this);
$theParent = into.parent("span");
$parentInp = $theParent.parent("input");
into.find(':input').css('border-color', '#d73333');
into.find(':input').mouseover(function() {
into.find(':input').css('border-color','#cccccc');
});
into.find(':input').focus(function() {
into.find(':input').css('border-color','#cccccc');
});
});
};
.wpcf7-validation-errors, .wpcf7-mail-sent-ng {
padding: 5px;
color: #E68B8B;
background-color: #FDF5F8 !important;
border: 1px solid #FDE2E2 !important;
width: 518px !important;
}
There is no universal solution because it all depends on how you styled your form
Anyway you can try use something like that:
span .wpcf7-not-valid {
border: 1px solid #ff0000 !important;
}
Note: using !important is never the best way to do anything with css

css: float blocks to occupy all free space

I'm trying to make an "image mosaic" that consists mostly of images of the same size, and some of them the double height.
They all should align neatly like this:
To make automatic generation of those mosaic as easy as possible, I thought floating them would be the best option. Unfortunately, the big block causes the following ones to flow behind it, but not before:
What can I do - apart from manually positioning them - to get the images to the place I want, and still have it easy to automatically create likewise layouts?
The code I'm currently using is :
FIDDLE
HTML :
<div class="frame">
<div id="p11" class="img">1.1</div>
<div id="p12" class="img h2">1.2</div>
<div id="p13" class="img">1.3</div>
<div id="p21" class="img">2.1</div>
<div id="p22" class="img">2.2</div>
</div>
CSS :
.frame {
background-color: blue;
border: 5px solid black;
width: 670px;
}
.img {
width: 200px;
height: 125px;
background-color: white;
border: 1px solid black;
float: left;
margin: 10px;
}
.h2 {
height: 272px;
}
You need to use Javascript to achieve this effect, I had to do that once and I used http://masonry.desandro.com/ -- worked well!
Pure CSS Solution
Tested in Firefox, IE8+ (IE7 looks like it would need to be targeted to add a top margin added to 2.1 because it overlaps 1.1). See fiddle. This assumes .h2 is the middle div (as your example). If left most div it should not need any change. If right most, you would need to expand the negative margin to also include the third div following.
.h2 + div {
float: right;
margin: 10px 14px 10px 0; /*14px I believe also has to do with borders */
}
.h2 + div + div {
margin-left: -434px; /*need to account for borders*/
clear: right;
}
You can use a column layout like this:
http://jsfiddle.net/KKUZL/
I don't know if that will conflict with your automation process though....
I realize this is not a CSS-only solution, but for what it's worth (JSFiddle):
HTML:
<div id='container'></div>
CSS:
html, body {
margin:0px;
padding:0px;
height:100%;
}
body {
background-color:#def;
}
#container {
margin:0px auto;
width:635px;
min-height:100%;
background-color:#fff;
box-shadow:0px 0px 5px #888;
box-sizing:border-box;
overflow:auto;
}
.widget {
float:left;
box-sizing:border-box;
padding:10px 10px 0px 0px;
}
.widget > div{
height:100%;
box-sizing:border-box;
color:#fff;
font-size:3em;
text-align:center;
padding:.5em;
overflow:hidden;
}
.widget > div:hover {
background-color:purple !important;
}
JS:
////////////////////////////////////////
// ASSUMPTIONS
//
var TWO_COLUMN_WIDGET_COUNT = 1;
var ONE_COLUMN_WIDGET_COUNT = 15;
var NUMBER_OF_COLUMNS = 2;
////////////////////////////////////////
function rand(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var colorFactory = (function () {
var colors = [
'#CC9A17',
'#9B2C16',
'#1A8B41',
'#D97114',
'#3B9EE6'];
var index = 0;
return function () {
if (index > 4) {
index = 0;
}
return colors[index++];
}
})();
function widgetFactory(columnSpan) {
return {
'height': rand(10, 30) * 10,
'width': 100 * columnSpan / NUMBER_OF_COLUMNS,
'columnSpan': columnSpan,
'color': colorFactory()
}
}
function getWidgets() {
var widgets = [];
for (var i = 0; i < TWO_COLUMN_WIDGET_COUNT; i++) {
widgets.push(widgetFactory(2));
}
for (var i = 0; i < ONE_COLUMN_WIDGET_COUNT; i++) {
widgets.push(widgetFactory(1));
}
return widgets;
}
function getHighestOffset(offsets){
}
function getHighestSlot(offsets, numOfColumns){
}
$(document).ready(function () {
var container = $('#container');
var widgets = getWidgets();
var col1 = Math.floor(container[0].offsetLeft);
var col2 = Math.floor(container[0].clientWidth / 2 + container[0].offsetLeft);
var offsets = {};
offsets[col1] = 0;
offsets[col2] = 0;
var newLine = true;
for (var i = 0; i < widgets.length; i++) {
var w = widgets[i];
var marginTop = 0;
if (offsets[col1] < offsets[col2]) {
marginTop = (offsets[col2] - offsets[col1]) * -1;
}
if(offsets[col1] <= offsets[col2] || w.columnSpan == 2){
newLine = true;
}
var margin = 'margin-top:' + marginTop + 'px;';
var height = 'height:' + w.height + 'px;';
var color = 'background-color:' + colorFactory() + ';';
var width = 'width:' + w.width + '%;';
var padding = newLine ? "padding-left:10px;" : "";
var component = $('<div class="widget" style="' + padding + margin + height + width + '"><div style="' + color + '">' + i + '</div></div>');
component.appendTo(container);
var c = component[0];
var index = 0;
var minOffset = null;
for(var p in offsets){
if(minOffset == null || offsets[p] < minOffset){
minOffset = offsets[p];
}
if(p == Math.floor(c.offsetLeft)){
index = 1;
}
if(index > 0 && index <= w.columnSpan){
offsets[p] = c.offsetTop + c.offsetHeight;
index++;
}
}
newLine = minOffset >= offsets[col1];
}
});

Resources