how to create a half-box in html/css - html

I'm trying to create a div that has a left and top border with text in top line. what I am trying to achieve is the following...
html half box
I am able to get the top with the text using the following css or alternately a table but can't get it with the left border also. any 'outside the box' thinkers?
.hr-sect {
display: flex;
align-items: center;
color: blue;
margin: 8px 0px;
}
.hr-sect::before
{
content: "";
width: 20px;
background: #000;
height: 1px;
font-size: 0px;
line-height: 0px;
margin: 0px 8px;
}
.hr-sect::after {
content: "";
width:100%;
background: #000;
height: 1px;
font-size: 0px;
line-height: 0px;
margin: 0px 8px;
}
CATEGORY
CATEGORY

You can simulate that interrupted border line by using an absolutely placed div that has a non-transparent background, just make sure it matches the actual background color.
.half-box {
border-left: 1px solid black;
border-top: 1px solid black;
position: relative;
padding: 30px;
}
.half-box > .title {
background-color: white;
padding: 0 10px;
position: absolute;
top: 0;
left: 30px;
font-size: 20px;
transform: translateY(-50%);
}
<div style="height: 100px">
</div>
<div class="half-box">
some content
<div class="title">
CONTENT
</div>
</div>

Set a positioning context on the outer box with position: relative;
For the border, use a pseudo ::before element with content: " "; and give it a position: absolute; to take it out of the flow. Give it a top and left border.
For the heading, also use position: absolute; and move it up with top: -20px or whatever. Set the same background color as the outer box to mask the border.
Adjust your margins and paddings as needed.
See this codepen: https://codepen.io/matthewsmith_io/pen/RVYQqy

Related

Add vertical and horizontal line to a div (representing a bracket) using selectors of CSS

