CSS Issue in wrapping contenteditable div around Floating image - html

I have a problem in floating a contenteditable div around a image. Here's my code:
HTML:
Section title
CSS:
.fl {
float: left;
}
.rgtDiv {
min-height: 300px;
border: solid 1px #ccc;
}
I want the rgtDiv to have left border at the right end of the image but right now it appears at the left end of the image.
When I click on the rgtDiv the cursor goes to the image and not inside the rgtDiv. How to make the cursor come inside the rgtDiv?
Also the border of the rgtDiv applies to the entire parent Div. How to make it to apply only for the rgtDiv.
Can anyone help resolving my problem?
Here's my jsfiddle link: http://jsfiddle.net/n8WJ2/
Thanks in advance!
yadav

try giving the rgtDiv a float: left; and a width ...
should work and don´t forget to clear your floats

You can add this:
.rgtDiv {
position: relative;
overflow:hidden;
min-height: 300px;
border: solid 1px #ccc;
}
Demo
It will resize depending of the width of the image.

Try this
HTML
<div>
<div class="section-title">Section title</div>
<div class="rgtDiv">
<img src="http://www.destination360.com/north-america/us/montana/images/s/great-falls.jpg" height="300" width="300"/>
<div contenteditable="true" class="editableblock"></div>
</div>
CSS
.fl, .rgtDiv img {
float: left;
}
.rgtDiv {
border: solid 1px #ccc;
display:block;
}
.editableblock {
min-height: 300px;
}

If anyone still cares.
To workaround the issue with caret position, you can add zero-width space to the div in HTML:
<div contenteditable="true" class="rgtDiv">​</div>
and restore it every time user clears it:
$('.rgtDiv').keyup(function(){
if($(this).text().length == 0){
$(this).text('\u200B');
}
});
Demo

overflow: hidden can be used for the contenteditable block :empty pseudo-class.
Please note that it has to be really empty: no spaces or tabs inside, just <div contenteditable="true"></div>

Related

How to put DIVs in one line without changing their width?

There are much answers answers uning float or overflow: hidden or display: inline-block, but they are not appliable for my problem, because of they all affect div width. So, please, avoid this answers and duplicate-marks.
here is my current page:
.scrollableWrapper {
overflow: auto;/*so if any of width changes apply, this won't work*/
}
.left {
width: 30%;
float: left;
}
.right {
width: 70%;
float: right;
}
.all {
border: 2px solid black;/*for visibility while developing*/
width: 80%;
overflow: hidden;
}
<div class="all">
<div class="left">
название
</div>
<div class="right">
<div class="scrollableWrapper"><label>tezrnjetgnd;sngnsdlgnknsgfndlsngfklsngdngndksngnsngflsdgnklsnkgklsgnkldsngkndklsngklsdgnlsglksdngksnglnsldkgnksndgknsdklgsngnsdlgnknsgfndlsngfklsngdngndksngnsngflsdgnklsnkgklsgnkldsngkndklsngklsdgnlsglksdngksnglnsldkgnksndgknsdklgsngnsdlgnknsgfndlsngfklsngdngndksngnsngflsdgnklsnkgklsgnkldsngkndklsngklsdgnlsglksdngksnglnsldkgnksndgknsdklgsngnsdlgnknsgfndlsngfklsngdngndksngnsngflsdgnklsnkgklsgnkldsngkndklsngklsdgnlsglksdngksnglnsldkgnksndgknsdklg</label></div>
<div>
edit
</div>
</div>
</div>
And i need the edit text to be right afres scrollable, on the same line. Margin doesn't work.
P.S. I prefer to do it without recalculating width using jquery, but I know that it is possible (edit div has constant widht)
check if this working fiddel will help you
in your case : https://jsfiddle.net/24ks85ue/1/
just change the div location and add float left for edit div class

only top-border is showing not complete border around container

