Crop section of image without sticking out - html

I am successfully achieving my goal but in so doing the divs stick outside the normal area and require scrolling. How can I achieve this sort of masking while keeping everything contained horizontally. I've tried altering the position of various elements and can't seem to achieve this goal. *Note the colors are only there for reference, in the end the red/blue/green divs would be white.
https://jsfiddle.net/xevsz81c/
#leftDivider {
width: 50%;
height: 50px;
background:red;
float: left;
position: absolute;
left: -50px;
}
#leftDivider div{
bottom: 0px;
height: 0px;
border-style: solid;
border-width: 50px 0 0 60px;
border-color: transparent transparent transparent green;
float: left;
position: relative;
left: 100%;
}
#rightDivider {
width: 50%;
height: 50px;
background: blue;
float: right;
position: absolute;
right: -50px;
}
#rightDivider div{
bottom: 0px;
height: 0px;
border-style: solid;
border-width: 0 0 50px 60px;
border-color: transparent transparent green transparent;
float: right;
position: relative;
right: 100%;
}
.divider {
position: absolute;
bottom: 50px;
right: 0;
left: 0;
}
.row {background: orange; position: relative; height: 300px; padding: 0; margin: 0;}
html, body {margin: 0; padding: 0;}
<div class="row">
This div has a background image
<div class="divider"><div id="leftDivider"><div></div></div></div>
<div class="divider"><div id="rightDivider"><div></div></div></div>
</div>

I am having a difficult time recreating the issue in your fiddle, might be a lack of the image within the orange div. But try the following:
You would have to utilize the overflow: hidden property.
By doing this you hide the extra and disable the scrolling which sounds like what you need and are experiencing.
See the explanation here as well as its uses.

Related

Fullscreen div showing scrollbar

I am trying to make div set to full screen with following CSS but always a scrollbar shows up and if I lessen width and height more than 100% then this is not working perfectly responsively. Is there a way I can make div set to full screen responsively?
#fullScreen
{
position: absolute;
text-align: left;
left: 0px;
top: 0px;
width: 100vw;
height: 100vh;
z-index: 5;
background-color: #FFDAB9;
border: 4px solid #FF0000;
border-radius: 10px;
}
I think the problem is due to the increased size of border i.e 4px so just try this
#fullScreen
{
margin: 0px;
position: absolute;
text-align: left;
left: 0px;
top: 0px;
width: calc(100% - 8px);
height: calc(100% - 8px);
z-index: 5;
background-color: #FFDAB9;
border: 4px solid #FF0000;
border-radius: 10px;
}
You should read about the CSS box model.
The problem is that the border is considered outside the element. So your element has a width/height of 100vh + 8px. 8px from the border values of 4px.
You can easily fix this by adding box-sizing:border-box so that the border width is included in the element
See below
#fullScreen {
position: absolute;
text-align: left;
left: 0px;
top: 0px;
width: 100vw;
height: 100vh;
z-index: 5;
background-color: #FFDAB9;
border: 4px solid #FF0000;
border-radius: 10px;
box-sizing:border-box;
}
<div id="fullScreen">
</div>

Image displaying a few pixels outside element

My image is displaying outside the element tag, like this:
Notice that the image itself is outside the element. Tried with both background image and IMG tag. Same results.
HTML and CSS structure:
.class {
width: 35px;
height: 35px;
position: absolute;
background: #FFFFFF;
margin-left: 310px;
border: 1px solid #E6E6E6;
border-radius: 50%;
margin-top: 5px;
}
.rounded {
border-radius: 100%;
}
.class2 {
height: 25px;
z-index: 100;
position: absolute;
width: 25px;
right: 0;
background-size: 25px 25px !Important;
background-color: black !important;
}
<div class="class">
<div class="class2 rounded" style="background: url('<image fetched with php code here>')" ></div>
</div>
The blue square in the image attached above code, is the inspector highlighting and NOT a part of the code/structure.
eThe actual question: Look at the blue element highlighter. That is the element, that the image has been assigned to. Notice how the image is sticking a few pixels out in the top and left side. Why is it outside the element?
I tried display: flex; as mentioned in a now deleted post, that didn't fix it.
just change position:absolute in .class (parent) to position:relative - that would do the trick. Like so:
.class {
width: 35px;
height: 35px;
position: relative;
background: #FFFFFF;
margin-left: 310px;
border: 1px solid #E6E6E6;
border-radius: 50%;
margin-top: 5px;
}
added later:
I see it now. That behaviour is absolutely normal cause they were sqares.
remove radius from .class2 for testing and zoom and you'll see why it happens.
Just adjust position of class2 adding this, and it would be ok.
right: 2px;
top: 2px;
If you set:
top: 0;
left: 0;
right: 0;
bottom: 0;
This will make the element adjustable by margin.
Then you can add:
margin: auto;
and it will display the image centered.
.class {
width: 35px;
height: 35px;
position: absolute;
background: #FFFFFF;
margin-left: 310px;
border: 1px solid #E6E6E6;
border-radius: 50%;
margin-top: 5px;
}
.rounded {
border-radius: 100%;
}
.class2 {
height: 25px;
z-index: 100;
position: absolute;
width: 25px;
right: 0;
left: 0;
bottom: 0;
top: 0;
margin: auto;
/*background-size: 30px 30px;*/
}
<div class="class">
<div class="class2 rounded" style="background: url('http://www.lorempixel.com/100/100/"></div>
</div>

Crop both sides of a CSS shape when resizing

