Basically what I want to do, considering the example below, is to create a fluid and dynamic background width depending on the text size with more than one line. This because I have set a justified text alignment and at some point (e.g. in the second line) the text doesn't fill up all the width of the background, which is enlarged by the upper sentence which is bigger. I don't want the background to fill it up! I don't know if I'm making myself clear, but I'll try to explain with the example below.
http://jsfiddle.net/gcAhL/
HTML
<div class="image">
<img src="http://s23.postimg.org/g033nno17/image.jpg">
<div class="title">This is a title</div>
</div>
<div class="image">
<img src="http://s23.postimg.org/g033nno17/image.jpg">
<div class="title">This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title</div>
</div>
CSS
.image {
position: relative;
width: 800px;
height: 530px;
margin: 10px;
}
.title {
position: absolute;
background-color: #CCC;
text-align: justify;
max-width: 600px;
bottom: 30px;
padding: 5px;
}
As you can see, the last blue square has text that breaks into two lines. The greyish background fills up the width basing itself on the first line. What I want to happen is that in the second line, the grey fills the text of that line only.
Example: http://s9.postimg.org/634pzc9y7/example.jpg
Is this even possible? Thanks in advance for all the responses.
Just use <span> element inside of your <div> and give background-color to <span> element instead of <div>.
HTML
<div class="image">
<img src="http://s23.postimg.org/g033nno17/image.jpg">
<div class="title"><span>This is a title</span></div>
</div>
<div class="image">
<img src="http://s23.postimg.org/g033nno17/image.jpg">
<div class="title"><span>This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title This is a title</span></div>
</div>
CSS
.image {
position: relative;
width: 800px;
height: 530px;
margin: 10px;
}
span{background-color: #CCC;}
.title {
position: absolute;
line-height:100%;
text-align: justify;
max-width: 600px;
bottom: 30px;
padding: 5px;
}
Related
We have outer div header which has 100% width of its container. The div is for heading text and button on right. The text have to be centered to the header and the button has to be on right. But if the text is long enough to overlap with button, then the text should fill left part of header and do not go on button.
header -> [ [CENTER TEXT] [button]]
OR (with wider CENTER TEXT)
header -> [[abcdabcdab CENTER TEXT cd][button]]
Tried with position: relative on header->text and position: absolute; left: 100%; on button when placing it as a child of center text. But this isn't exactly what is should look like. Any good way to do it with pure CSS?
Button should be placed with little margin to right border of header, rather not with margin to center text.
You can use this simple trick:
Use a span positioned inline after the text itself. Once the text is longer than the size of the header, the span drops a to the next line and the text can take all the space.
Notice that you need to set a fixed width to the button.
div.container {
border: 1px solid red;
height: 50px;
width: 100%;
position: relative;
}
h1 {
background: gray;
width: calc(100% - 100px);
float: left;
height: 50px;
line-height: 50px;
text-align: center;
margin: 0;
direction: rtl;
}
h1 span.text {
color: black;
background: lightyellow;
direction: ltr;
}
h1 span.padding-holder {
width: 100px;
display: inline-block;
position: relative;
}
button {
float: right;
width: 100px;
height: 50px;
}
<div class="container">
<h1>
<span class="text">Short Header</span>
<span class="padding-holder"></span>
</h1>
<button>Click Me</button>
</div>
<div class="container">
<h1>
<span class="text">Now a Medium Header</span>
<span class="padding-holder"></span>
</h1>
<button>Click Me</button>
</div>
<div class="container">
<h1>
<span class="text">And This is a Very Long Header</span>
<span class="padding-holder"></span>
</h1>
<button>Click Me</button>
</div>
I currently have some text that is left aligned but centered as follows:
<div class="center-text">There is some text here</div>
<div class="center-text">There is also some other text here</div>
<div class="center-text">Finally there is some text here</div>
.center-text {
width: 50%;
margin: auto;
}
How can I float an image to the left of the text that is in the bottom right corner? What I'm looking for is the following:
The black frame is the surrounding div, the red is the image and the text is as described above. My text is currently behaving as expected but I can't seem to add the image without impacting the text.
I made it a little bit different:
.container{
height: 300px;
position:relative;
border: 30px solid black;
}
.center-text {
width: 100%;
}
p {
margin: 0;
}
img{
position: absolute;
bottom: 0;
left: 0;
width:30%;
}
.text{
float: right;
width: 65%;
margin-top: 100px;
}
<div class="container">
<div class="center-text">
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRLwIM4lLwdmXvvYio988Z70kxTBtoNudITd9_72iGRjlusoVey" />
<div class="text">
<p>There is some text here</p>
<p>There is also some other text here</p>
<p>Finally there is some text here</p>
<p>Finally there is some text here</p>
<p>Finally there is some text here</p>
</div>
</div>
</div>
I hope it also helps you :)
Currently I can not find a solution that is responsive and scrollable to put text on an image. I need the height to be flexible and the width at 100%. I tried to use position:relative; and css background images with no luck. When I use position: relative; there is a space at the top of the image and the only way to delete it is negative margins which I think is not sustainable it there are multiple posts. css backgrounds does not show the full image unless you set dimensions and when is responsive you cant set dimensions. I dont think I can use position absolute because it would not scroll. so I dont not know what to use.
I have this HTML code here:
<div class="post">
<span><a>Posted By Adam</a></span>
<img width="100%" src="uimg/adam-levine-600.jpg">
</div>
Use position: absolute; and add a spacer for the nav:
http://jsfiddle.net/ryanpcmcquen/p3bes5xq/
.nav {
height: 100px;
width: 100%;
position: fixed;
background-color: #21A7F0;
text-align: center;
z-index: 10;
color: #ffffff;
}
.spacer {
height: 105px;
}
.post span {
position: absolute;
color: #ffffff;
text-shadow: 1px 1px 2px #000000;
}
.post img {
width: 100%;
}
<div class="nav">nav bar</div>
<div class="spacer"></div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/450" />
</div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/260" />
</div>
<div class="post"> <span><a>Posted By Adam</a></span>
<img src="//fillmurray.com/880/194" />
</div>
So I'm trying to make a user comment thing in HTML. I would like it to look similar to vimeo's comments, with the user icon and the text aligned to the right of it. Here is my markup(using a bootstrap container but i dont really think that is the problem):
<div class="comment">
<img src="{{comment.poster.profile.avatar.url}}" alt="...">
<span>poster name time</span>
<p>comment body</p>
</div>
and my CSS:
.comment{
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
text-align: left;
width: 800px;
padding: 10px;
background-color: #secondary;
img{
width: 55px;
height: 55px;
vertical-align: top;
}
The <span>poster name time</span> aligns with the top right of the image just how I want it to, but the body text ends up under the image, not under the info like where I want it to be. Here is an image of it, arrow is pointing where I want the text to go:
Any idea how I should do this? I'm real bad at aligning things, so sorry if this is a simple mistake. Thanks.
Here is how you canc achieve this:
<div class="pic">
<img src="http://placekitten.com/100/100">
</div>
<div class="pic-meta">
<span>
poster name
time
</span>
<span class="comment">comment</span>
</div>
and css:
.pic, .pic-meta {
float: left;
}
.comment {
display: block;
}
http://jsfiddle.net/p4K7u/
This is a CSS question that's driving me up the wall. Below is the code I currently have, and I want the description text to be to the right of the blue box (i.e. under the title), but for it to continue over, under the 'button'. I've tried various combinations, but they all either start at the current position or underneath the title but indented by its width.
Any help greatly appreciated
<html>
<head>
<style>
body { background-color: #fff; color: white; }
.outer { width: 850px; height: 400px; background-color: #000; }
.logo {float: left; width:150px;height:150px;background-color: #00f;}
.button {float: right; height: 60px; width: 80px; background-color: #f00; }
.title { font-size: 60px; float:left;}
.desc {clear:both;}
</style>
</head>
<body>
<div class="outer">
<div class="head">
<div class="logo">oo</div>
<div>
<div class="title">Title</div>
<div class="button">button</div>
<div class="desc">description text description text description text description text description text description text description text description text description text description text description text description text</div>
</div>
</div>
</div>
</body>
</html>
The text should be where the white box is in the image above.
Now that should be very simple eh? Just float it to the left and give it a width...
Demo
CSS
.desc {
float: left;
width: 650px;
padding: 10px;
}