Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide an element off the edge of the screen?

Tags:

html

css

I've got a div that I want to position partially off-screen like so:

div{     position: absolute;     height: 100px;     width: 100px;     right: -50px;     top: 50px; } 

But this increases the size of the page, allowing it to be scrolled to the right. Is there any way to keep half of this div hidden and prevent scrolling to view it?

like image 239
lavelle Avatar asked Jul 19 '11 11:07

lavelle


People also ask

How do I hide the elements on my small screen?

To hide an element in a responsive layout, we need to use the CSS display property set to its "none" value along with the @media rule. The content of the second <p> element having a "hidden-mobile" class will be hidden on devices smaller than 767px.

How do you hide an element?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden. display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.

How do you hide an element in web page?

CSS Display Property. Each element has a default display value like inline-block , block , table ..etc. To hide an element with the display property, we should use display: none . When an element is hidden with display: none , all of its descendants will be removed along with it.

How do you show and hide an element?

Style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery. To hide an element, set the style display property to “none”. document. getElementById("element").


2 Answers

Yes, just create an enclosing div with overflow: hidden, like this:

.outer {    overflow: hidden;    position: relative;  }  .inner {    position: absolute;    height: 100px;    width: 100px;    right: -50px;    top: 50px;  }
<div class="outer">    <div class="inner">      CONTENT    </div>  </div>

Example: http://jsfiddle.net/Uj3eQ/

like image 72
jackJoe Avatar answered Oct 01 '22 14:10

jackJoe


Just add overflow:hidden to the css. That should do the trick.

like image 44
Aaditi Sharma Avatar answered Oct 01 '22 14:10

Aaditi Sharma