I have this triangle:
When browser gets smaller it is cropped this way:
I would like it to crop from both left and right, so the text would still be viewable.
Markup:
echo '<div class="triangle"><p class="season">SEASON '.substr($patch_array[$x][0],0,1).'</p></div>';
CSS:
.season{
font-size: 16px;
text-align: center;
top: -35px;
left: -60px;
position: relative;
width: 113px;
margin: 0px;
padding: 0px;
color: white;
}
.triangle{
width: 0;
height: 0;
clear: both;
margin-left: auto;
margin-right: auto;
border-left: 300px solid transparent;
border-right: 300px solid transparent;
border-top: 45px solid #6699ff;
}
The idea is to set the container to relative position, then draw the shape with pseudo element, and set both the shape and text as absolute position and always stay centered.
Also made a some small improvement - changed left and right border style to outset, it does the trick to make lines look much smoother on Firefox.
Try the demo, resize the output frame, and see how the shape and text always stay in the center.
JsFiddle Demo
.triangle {
text-align: center;
position: relative;
}
.triangle:before {
width: 0;
height: 0;
border-left: 300px outset transparent;
border-right: 300px outset transparent;
border-top: 45px solid #6699ff;
content: "";
display: inline-block;
position: absolute;
left: 50%;
margin-left: -300px;
}
.season {
position: absolute;
width: 100%;
text-align: center;
color: white;
margin: 10px 0;
}
<div class="triangle">
<p class="season">Hello World</p>
</div>

CSS: margin auto and position absolute

I'm trying to create a "button" with 2 sections (each is 50% of the height of the div) separated by an horizontal bar. Each of the sections has centered text. The size of the button is going to be manipulated using javascript, and I'm trying to avoid also using javascript to position the elements inside the "button".
What I have so far is http://jsfiddle.net/u5u7d31p/2/, but i'm having a problem centering the horizontal bar. If I change the position of the separator to relative, the bar is centered, but then it changes the position of the bottom part of the text. I can also change the margin to a static value (margin: 0 63px;) to center it, but I would like to avoid it if there is an easier solution that doesn't require javascript.
.img_overlay .separator{
position: absolute;
top: -1px;
left: 0;
height: 3px;
width: 70px;
margin: 0 auto;
background: #444;
}
Any ideas? Thanks.
All codes are ok. Just put this css below to .img_overlay .separator class.
Full code is below:
.img_overlay .separator {
position: absolute;
top: -1px;
left: 0;
height: 3px;
width: 70px;
margin: 0 auto;
background: #444;
right: 0;
}
view my demo on jsfiddle
.img{
float: left;
background-repeat:no-repeat;
background-size:100% 100%;
border-radius: 4px;
width: 200px;
height: 51px;
background: red;
overflow: hidden;
}
.img_overlay{
width: 100%;
height: 100%;
background: #222;
color: #ddd;
position: relative;
opacity: 0.8;
}
.img_overlay>div{
display: block;
width: 100%;
height: 50%;
text-align: center;
position: relative;
}
.img_overlay .middle{
position: relative;
top: 50%;
transform: translateY(-50%);
}
.img_overlay .separator{
height: 3px;
width: 70px;
margin: 0 auto;
background: #444;
}
<div class="img">
<div class="img_overlay">
<div class="img_show_details">
<div class="middle">details</div>
</div>
<div class="img_open">
<div class="separator"></div>
<div class="middle">open</div>
</div>
</div>
</div>
All I did was taking off :
.img_overlay .separator{
position: absolute;
top: -1px;
left: 0;
}
This following fix works okay in firefox and chrome but mess in IE.
I fixed height in div, top in middle and top in separator
.img_overlay>div {
display: block;
width: 100%;
height: 40%;
text-align: center;
position: relative;
}
.img_overlay .middle {
position: relative;
top: 60%;
transform: translateY(-50%);
}
.img_overlay .separator {
position: relative;
top: 5px;
left: 0;
height: 3px;
width: 70px;
margin: 0 auto;
background: #444;
}
here's the demo in jsfiddle.

fixed right menu with 100% width content

when this menu is on the left the 100% width content is fine, as soon as i swap the menu from the left to right right the content is now 100% the whole width and not the space between the menu (its when i add right: 0; to the left menu to make it appear on right
jfiddle left menu: http://jsfiddle.net/mxadam/ZQQ6s/21/
jfiddle right menu: http://jsfiddle.net/mxadam/ZQQ6s/22/
left menu
html, body {
height: 100%;
margin: 0;
font-size: 20px;
}
#left {
width: 300px;
height: 100%;
position: fixed;
outline: 1px solid;
background: red;
z-index: 10;
}
#right {
width: 100%;
height: auto;
outline: 1px solid;
position: absolute;
right: 0;
background: blue;
left: 300px;
border-left: 10px solid #fff;
}
right menu
html, body {
height: 100%;
margin: 0;
font-size: 20px;
}
#left {
width: 300px;
height: 100%;
position: fixed;
outline: 1px solid;
background: red;
z-index: 10;
right: 0;
}
#right {
width: 100%;
height: auto;
outline: 1px solid;
position: absolute;
left: 0;
background: blue;
right: 300px;
border-right: 10px solid #fff;
}
what can i do? cheers
Remove the width:100%.
The left and right coordinates of an absolute or fixed positioned element are enough to calculate the desired width.
Just remove the border:10px.. The white space is nothing but border...
border-left: 10px solid #fff;
Either remove it or make it blue or red to remove the color distinguish.. :-)
Edited JSFiddle (I know it is not needed :P) : http://jsfiddle.net/rahulrulez/ZQQ6s/23/
http://jsfiddle.net/xTPLG/
Check this link. It might help you.
#right {
height: auto;
outline: 1px solid;
position: absolute;
left: 0;
background: blue;
width:250px;
border-right: 10px solid #fff;
}