Change layout of page using css only (without changing DOM placement) - html

I have a structure which cannot be changed due to some reasons.Here is the structure:
<h1>heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consecadipiem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet]consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sitg elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. Se</p>
<div style="width: 200px; height: 200px; background: #f1f1f1">container</div>
I want to get this particular layout using CSS only, ie. no positions, negative margins etc. The HTML elements will remain in same flow - h1, p and div. Is it possible to do this?

This should work for you. The main thing is to put float: left on the left hand div.
<style type="text/css">
#wrapper {
width: 90%;
}
#container {
float: left;
width: 200px;
height: 150px;
background-color: #666;
margin: 0 10px 10px 0;
}
H1 {
font: bold 2em arial;
}
P {
background-color: #ccc;
}
</style>
<div id="wrapper">
<div id="container">#container</div>
<h1>Heading</h1>
<p>
Some text.
</p>
</div>
Example fiddle

Of course you can do that in CSS only! :)
I know this is an old question, but its a fun challenge. The trick is to create a pseudo element before the h1 that floats left to create the space for the container div.
I'm sure there are many other ways to do this...
div {
position:absolute;
top:0;
}
h1::before {
content:'';
float:left;
width:200px;
height:200px;
margin-left:20px;
}
<h1>heading</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consecadipiem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet]consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sitg elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. SeLorem ipsum dolor sit amet, consectetur adipiscing elit. Se</p>
<div style="width:200px; height:200px; background:#f1f1f1">container</div>

Related

Scrollable child and parent unscrollable

Lets say there is something like this:
<div class="parent">
<div class="child">
</div>
</div>
How to make parent to occupy the entire screen height?
And how to make child to be scrollable, if its height exceeds the parent height(which is screen max height).
I tried something like this:
.parent{
height: 100vh;
}
.child{
overflow: auto;
}
Apply overflow rule to the parent div, see working example below:
html, body {
height: 100%;
margin: 0;
font-family: sans-serif;
}
.parent {
overflow: auto;
height: 100vh;
padding: 10px;
border: 1px solid #ccc;
}
.child span {
height: 100vh;
display: block;
background: gray;
padding: 10px
}
.child span:nth-child(odd) {
background: lightgray
}
<div class="parent">
<div class="child">
<span>Child container 1</span>
<span>Child container 2</span>
<span>Child container 3</span>
</div>
</div>
Instead of your CSS, try to apply this CSS:
html, body{
overflow:hidden;
}
.parent{
height: 100vh;
overflow: scroll;
}
Here is the link to the fiddle supporting it.
html,
body {
overflow: hidden;
}
.parent {
height: 100vh;
overflow: scroll;
}
<div class="parent">
<div class="child">
"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit
amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing elit"Lorem ipsum dolor sit amet, consectetur adipisicing
elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum
dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet,
consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing
elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum
dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet,
consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing
elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit" "Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum
dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit""Lorem ipsum dolor sit amet, consectetur adipisicing elit"
</div>
</div>

Outlook signature html

I am trying to make signature in html for my Outlook mail.
The problem is that everything looks great in browser but in outlook is too wide.
This should look like in the browser.
Source code:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<div id="sig" style="min-width: 680px; min-height: 82px; line-height: 18px; padding: 24px 0 0 30px; font-family: Helvetica, Verdana, Arial, Sans-Serif; font-size: 12px; color: #999999;">
<img src="logo.jpg" alt="logo" style="float: left; border: none;" />
</a>
<div style="margin-left: 40px; padding-left: 20px;">
<span style="display: block; font-size:13px; color: #404040; margin-bottom: 3px;">Name Surnamek </span>
<span style="display: block; font-size:10px; color: #404040; margin-bottom: 3px;">TT Test </span>
</div>
<div style="padding-left: 0px;">
</br>
<strong><a title="TEST" style="color: #404040; text-decoration: none;">Company Name</a></strong>
<br /> tel. &nbsp+00 (0) 00 – 000 00 00 </br>fax. +00 (0) 00 – 000 00 00</br>
</br>
Lorem ipsum dolor sit amet</br>
Lorem ipsum dolor sit amet, </br>
Lorem ipsum dolor sit amet</br>
Lorem ipsum dolor sit amet</br>
Lorem ipsum dolor sit amet</br>
Lorem ipsum dolor sit amet</br>
</br>
</div>
<hr style="width: 680px; float: left;"></hr>
</br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>
</br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit.</br>
</br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit </br>Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit.</br>
</div>
</div>
<div style="clear:both"> </div>
</body>
</html>

Make td expand to max width before text wraps

