Crop a picture with CSS [closed] - html

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am doing a Userstyle for a Website, so I can only change the CSS.
They generate their pictures with a white border at the top and the bottom which I want to get rid off.
The HTML-structure looks like this:
<a>
<img></img>
<span></span>
</a>
The span is a little coloured text-field, which overlaps the img, so putting overflow: hidden on the a doesnt work. (Because it will crop the span too)
I also tried using a border, but that didn't get me anywhere.
Is there another way?
EDIT: Here is a codepen of my problem

trautmann, take a look here:
https://jsfiddle.net/0qc27otz/
.wrapper {
background-color: grey;
padding-bottom: 4em;
padding-left: 4em;
padding-top: 4em;
width: 100%;
float: left;
}
div.wrapper a{
border: none;
display: block;
position: relative;
float: left;
width: auto;
height: 165px;
overflow: hidden;
}
div.wrapper a img{
display: block;
position: relative;
width: 100%;
margin-top: -5px;
}
.myspan {
display: block;
position: absolute;
bottom: 20px;
left: 5%;
width: 10%;
color: #FFF;
text-transform: uppercase;
font-weight: bold;
height: 16px;
background: red;
}
is that what you need?

As quantumwannabe said in the comments, you can use clip-path like so:
img {
-webkit-clip-path: inset(10px);
clip-path: inset(10px);
}
<img src="http://placehold.it/300x125">
Browser support is quite bad to be honest. Here's a fun tool to play with the property.

You can use clip-path on top and bottom, add this to your CSS, if the browser don't support clip-path it will not the end of the world, it will show the border image.
a > img{
/* top, right, bottom, left */
-webkit-clip-path: inset(2px 0px 2px 0px);
clip-path: inset(2px 0px 2px 0px);
}
Further Reading
Clipping in CSS and SVG — The clip-path Property and <clipPath> Element
Using clip-path

I suggest you to take a look here:
http://cssdeck.com/labs/full/1z7osafa
I added classes to img, a and wrapped everything to div.
So the main idea is to make to be blocks of definite height and hide the oversflow and also you can set any borders around.
Hope the code will be shown to you and you will understand it.
if no, here is html:
<div class='SomeWrapper'>
<a class='TheLinker' href='http://sdelanounas.ru/'>
<img class='TheIMG' src='http://sdelanounas.ru/i/c/2/r/f_c2RlbGFub3VuYXMucnUvdXBsb2Fkcy82LzkvNjk1MTM4NjU3MDk5NF9vcmlnLmpwZWc_X19pZD00NDYwMg==.jpeg'/>
<span class='sometext'>This Is a Great Plane</span>
</a>
<a class='TheLinker' href='topwar.ru/'>
<img class='TheIMG' src='http://cdn.topwar.ru/uploads/posts/2014-03/1395891634_2249x1444_su-34-frontovoj-zaschitnik-fullback.jpg'/>
<span class='sometext'>This Is a Great Plane</span>
</a>
</div>
Here is CSS:
div.SomeWrapper{
width: 100%;
display: block;
position: relative;
float: left;
}
div.SomeWrapper{
width: 100%;
display: block;
position: relative;
float: left;
}
a.TheLinker{
display: block;
position: relative;
float: left;
width: 48%;
margin: 0 1%;
height: 18em;
overflow: hidden;
}
a.TheLinker img{
width: 100%;
border: none;
}
span.sometext{
display: block;
position: absolute;
bottom: 1em;
background: rgba(255,255,255, 0.8);
color: #555;
text-shadow: #ccc;
width: 100%;
text-align: center;
}
a.TheLinker img{
width: 100%;
border: none;
}
span.sometext{
display: block;
position: absolute;
bottom: 1em;
background: rgba(255,255,255, 0.8);
color: #555;
text-shadow: #ccc;
width: 100%;
text-align: center;
}
I'm a newbie here so my code could be not properly formed, so sorry if something's not looking good..
If you have questions - ask, I think I really can help!

Related

How to overlap HTML block level element over another HTML block level element while retaining responsive behaviour across screen sizes