Border is not displayed properly.Side and bottom ones
are missing.
here shorthand property is acting like top-border
property.
If we apply height tag to container than container than
borders are displayed correctly but it should work on its own.
CSS
.container
{
border:1px solid black;
}
.container DIV
{
width: 15px;
border: 1px solid Blue;
margin: 1px;
}
HTML
<div style="width: 200px; " class="container">
<div style="float: left;">1</div>
<div style="float: left;">2</div>
<div style="float: left;">3</div>
<div style="float: left;">4</div>
<div style="float: right;">5</div>
<div style="float: right;">6</div>
<div style="float: right;">7</div>
<div style="float: right;">8</div>
</div>
You need to provide more code (including the html that shows the actual container element). However, my guess from what you have said is that adding overflow:hidden to your style should fix it.
.container
{border:1px solid black;
margin:auto;
margin-top:33px;
overflow:hidden;
}
If elements within your container are floating, then the container acts like it has a height of 0. This would cause a border to be a single line at the top. Overflow:hidden gives it the height including any floating elements (see http://www.w3.org/TR/CSS21/visudet.html#root-height )
As I say, more code would be required to say if that is what the issue is in your case but it is a common cause of that style problem.
Update your container class like below.
.container
{
border:1px solid black;
display:table;
}
Fiddle DEMO
As you are using float property on child elements. to fix it just use overflow:hidden on parent element i.e. in your case use add overflow on class .container.
Here is a DEMO.
.container
{
border:1px solid black;
overflow:hidden;/* Added Line*/
}

Box getting shifted from its place

I have some boxes in HTML but one of the boxes is getting shifted from its place. Here is JsBin Demo
HTML
<div id="summary">
<div class="box"><span>Average fill time</span></div>
<div class="box"><span>Listing</span></div>
<div class="box"><span>Archive</span></div>
<div class="box"><span>Views</span></div>
<div class="box"><span>Submissions</span></div>
</div>
CSS
.box {
height: 60px;
width: 80px;
display: inline-block;
text-align: center;
padding: 20px;
border: 1px solid;
margin: 10px;
}
Screenshot
PS: I know this is happening due to three words in the box. Setting overflow-y: hidden fix this problem. But I want to know why is this happening at first place ?
Example code : http://jsbin.com/elOdOpa/1/edit
Add vertical-align: top to your .box elements (since vertical alignment is baseline by default and the current alignment is shown as in the picture below
You could change display:inline-block; to float:left;.
JSBin

content hidden but not breaking line

I would like to create a div container with fixed width and height of 100px and it should work like a window.
Then in addition
It should have content divs into it next to each other 'floating' left, not breaking into a new line.
The container should hide all what is longer as it width or height.
Do I have to use
overflow:hidden
?
fiddle here:
container and content
http://jsfiddle.net/hd8Bm/1/
Here is a sample HTML structure:
<div id="container">
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
<div class="content"></div>
</div>
Here is what the CSS needs to be like:
#container
{
width: 100px;
height: 100px;
padding: 5px;
border: 1px solid #000;
overflow: auto;
white-space: nowrap;
}
.content
{
width: 50px;
height: 50px;
display: inline-block;
border: 1px dashed #000;
}
Here is a working fiddle:
http://jsfiddle.net/HB8kB/
The trick is done by white-space: nowrap;
This is what you want.
http://jsfiddle.net/hd8Bm/9/
display:inline was not necessary.
OK, if you want to hide something, or prevent it from being clicked, position:absolute may work, on newer browsers, I mean. float:left is sometimes helpful, too.

centering an image inside an anchor

I am trying to horizontally center an image that is contained within an anchor tag. I have tried setting it as a block and setting margins to auto with no luck. I have tried wrapping it in a div tag and doing the same, still, no luck. Even tried centering the img within the div within the div. I looked at other posts, and nothing seems to help. The image is still aligned to the left no matter what I do.
###HTML
<div id="slideWrapper">
<h1 id="slideHeading">This is a Header</h1>
<hr/>
<div class="centerMe">
<a href="javascript:slidelink()" class="slideA">
<img src="./images/Slides/cheeseBoards.jpg" name="slide" id="slideImg"/>
</a>
</div>
<hr/>
<div class="centerMe">
Check out our services and other great stuff.
</div>
</div>
###CSS
.centerMe {
margin-left: auto;
margin-right: auto;
border: 1px solid green;
text-align: center;
}
#slideWrapper {
border: 1px solid blue;
}
#slideImg {
display: block;
height:500px;
width:900px;
border:1px solid red;
margin-left: auto;
margin-right: auto;
}
I put borders around everything so that I could see where things were getting placed. It seems like the image isn't being contained within the div for some reason. This seems like it should be so simple. Any help would be greatly appreciated. Thanks.
Make sure there is no float:left inherited from parents. margin:0 auto; does not work when you have float:left; or position:absolute;