I feel like there's a simple way to do this, but I just can't think of/find a solution...
I have a <table> that that should scroll-x if it overflows (which it's expected to) The <td> elements are set to max-width: 300px. I want the text in the <td> to wrap ONLY AFTER the <td> has hit the max-width. Right now text is wrapping as soon as the <table> doesn't fit its parent <div>.
How can I make the <td> expand to its max width before the text wraps?
Here's a fiddle: https://jsfiddle.net/ds99unpz/2/
EDIT: to clarify...
If the td doesn't have to be 300px wide to fit the text on one line, I don't want it to be 300px. If the text is too long to fit in a 300px td, THEN I want the td to be 300px wide and the text to wrap.
I updated your JSFiddle. It coerces the tables and cells to act like block's and inline-block's, respectively. Then using a little white-space: nowrap; magic and forcing the table to overflow, we get the desired result. However, the cells aren't all the same height.
.scrollable {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
table{
height: 150px;
}
td {
max-width: 200px;
white-space:nowrap;
overflow-x: scroll;
}
<table class="table table-striped">
<tr>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
</tr>
</table>
EDIT:,
Added style="white-space: nowrap" to <td>
HTML:
<table class="table table-striped">
<tr>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
</tr>
</table>
CSS:
.scrollable {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
table{
height: 150px;
}
td {
max-width: 200px;
white-space:nowrap;
overflow-x: scroll;
}
Fiddle
Or all css
<table class="table table-striped">
<tr>
<td style="white-space: nowrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td></tr>
<tr>
<td>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
<td >Lorem ipsum dolor sit amet, consectetur adipiscing elit.</td>
</tr>
</table>
CSS:
.scrollable {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
table{
height: 150px;
}
td {
max-width: 200px;
white-space:nowrap;
overflow-x: scroll;
}
Fiddle

White space tabs in bootstrap

I am trying to achieve a layout similar to the attached image. It looks fine and as how I want it when displayed in a browser, but when I test on a mobile/tablet device the spacing of the p tags ends up not correctly displayed- I assume this is due to me using hard coded widths in my span tags and the p tags taking up more than one line.
Is it possible to achieve the attached image layout in a responsive manner? If so how do I go about doing this?
I have tried using % and EM in place of px with similar results.
The HTML that I have written so far is:
<h2>Lorem Ipsum </h2>
<p>
<span style="display:inline-block; width: 50px;"></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.
</p>
<p>
<span style="display:inline-block; width: 100px;"></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.
</p>
</br>
<h4>
<span style="display:inline-block; width: 200px;"></span>
or
</h4>
</br>
<p>
<span style="display:inline-block; width: 50px;"></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat
</p>
<p>
<span style="display:inline-block; width: 100px;"></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.
</p>
</br>
<h2>
<span style="display:inline-block; width: 550px;"></span>
Lorem Ipsum
</h2>
<p>
<span style="display:inline-block; width: 600px;"></span>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. ipsum dolor sit amet, consectetur adipiscing elit. Curabitur
</p>
<p>
<span style="display:inline-block; width: 663px;"></span>
Lorem Ipsum
</p>
<p>
<span style="display:inline-block; width: 650px;"></span>
Lorem ipsum dolor sit amet
</p>
First of all, you better walk this way to achieve something similar to what you want:
.indent-1 {
margin-left: 2.5%;
}
.indent-2 {
margin-left: 5%;
}
.indent-3 {
margin-left: 7.5%;
}
.indent-4 {
margin-left: 10%;
}
.indent-5 {
margin-left: 12.5%;
}
.indent-6 {
margin-left: 15%;
}
.indent-7 {
margin-left: 17.5%;
}
.indent-8 {
margin-left: 20%;
}
.indent-9 {
margin-left: 22.5%;
}
<h2>Lorem Ipsum </h2>
<p class="indent-1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.</p>
<p class="indent-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.</p>
<h4 class="indent-3">or</h4>
<p class="indent-4">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat</p>
<p class="indent-5">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ullamcorper volutpat.</p>
<h2 class="indent-6">Lorem Ipsum</h2>
<p class="indent-7">Lorem ipsum dolor sit amet, consectetur adipiscing elit. ipsum dolor sit amet, consectetur adipiscing elit. Curabitur</p>
<p class="indent-8">Lorem Ipsum</p>
<p class="indent-9">Lorem ipsum dolor sit amet</p>
CodePen using LESS: http://codepen.io/anon/pen/MweYma
JSFiddle using CSS: https://jsfiddle.net/c80p3pyx/1/
If you need to make sure your paragraphs do not wrap, just add
p { white-space: nowrap; }
to your CSS. This way your paragraphs will always stay in one line, but lines that do not fit the screen width will cause the browser to show (or make available at least) a horizontal scrollbar, which in almost all cases you will want to avoid. The only other option on "too-long" paragraphs is to either shorten the text, or to use a smaller font.

preg_replace add class to anchor tags ONLY between h1 tags

I need to add a custom class to every anchor tag found within h1 tags, leaving all other anchor tags untouched.
At the moment I have:
$content = preg_replace("/(<h1.*?<a.*?)/i","$1 class=\"mystyle\"",$content);
The problem with the above is that it only adds my class to the first anchor found in any h1 header and I'm really struggling to figure out how to correct this.
To clarify,
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
Becomes,
<h1><a class="mystyle" href="page.html">Lorem</a> ipsum dolor sit amet, consectetur adipiscing elit.</h1>
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<h1><a class="mystyle" href="page.html">Lorem</a> ipsum dolor sit amet, consectetur adipiscing elit.</h1>
Bit of a regex beginner so apologies if this is a really stupid question,
I have searched for hours and hours trying to get this on my own so I hope someone can help!
Cheers
Done with the help of $xpath->query('//h1//a');