简体   繁体   English

跨度标记上的 CSS 变换元素(连同显示:内联块)正在强制换行

[英]CSS Transform element on span tag (along with display: inline-block) is forcing a line break

My Google font's italic face is really subtle so I'm trying to add additional slant using the CSS transform: skew element.我的 Google 字体的斜体非常微妙,所以我尝试使用 CSS transform: skew元素。 I have the text wrapped in a span, but in order to allow the transform property to work, I'm also using display: inline-block .我将文本包裹在一个跨度中,但为了让转换属性起作用,我还使用了display: inline-block However, when using this method within a list item, it forces half the list item down onto a new line.但是,当在列表项中使用此方法时,它会强制将列表项的一半放到新行上。 Does anyone know how to prevent this?有谁知道如何防止这种情况?

Screenshot of list item with forced line break:强制换行的列表项截图:

带有强制换行符的列表项的屏幕截图

 .slant { transform: skew(-8deg); display: inline-block; }
 <ul> <li>Ripley, John W. (Ed.).1975. <span class="slant">Those Dreadful Devil Wagons: Shawnee County's Automobile Owners, Dealers and Manufacturers</span>, 1902-1912 (Shawnee County Historical Society Bulletin No. 49).</li> <li>Boyd, John/Toronto Star [Photographer]. (1900). Cars; trucks and horse-drawn wagons competed for space at fruit and vegetable whole. [Photograph], Retrieved May 6, 2020, from: <a href="https://www.gettyimages.com/detail/news-photo/cars-trucks-and-horse-drawn-wagons-competed-for-space-at-news-photo/502831383" target="_blank">https://www.gettyimages.com/detail/news-photo/cars-trucks-and-horse-drawn-wagons-competed-for-space-at-news-photo/502831383</a></li> <li>Daily Herald [Photographer]. Hospital X-ray, 1932 [Photograph], Retrieved May 6, 2020, from: <a href="https://www.gettyimages.com/detail/news-photo/hospital-x-ray-1932-a-photograph-of-staff-taking-an-x-ray-news-photo/102730396" target="_blank">https://www.gettyimages.com/detail/news-photo/hospital-x-ray-1932-a-photograph-of-staff-taking-an-x-ray-news-photo/102730396</a></li> </ul>

One approach to achieve this effect is to use javascript to apply a <span class="slant"> to every individual character in your original <span class="slant"> (which, in the working example below, I have renamed <em class="title"> ).实现此效果的一种方法是使用 javascript 将<span class="slant">应用于原始<span class="slant"> "> 中的每个单独字符(在下面的工作示例中,我已将其重命名为<em class="title"> )。

This prevents your inline-block becoming so wide that the rest of the bibliography entry can only follow it by starting on a new line.这可以防止您的inline-block变得如此宽,以至于参考书目条目的 rest 只能通过从新行开始来跟随它。

Working Example:工作示例:

 // GRAB EACH BOOK TITLE IN THE BIBLIOGRAPHY const bookTitles = [... document.getElementsByClassName('title')]; // LOOP THROUGH THE BOOK TITLES for (bookTitle of bookTitles) { // GRAB THE TEXT OF THE BOOK TITLE let bookTitleText = bookTitle.textContent; // TEMPORARILY REPLACE THE SPACES bookTitleText = bookTitleText.replace(/\s/g, '+') // BUILD AN ARRAY OF CHARACTERS FROM THE BOOK TITLE let bookTitleTextArray = bookTitleText.split(''); // TRANSFORM EACH CHARACTER INTO A <span class="slant"> bookTitleHTML = '<span class="slant">' + bookTitleTextArray.join('</span><span class="slant">') + '</span>'; // REINTRODUCE THE SPACES bookTitleHTML = bookTitleHTML.replace(/<span class="slant">\+<\/span>/g, ' '); // INSERT THE NEW HTML INTO THE BOOK TITLE bookTitle.innerHTML = bookTitleHTML; }
 .slant { display: inline-block; transform: skew(-18deg); }
 <ul> <li>Ripley, John W. (Ed.).1975. <em class="title">Those Dreadful Devil Wagons: Shawnee County's Automobile Owners, Dealers and Manufacturers</em>, 1902-1912 (Shawnee County Historical Society Bulletin No. 49).</li> <li>Boyd, John/Toronto Star [Photographer]. (1900). Cars; trucks and horse-drawn wagons competed for space at fruit and vegetable whole. [Photograph], Retrieved May 6, 2020, from: <a href="https://www.gettyimages.com/detail/news-photo/cars-trucks-and-horse-drawn-wagons-competed-for-space-at-news-photo/502831383" target="_blank">https://www.gettyimages.com/detail/news-photo/cars-trucks-and-horse-drawn-wagons-competed-for-space-at-news-photo/502831383</a></li> <li>Daily Herald [Photographer]. Hospital X-ray, 1932 [Photograph], Retrieved May 6, 2020, from: <a href="https://www.gettyimages.com/detail/news-photo/hospital-x-ray-1932-a-photograph-of-staff-taking-an-x-ray-news-photo/102730396" target="_blank">https://www.gettyimages.com/detail/news-photo/hospital-x-ray-1932-a-photograph-of-staff-taking-an-x-ray-news-photo/102730396</a></li> </ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM