First, im new so dont give me a hard time ;)
i have a problem with styling my foreach. What I want is that if I hover on the row. It only returns single line bottom and top border.
In this case when I hover on the next row the bottom top border from other rows are there creating a 2px border. I tried many things margin-top:-1px etc... some gave me a better result but not the final one.
.frameregels{
border-bottom:1px solid #e1e1e1;
border-top:1px solid #e1e1e1;
}
.frameregels:nth-child(odd){
background-color:#FFFFFF;
}
.frameregels:nth-child(even){
background-color:#f9f9f9;
}
.frameregels:hover{
background-color:#ecf5f9;
border-color:#66afe9;
}
<div class="xxlarge-12 xlarge-12 large-12 medium-12 small-12 columns frameregels">
<div class="xxlarge-1 xlarge-1 large-2 columns large-down-hidden">[artikelnr]</div>
<div class="xxlarge-11 xlarge-11 large-10 columns large-down-hidden">[omschrijving]</div>
</div>
<div class="xxlarge-12 xlarge-12 large-12 medium-12 small-12 columns frameregels">
<div class="xxlarge-1 xlarge-1 large-2 columns large-down-hidden">[artikelnr]</div>
<div class="xxlarge-11 xlarge-11 large-10 columns large-down-hidden">[omschrijving]</div>
</div>
<div class="xxlarge-12 xlarge-12 large-12 medium-12 small-12 columns frameregels">
<div class="xxlarge-1 xlarge-1 large-2 columns large-down-hidden">[artikelnr]</div>
<div class="xxlarge-11 xlarge-11 large-10 columns large-down-hidden">[omschrijving]</div>
</div>
margin-bottom:-1px is the completely right idea, however you need a few more things for that to work:
make sure you don't apply it to the last element to retain a clean bounding box of your list
position the elements in a way that accepts a z-index property so that you can shift the element you're hovering in the foreground. If you don't do this, you will change the color of your border, but the next element's border is just going to overlay it.
In practice, this is how it works (padding added for beauty):
.frameregels {
border-bottom: 1px solid #e1e1e1;
border-top: 1px solid #e1e1e1;
padding: 5px 0;
position: relative;
z-index: 0;
}
.frameregels:not(:last-child) {
margin-bottom: -1px;
}
.frameregels:nth-child(odd) {
background-color: #ffffff;
}
.frameregels:nth-child(even) {
background-color: #f9f9f9;
}
.frameregels:hover {
background-color: #ecf5f9;
border-color: #66afe9;
z-index: 1;
}
<div class="frameregels">
<div>[artikelnr]</div>
<div>[omschrijving]</div>
</div>
<div class="frameregels">
<div>[artikelnr]</div>
<div>[omschrijving]</div>
</div>
<div class="frameregels">
<div>[artikelnr]</div>
<div>[omschrijving]</div>
</div>
<div class="frameregels">
<div>[artikelnr]</div>
<div>[omschrijving]</div>
</div>
Related
Question: Is it possible to draw a CSS box around multiple div elements with unique classes, and with no ability to add parent div tags into the HTML?
I'm trying to group multiple div classes together as part of a larger form. The HTML in the form itself cannot be modified to add additional parent div layers. The CSS and JavaScript are editable
Example: We have a large request form that has 50 questions, with 10 questions in each section of the form. We can draw boxes around those individual questions, but also want to draw a box around a section of questions.
Each div has its own unique class. This is something we cannot change, as it's supplied by the tool we use.
Here's an example of our HTML and CSS:
.form-field {
background-color: #eee;
padding: 15px;
/* border: 1px solid black; */
border-radius: 5px;
box-shadow: 4px 4px grey;
}
.form-field:valid {
background-color: #000;
padding: 15px;
/* border: 1px solid black; */
border-radius: 5px;
box-shadow: 4px 4px grey;
}
.form-field.select.optional.request_ticket_form_id {
background-color: #d9ead3;
padding: 15px;
/* border: 1px solid black; */
border-radius: 5px;
box-shadow: 4px 4px grey;
}
.form-field:hover {
background-color: #ccc;
}
<div class="form-field text optional request_custom_fields_12345">
<label id="request_custom_fields_12345_label" for="request_custom_fields_12345">Vest Size<span class="optional">(optional)</span></label>
<textarea name="request[custom_fields][12345]" id="request_custom_fields_12345" aria-required="false" aria-labelledby="request_custom_fields_12345_label"></textarea>
</div>
<br>
<div class="form-field text optional request_custom_fields_67890">
<label id="request_custom_fields_67890_label" for="request_custom_fields_67890">Vest Shape<span class="optional">(optional)</span></label>
<textarea name="request[custom_fields][67890]" id="request_custom_fields_67890" aria-required="false" aria-labelledby="request_custom_fields_67890_label"></textarea>
</div>
<br>
<div class="form-field text optional request_custom_fields_98765">
<label id="request_custom_fields_98765_label" for="request_custom_fields_98765">Vest Color<span class="optional">(optional)</span></label>
<textarea name="request[custom_fields][98765]" id="request_custom_fields_98765" aria-required="false" aria-labelledby="request_custom_fields_98765_label"></textarea>
</div>
<br>
<div class="form-field text optional request_custom_fields_23456">
<label id="request_custom_fields_98765_label" for="request_custom_fields_23456">Vest Color<span class="optional">(optional)</span></label>
<textarea name="request[custom_fields][23456]" id="request_custom_fields_23456" aria-required="false" aria-labelledby="request_custom_fields_23456_label"></textarea>
</div>
The part that does not seem to work for us is trying to say "draw box around 67890 to 23456" (and anything in between).
Yes. There is a possibility
if the sole purpose is to highlight, or add a "visual shape" on-screen without altering the DOM.
Create a <div> element which has CSS position fixed.
Add pointer-events: none; to that DIV in order to use it exclusively as a "drawing layer" on-top of your app but allow pointer events to propagate trough it.
Get all your elements on the page From-element and to-element. Get their coordinates using getBoundingClientRect. BCR is relative to the viewport, which is perfect to use on a position fixed element overlay.
Once you have the "min-max" coordinates (calculate to min top-left value and the max bottom-right value) having those two points you can now freely draw a rectangle on your canvas. Coincidentally it will be drawn exactly around all the desired elements.
Make sure to "redraw/reposition" the DIV on page resize, scroll, load, DOM ready - or on some button click - if needed.
Create a JavaScript function to be used like:
highlightBox(Elements_to_consider, start_index, end_index)
// DOM utility functions:
const ELS = (sel, par) => (par || document).querySelectorAll(sel);
const EL = (sel, par) => (par || document).querySelector(sel);
// Task:
const EL_highlightBox = EL("#highlightBox");
const highlightBox = (ELS_items, fr, to) => {
const BCR_fr = ELS_items[fr].getBoundingClientRect();
const BCR_to = ELS_items[to].getBoundingClientRect();
EL_highlightBox.style.cssText = `
top: ${BCR_fr.top}px;
left: ${BCR_fr.left}px;
height: ${BCR_to.top - BCR_fr.top + BCR_to.height}px;
width: ${BCR_to.left - BCR_fr.left + BCR_to.width}px;
`;
};
const drawHighlightBox = () => highlightBox(ELS(".item"), 2, 4);
addEventListener("resize", drawHighlightBox);
addEventListener("scroll", drawHighlightBox);
drawHighlightBox();
#highlightBox {
/* Important styles: */
position: fixed;
z-index: 1000;
pointer-events: none;
/* Other styles: */
background: hsla(100, 60%, 50%, 0.2);
outline: 4px solid hsla(100, 60%, 50%, 1);
}
.item {
margin: 10px 0;
padding: 60px;
border: 1px solid gray;
}
<div id="highlightBox"></div>
<div class="item">Item 0 (scroll down)</div>
<div class="item">Item 1</div>
<div class="item">Item 2</div>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
<div class="item">Item 5</div>
<div class="item">Item 6</div>
<div class="item">Item 7</div>
<div class="item">Item 8</div>
<div class="item">Item 9</div>
<div class="item">Item 10</div>
I have a stepper, in which the active step is highlighted in blue color.
Working Snippet:
.inline-flex {
display: inline-block;
border-bottom: 2px solid black;
padding-left: 100px;
}
.inline-flex:first-child {
padding-left: initial;
}
.active {
border-bottom: 2px solid blue;
}
<div class="steps">
<div class="inline-flex active">Registration</div>
<div class="inline-flex active">Basic Information</div>
<div class="inline-flex">Professional Information</div>
<div class="inline-flex">Others</div>
</div>
To make the active indication, we are making it upto the current step title.
Requirement:
The requirement is that the progress bar should split up equally for 100% width.
In the above example there are 4 steps, So the active indication should be there for
-> 25% for Registration (If user is in Step 1)
-> 50% for Basic Information (If user is in Step 2)
I am trying to achieve it by using padding left and it only works until the title ends.
So kindly please help me to make the progress bar to split up for total width.
Expected Output:
Active in Step 1 Registration Step
Registration Basic Information Step 3
-------blue--------black------black-----black---
The easiest way to make the bars to have the same width is adapting their total percentage to a value less than 100%. For example:
.inline-flex {
display: inline-block;
border-bottom: 2px solid black;
width: 24%;
}
When using the inline-block display, the html space and line count as a little percentage of the total width (html-css shenanigans...), so you could write the html like this:
<div class="steps">
<div class="inline-flex active">Registration</div><div class="inline-flex active">Basic Information</div><div class="inline-flex">Professional Information</div><div class="inline-flex">Others</div>
</div>
When I place a border on the right of the text the border is always at the very right of the page, not to the right of the text.
I've removed the default border properties of the browser and the result is still the same.
On the code pen the third result is what I want but with the border on the right.
Example: http://codepen.io/twig941/pen/zoqEXx
Code:
<div class = "logo">
The Three Words
</div>
<br>
<br>
<br>
<br>
<div class = "ideal-logo">
The
<br>
Three
<br>
Words
</div>
<div class = "ideal-left">
The
<br>
Three
<br>
Words
</div>
.logo {
border-right: 10px solid black;
}
.ideal-logo {
border-right: 5px solid black;
}
.ideal-left {
border-left: 5px solid black;
}
Use display: inline-block; on .logo & .ideal-logo. Currently they are block elements that is why they are flowing end-to-end.
Here is the snippet, have a look:
.logo {
display: inline-block;
border-right: 10px solid black;
}
.ideal-logo {
display: inline-block;
border-right: 5px solid black;
}
.ideal-left {
border-left: 5px solid black;
}
<div class = "logo">
The Three Words
</div>
<br>
<br>
<br>
<br>
<div class = "ideal-logo">
The
<br>
Three
<br>
Words
</div>
<div class = "ideal-left">
The
<br>
Three
<br>
Words
</div>
Hope this helps!
A <div> is a block, which by default spans the entire width of the page. Thus the right edge of each <div> is the right side of the screen, and the rest is empty space.
Using display: inline-block; will make the <div> shrink-wrap around its contents. (This will also allow it to sit on the same line with text and other elements, so you might need an extra wrapper if you still want an overall block.)
This happens because you are actually applying border on <div> and div is a block element you could try setting border to paragraph ` and it will work
html
<div class = "logo">
<p>The Three Words</p>
</div>
css
p
{
border:10px dashed #000;
}
What you could also do is set a width to div and set a border around it but that is quite in-
efficient
Use display: inline-block.
The pen
.logo {
border-right: 10px solid black;
display: inline-block
}
.ideal-logo {
border-right: 5px solid black;
display: inline-block;
}
.ideal-left {
border-left: 5px solid black;
}
<div class = "logo">
The Three Words
</div>
<br>
<br>
<br>
<br>
<div class = "ideal-logo">
The
<br>
Three
<br>
Words
</div>
<div class = "ideal-left">
The
<br>
Three
<br>
Words
</div>
Im really confused, it is strangest bug i have seen in my life.
Here is JSFiddle example: http://jsfiddle.net/c92mjkne/1/
As you can see, when our "comment" is hovered, #content get stange margins (but in CSS it have no margins). As i can know, it is ol's margins. But why they are outside of parent div?
Ok, that's strange. BUT! When we changing padding: 0; to padding: 1px; in #content's CSS, we see, that block have no margin! WTF? Help me please :D I really dont know how to google :D
Here is example:
#head, #foot, #content {
padding: 7px;`
}
#content {
padding: 0;
}
#comment:hover div {
background: #eee;
}
#comment {
border: 1px solid rgba(0, 0, 0, 0);
}
#comment:hover {
border: 1px solid gray;
}
ul {
margin: 7px;
}
<div id="comment">
<div id="head">
Efog <span style="color: gray">today, 10:10 pm</span>
</div>
<div id="content">
<ul>
<li>Hello</li>
<li>Stack</li>
<li>Overflow</li>
</ul>
</div>
<div id="foot">
answer
</div>
</div>
And here is code with padding: 1px:
#head, #foot, #content {
padding: 7px;`
}
#content {
padding: 1px;
}
#comment:hover div {
background: #eee;
}
#comment {
border: 1px solid rgba(0, 0, 0, 0);
}
#comment:hover {
border: 1px solid gray;
}
ul {
margin: 7px;
}
<div id="comment">
<div id="head">
Efog <span style="color: gray">today, 10:10 pm</span>
</div>
<div id="content">
<ul>
<li>Hello</li>
<li>Stack</li>
<li>Overflow</li>
</ul>
</div>
<div id="foot">
answer
</div>
</div>
Sorry for english, thanks.
As i can know, it is ol's margins. But why they are outside of parent div?
Because they are supposed to be (the are not “outside” the div, they have become margins of the div) – http://www.w3.org/TR/CSS21/box.html#collapsing-margins:
“In CSS, the adjoining margins of two or more boxes (which might or might not be siblings) can combine to form a single margin. Margins that combine this way are said to collapse, and the resulting combined margin is called a collapsed margin.
Adjoining vertical margins collapse, […]”
So no bug at all, but specs followed to the point.
BUT! When we changing padding: 0; to padding: 1px; in #content's CSS, we see, that block have no margin!
Read on at the above point,
“Two margins are adjoining if and only if:
[…]
- no line boxes, no clearance, no padding and no border separate them
[…]”
http://jsfiddle.net/c92mjkne/2/
#comment:hover{
background: gray;
}
It is normal, you set every div inside your comment div a background but you set some a margin. If you don't want any blank area, just set the background color to the div containing them all.
It's not a bug.
I have this html code:
<div class="productWarp">
<div class="clear"></div>
<div class="productLine" ></div>
<div class="clear"></div>
<div class="productLine" ></div>
</div>
css:
.productWarp .productLine {
background-color: #DFDDDD;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
.productWarp .productLine:nth-of-type(2)
{
background-color: white;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
This choosing the second child of productWarp(first productLine) and not the second productLine,so it acting Exactly as nth-child selector
<div class="productWarp">
<div class="clear"></div>
<div class="productLine" ></div>//this one is choose
<div class="clear"></div>
<div class="productLine" ></div>//this one should be choose
</div>
any idea what wrong here?
:nth-of-type() looks at an element's type, not its class. In this case, all your elements are of the type div, which is why :nth-of-type() works exactly the same as :nth-child().
If you have only two .productLine elements, use the following selector to style your second one instead:
.productWarp .productLine ~ .productLine
{
background-color: white;
border-bottom: 1px solid #B7B7B7;
padding-right: 5px;
}
Otherwise you'll just have to go by :nth-child() indices, in this case :nth-child(4), or override styles for subsequent .productLine elements by adding more rules repeating the ~ .productLine part as necessary.
This take in consideration the clearing div.
.productWarp div.productLine:nth-of-type(4n)