I am trying to replicate the behaviour of a piece of HTML and CSS content that appears on the website i have provided a link to below. The website in question is www.air-it.co.uk.
I have included below a mockup image, which indicates the layout that i want to achieve.
I do not know how else other than to link to the working version on the website below to visualise this for users reading this question, because i do not know how to solve the problem i am trying to address with this question using HTML and CSS.
The example of this can be seen roughly 1/3 of the way down the following page.
www.air-it.co.uk
Essentially, it appears to be be positioning one div on the left over another div on the right within a container. It appears to be leveraging a 'card content' element which is placed over another div containing a background image.
I could possibly do this at one screen size using absolute positioning, i think. But i need it to behave responsively in a similar way (or the same way) as the example above?
I am aware that the above example uses Foundation. But my question would be is there an inbuilt way to do this using Bootstrap?
I would imagine the alternative here is to customise CSS for different media queries in order to do this, which unfortunately i don't know how to do.
Please do not simply close this question again if you would like to take umbrage with my syntax or question structure. Kindly post your feedback or criticism in a comment which will allow me to revise this question as opposed to simply closing the question with no additional clues or feedback as to why you have chosen to do so.
Thank you.
maybe this can help, try to open in full view
body {
font-family: Roboto;
margin: 0;
}
.overlap-section {
min-height: 450px;
background-color: #fff;
display: inline-block;
float: left;
width: 45%;
border: 1px solid #ff5722;
padding: 50px;
position: absolute;
z-index: 99;
top: 50%;
transform: translateY(-50%);
left: 5%;
}
.main-box {
background-color: lightgray;
height: 100%;
width: 75%;
float: right;
position: relative;
}
.main-section {
height: 100vh;
position: relative;
}
.text-wrapper {
display: inline-block;
position: absolute;
top: 50%;
right: 26%;
transform: translate(50%, -50%);
}
.text-wrapper h2 {
display: inline-flex;
margin: 0;
text-transform: uppercase;
line-height: 42px;
color: #fff;
font-weight: bold;
}
.overlap-section h3 {
text-transform: uppercase;
font-weight: bold;
font-size: 30px;
padding-bottom: 25px;
}
.overlap-section label {
font-size: 25px;
display: block;
}
.overlap-section span {
font-size: 16px;
padding: 18px 0;
display: block;
}
.button-wrapper {
margin: 0 auto;
display: table;
padding-top: 52px;
}
.button-wrapper .custom-btn {
color: #fff;
background-color: #ff5722;
padding: 14px 35px;
border: 0;
font-size: 19px;
}
<div class="main-section">
<div class="overlap-section">
<h3>Header text is here</h3>
<label>More header text here</label>
<span>List item</span>
<div class="button-wrapper">
<button class="btn-default custom-btn" type="button">Call to action here</button>
</div>
</div>
<div class="main-box">
<div class="text-wrapper">
<h2>This Grey Element</h2><br>
<h2>Will contain an image</h2>
</div>
</div>
</div>

How can I keep a button centered on the page and responsive?