I'm doing a design using HTML & CSS to represent that I'm doing a calculation with the data that will be entered on the fields.
What I want to achieve:
What I have tried:
.bracket-dividers {
border-left: 4px solid #000;
border-right: 4px solid #000;
position: relative;
display: inline-flex;
}
.bracket-dividers:before {
content: '';
height: 4px;
width: 10px;
background: #000;
position: absolute;
top: 0;
}
.bracket-dividers:after {
content: '';
height: 4px;
width: 10px;
background: #000;
position: absolute;
bottom: 0;
}
.plus-symbol {
height: 35px;
width: 35px;
color: #000;
font-size: 35px;
line-height: 35px;
text-align: center;
align-self: center;
}
.plus-symbol::before {
content: '+';
}
<div class="bracket-dividers">
<div>
Field 1
</div>
<span class="plus-symbol"></span>
<div>
Field 2
</div>
</div>
Issues In the example above:
if I copy-paste the .bracket-dividers:before and .bracket-dividers:after but changing the position (right & top = 0, right & bottom = 0), causes that the horizontal lines of the left side disappear. Maybe we cannot have more than 1 before/after selector?
I try to apply margin or padding to the content inside but, don't work. Seems that the selectors don't allow this.
My goal is to apply the vertical and horizontal lines on both sides to a div and apply a space inside for the content (margin or padding).
No, you cannot define multiple pseudo-elements (::before / ::after) for a single element.
Instead, imagine using the ::before pseudo-element for the left bracket and the ::after pseudo-element for the right bracket.
The left bracket is an element with top, left and bottom borders defined, while the right bracket is an element with the top, right and bottom borders defined.
Example:
.bracket-dividers {
position: relative;
display: inline-flex;
margin-left: 10px;
margin-right: 10px;
line-height: 35px;
padding: 30px; /* Extra padding works correctly! */
}
.bracket-dividers:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: -10px;
width: 10px;
box-sizing: border-box;
border: 4px solid #000;
border-right: 0;
}
.bracket-dividers:after {
content: '';
position: absolute;
top: 0;
bottom: 0;
right: -10px;
width: 10px;
box-sizing: border-box;
border: 4px solid #000;
border-left: 0;
}
.plus-symbol {
height: 35px;
width: 35px;
color: #000;
font-size: 35px;
line-height: 35px;
text-align: center;
align-self: center;
}
.plus-symbol::before {
content: '+';
}
<div class="bracket-dividers">
<div>
Field 1
</div>
<span class="plus-symbol"></span>
<div>
Field 2
</div>
</div>
A border-image can do it:
.bracket-dividers {
border: 4px solid transparent;
border-image:linear-gradient(to right,#000 10px,transparent 0 calc(100% - 10px),#000 0) 4;
padding:10px;
display: inline-flex;
}
.plus-symbol {
height: 35px;
width: 35px;
color: #000;
font-size: 35px;
line-height: 35px;
text-align: center;
align-self: center;
}
.plus-symbol::before {
content: '+';
}
<div class="bracket-dividers">
<div>
Field 1
</div>
<span class="plus-symbol"></span>
<div>
Field 2
</div>
</div>

How to pixel-perfect mockup this border?

I'm trying to mockup this design:
But, I can't render the red border correctly. I tried with the obvious solution:
border: 1px solid #939393;
border-left: 4px solid red;
But It's affected by the top and bottom borders, leaving the red stripe with diagonal corners, as you can see in this fiddle:
http://jsfiddle.net/anp0e03k/
Is there any way correct way to fix this?
The only thing that I can think is to add a div inside with red background and negative margins on top and bottom, but it seems to be an overkill and would love to find something that doesn't ruins the html semantic.
Apply the left border to a :before pseudo element of the div and remove the divs left border.
Compatibility: All modern browsers and IE8 +
Give the :before
height: 100% to span the entire height of your div
margin-top: -1px to overlap the top border
padding-bottom: 2px to overlap the bottom border
Then use either
position: absolute on the :before with position: relative on the div like this example:
body {
background-color: #c2c2c2;
}
div {
margin: 50px;
background-color: #FFF;
border: 1px solid #939393;
height: 50px;
width: 200px;
border-left: none;
position: relative;
}
div:before {
content: '';
display: block;
border-left: 4px solid red;
height: 100%;
margin-top: -1px;
padding-bottom: 2px;
position: absolute;
top: 0;
left: 0;
}
<div>
</div>
or
display: inline-block for the :before like this example:
Note: You will probably want to use vertical-align: top / middle / bottom for the :before. This example uses the value top.
body {
background-color: #c2c2c2;
}
div {
margin: 50px;
background-color: #FFF;
border: 1px solid #939393;
height: 50px;
width: 200px;
border-left: none;
}
div:before {
content: '';
display: inline-block;
border-left: 4px solid red;
height: 100%;
margin-top: -1px;
padding-bottom: 2px;
vertical-align: top;
}
<div>
There is text in this
</div>
Final result

Vertical line centered above div

I am trying to get this done in HTML and CSS. I am able to get the box done using the border and padding. But how do I get the line above?
Here is what I have so far:
.november {
padding: 1%;
border: 2px solid #000;
}
<div class="november">November 2014</div>
Pseudo element goodness
The HTML
It's a one liner:
<div>November 2014</div>
The CSS
The vertical line is created with a :before pseudo element:
The :before pseudo element is given position: absolute
left: 50% shifts the line to the middle and bottom: 100% pops the line above the div
The line is created by the 2px width
margin-left: -2px shifts the line 2px to the left to correctly offset its position (this is equal to the width)
The div is made position: relative and the position: absolute :before will position itself in relation to it. Space above the div is created with the top margin.
Complete Example
In this example, display: inline-block allows the div to expand and retract with its contents.
div {
padding: 10px;
border: solid 2px #000;
display: inline-block;
position: relative;
margin-top: 50px;
}
div:before {
content: '';
width: 2px;
height: 50px;
background: #000;
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -2px;
}
<div>November 2014</div>
I tried this and got it right:
body {
background: #EEE;
}
.november {
margin: 0;
padding: 1%;
border: 2px solid white;
clear: both;
}
<div class="col-sm-2">
<hr style="width: 2px; border-top: 50px solid white; padding: 0; text-align: center; margin: auto;" />
<div class="november">November 2014</div>
</div>

how to get the div with text on another background image

I need to get the div content like this
Where "time" is the text on the background-image
Use CSS Positioning techniques, here am doing nothing but nesting an element which is set to position: absolute; under the parent element which is set to position: relative;. Also am using rgba for opaque border and last but not the least am using bottom and right properties set to 0 to position the timer on the bottom right.
Demo
div {
height: 200px;
width: 280px;
background: url(http://pimg.tradeindia.com/00288122/b/0/Our-Valuable-Client-List-Click-on-Image-.jpg);
border: 5px solid rgba(0,0,0,.4);
position: relative;
}
div span {
position: absolute;
right: 0;
bottom: 0;
padding: 5px;
font-weight: bold;
font-size: 14px;
font-family: Arial;
color: #fff;
background: rgba(0,0,0,.5);
}

Link not appearing in div class, appearing outside of it

I'm trying to re-create a few elements I've seen online and I've been using Element Inspector but can't seem to figure out why this a href element is loading outside of my modalHeader class.
Here's some HTML:
<div id="modalContainer">
<div class="fakeModal">
<div class="modalHeader">
<h2>Fake Modal Heading</h2>
x
</div> <!-- end modalHeader -->
</div> <!-- End fakeModal -->
And corresponding CSS (using Less)
#modalContainer {
width: 700px;
height: 250px;
background: gray;
padding: 1px; }
.fakeModal {
width: 500px;
height: 150px;
margin: 50px auto 50px auto;
border-radius: 3px;
//border: 3px solid black;
background: white;
}
.modalHeader {
h2 {
background: #dullGray;
border-bottom: solid 1px #EEE; //This makes so much of a difference!!!!
border-radius: 3px 3px 0 0;
display: block;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
padding: 9px 15px;
}
a.close{
position: absolute;
top: 10px;
right: 10px;
color: gray;
text-decoration: none;
font-size: 18px;
}
a.close:hover {
text-decoration: underline;
color: gray;
}
}
Can anyone figure out why the x isn't rendering in the horizontal box I've defined in modalHeader?
#zack; you give position: absolute; to your a tag so, give position: relative; to your parent div modalHeader that's work for you .
CSS:
.modalHeader {position: relative;}
for more read this article http://css-tricks.com/791-absolute-positioning-inside-relative-positioning/
You've set the link to be position absolute, not relative to it's parent container. Remove the position, and change the top and right to margins.
An absolute position always refers to the element above which is positioned relative or absolute. If there isn't one, it refers to the body. Try to change position: absolute; to position: relative; or define the modalHeader as position: relative;.