I am trying to make it so that the button that I have centered on the screen (when the screen is full size, it is centered) stays in the center while still scaling down to fit to smaller screens.
I have tried some of the answers I found here and other places about changing position: absolute; and wrapping the button in a div with text-align: center; and margin: auto; but so far the button ends up not staying centered.
Here is what I have:
.wrapper {
text-align: center;
margin: auto;
}
#mybutton {
position: absolute;
left: 37%;
text-align: center;
cursor: pointer;
bottom: 10%;
letter-spacing: .55rem;
max-width: 50%;
background: #3498db;
background-image: linear-gradient(to bottom, #3498db, #2980b9);
text-shadow: 1px 1px 3px #666666;
font-family: Arial;
color: #ffffff;
font-size: 30px;
padding: 10px 20px 10px 20px;
text-decoration: none;
border-color: #3498db;
-webkit-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}
This is probably something very simple that I am missing, but it's late and I am tired of messing around with this, so if anyone can offer any help, it would be appreciated!
Make it simple. You just need text-align:center with width.
CSS i have used
width:50%;margin:0 auto;text-align:center;
see here
try this , it is working .
.button1 {
text-align: center;
}
.button1 a {
background-color: #03326c;
font-size: 25px;
height: 35px;
position: relative;
text-align: center;
display: inline-block;
color: white;
padding: .5em 1em;
}
<div class="button1">
<span class="Button1">BUTTON</span>
or you can put button also.
</div>
This is what I understood of your problem: you wanted to make a button that scaled in accordance with the screen size AND you wanted it to be be centered.
I've pretty much done what you've been trying to do and achieved this.
.wrapper{
text-align: center;
}
button{
width: 50%;
...
}
Assigned the text align center property to the button's parent div and assigned the button a relative width.
body {
position: relative;
}
button {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
<body>
<button>CLICK ME</button>
</body>
see my pen for further explanation on how I used transform property of css

How to put text inside border html

#border {
position: static;
z-index: 1;
width: 120px;
height: 120px;
margin-left: 92% ;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
margin-left: 93%;
z-index: 2;
color: white;
font-weight: bold;
}
<div id="border"></div>
<div id="text">Users online</div>
I can't post the image here, cuz I have less than 10 reputation, so try to imagine it please. I want to place it's "Users online" inside the border, how should I do this? Thanks.
I'm assuming you are trying to have an element with a semitransparent background.
Since you are using the opacity property on the element with an id of border.
The problem here is that z-index will not have any effect, if the position is set to static, which is the default value for div elements.
The other thing is, that you should be using a relative positioned parent to make your life easier and have more control over the elements since positioned elements will leave the normal document flow and result in new stacking order.
Here you can find good information on the the z-index property, stacking and the document flow.
This is one solution to your problem.
body {
background:black;
}
.holder {
position:relative;
}
#border {
position: absolute;
z-index:1;
right:0;
width: 120px;
height: 120px;
padding: 15px;
border-radius: 11px;
background: white;
opacity: 0.2;
}
#text {
position: absolute;
z-index:2;
right:0;
width: 120px;
height: 120px;
padding: 15px;
text-align: center;
color: white;
font-weight: bold;
}
<div class="holder">
<div id="border"></div>
<div id="text">Users online</div>
</div>
But i would actually try to solve this with a different approach, because i find the above solution a bit to complex and it involves to much positioning, so if all you need is a semitransparent background just make use of the background property with an rgba value. Here is an example.
.user-panel {
float:right;
height: 120px;
width: 120px;
padding: 15px;
border-radius: 11px;
/* fallback for browser that do not support rgba */
background: #ccc;
/* semitransparent background */
background: rgba(0, 0, 0, .2);
text-align: center;
color: white;
}
/* clear the float using the pseudo after element */
user-panel:after {
clear: both;
display: block;
visibility: hidden;
height: 0px;
}
<header>
<div class="user-panel">Users online</div>
</header>
Hope that helps.
Change
position: static;
to
position: absolute;
for #border. That way, border will be "removed from the flow" (i.e. other elements will ignore it). You may need to adjust the margin-left property for #text so it properly aligns.
Fiddle: https://jsfiddle.net/xzdmLt33/1/

Different behavior with display:table/table-cell across browsers

I using Twitter's Bootstrap and this color picker: http://bootstrapformhelpers.com/colorpicker/.
And I'm having an issue with these div/span/input created by library.
It uses bootstrap classes the apply display: table to div, display: table-cell to span and display: inline-block to input.
I've overwritten some CSS attributes to get my expected layout, testing it in Chrome.
However, it does not work as expected in IE9 and Firefox. Works as expected in Chrome, Opera, IE10 (and IE9#IE10).
I've reproduced it in jsFiddle, here is the important code:
HTML:
<div>
<span class="btn">
<span></span>
</span>
<input type="text" />
</div>
CSS:
body {
line-height: 20px;
}
div {
display: table;
position: relative;
width: 140px;
}
span.btn {
background: #ccc;
display: table-cell;
padding: 6px 12px;
position: relative;
left: 90px;
}
span.btn > span {
background: #333;
display: block;
height: 16px;
width: 16px;
}
input {
border: 1px solid #ccc;
display: inline-block;
height: 20px;
margin-left: -42px;
padding: 6px 12px;
width: 100%;
}
Why this is exactly happening? Every browser interpreting display: table/table-cell differently?
What is the cross-browser solution?
Because Firefox doesn't support position: relative; on table cells...
Bug Report
The issue is that you are actually having some really weird markup and CSS positioning, you should consider nesting an absolute positioned element under a relative positioned parent.
Demo
Demo 2 (With a center black box)
div {
position: relative;
width: 180px;
border: 1px solid #ddd;
margin: 20px;
height: 30px;
}
div input {
padding: 6px;
}
.btn {
position: absolute;
height: 30px;
width: 30px;
background: #aaa;
right: 0;
top: 0;
}

z-index not working as expected (Chrome and Opera)

I have a div with class "opaque" and another with class "product-info", which are both on the same level.
The code is as follows:
<div class="opaque"></div>
<div class="product-info">
<img class="product-image" src="/Images/D3.jpg" />
fsdfdsfsdfs
</div>
.opaque
{
background-color: White;
-moz-opacity:.60; filter:alpha(opacity=60); opacity:.60;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1;
}
.product-info
{
padding: 5px;
text-align: center;
z-index: 2;
}
Note that product-info is set to z-index 2 and opaque has z-index 1. Therefore product-info should be displayed over opaque so should not be faded. However the image within product-info (and text) is faded. This happens in both Chrome and Opera, therefore I expect this is what should be happening since they are not IE!
There are lots of bits of HTML code as shown above, each nested in lis which are set to float left with width of 33%. When the page is fully loaded ($(window).load()) I use jQuery to detect the maximum height of all the products and apply that height to all the rest. I have tried removing all the jQuery in case this is affecting the z-index, but I get the same result only with an untidy look and feel.
I have tried using Google Chromes Inspect Element tool and the elements in question are showing the correct characteristics.
Can anyone see what I am doing wrong here? I have been trying to solve this for a couple of days now and would like to find out what is going on.
Thank you.
Regards,
Richard
Full code as requested:
I think this is all that is required. I will create a page with just this code in a few minutes, to see if it reproduces the problem.
<div id="BodyTag_ContentPanel">
<div class="overlay-background"></div>
<div class="scroll-pane">
<div>
<ul class="product-list">
<li class="product">
<div class="spacer">
<div class="opaque"></div>
<div class="product-info">
<img class="product-image" src="/Images/D3.jpg" />
<div class="enlarge">
<div class="image-enlargement">
<span class="close"><img src="/Images/close.jpg" /></span>
<div class="enlargement">
<div class="image-container"><img src="/Images/D3.jpg" /></div>
<div class="product-code"><span class="text-container">D3</span></div>
</div>
</div>
</div>
</div>
<div class="product-code">D3</div>
<div class="clear"></div>
</div>
</li>
</ul>
</div>
</div>
</body>
.product-list
{
list-style: none;
padding: 0;
width: 100%;
}
.product
{
width: 33%;
height: 25%;
float: left;
position: relative;
}
.product .spacer
{
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
margin: 10px;
padding: 5px;
border: 4px solid #C47F50;
position: relative;
}
.product .opaque
{
background-color: White;
-moz-opacity:.60; filter:alpha(opacity=60); opacity:.60;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
z-index: 1;
}
.product .product-info
{
padding: 5px;
text-align: center;
z-index: 2;
}
.product .product-info .product-image
{
max-width: 200px;
max-height: 200px;
min-width: 150px;
min-height: 150px;
z-index: 2;
}
.product .product-code
{
position: absolute;
bottom: -15px;
width: 50%;
margin-left: auto;
margin-right: auto;
background-color: White;
text-align: center;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 4px solid #C47F50;
line-height: 20px;
z-index: 2;
}
.product .image-enlargement
{
position: fixed;
display: none;
padding: 5px;
background-color: White;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border: 4px solid #C47F50;
z-index: 103;
}
.product .enlarge
{
float: right;
}
I have found the solution!! I simply added position: relative; to .product-info. I can't believe I was so stupid as to not try that in the first place! Thanks for both your efforts #Thomas & Lazycommit. #Lazycommit your link came in handy - it confirmed that my code should have been working if it weren't for missing out the position: relative;. I noticed that they had set the position attribute for all of the divs in the example - this is what made me try it.
This is a big theme. U may look this page from Firefox developers for better understanding browsers stacking.
Try setting the z-index of the item that is supposed to be in the back to a negative number, like -1 :)
I know this is old, but you can use rgba() instead of opacity and get rid of the "product-info" div. This does the same effect you want since rgba() uses a different method of causing transparency that does not make the children elements go transparent as well. Makes doing the effect you wanted much easier.
if there is outer div to set position: fixed; and you need position: fixed; there add z-index same as inner div.
ex:
.notifications {
position: fixed;
width: auto;
max-width: 70%;
z-index: 9999;
}
.notifications > div {
position: relative;
z-index: 9999;
/* margin: 5px 0px;*/ /*default value*/
margin: 65px 10px;
display: inline-block;
}
will work fine.
But if notifications class like below it does not set z-index in chrome correctly.
.notifications {
width: auto;
max-width: 70%;
z-index: 9999;
}