gpt4 book ai didi

html - 使用 SVG 形状创建响应式圆形标题

转载 作者:搜寻专家 更新时间:2023-10-31 08:23:48 26 4
gpt4 key购买 nike

我正在尝试制作一个半圆形/椭圆形的标题,该标题与其内部内容一起响应。现在它只在桌面上看起来不错,我真的不知道如何让它在移动设备上或窗口调整大小时看起来正确。

问题是缩小时圆圈的可见部分在顶部变得太细几乎消失,现在标题的内容留在形状之外,放大时(以及在移动设备/较小的屏幕上) ) 圆圈变得非常大,svg 中的图像不再填充标题形状。

感谢您的帮助。

理想情况下,标题应如下所示:

Ideally the header should look like this

在移动设备上而不是像这样

this

更像是这样的:

this

这是它的另一个问题,我通过缩小很多来夸大它:

another issue

这是一个 fiddle :https://jsfiddle.net/150dr2bb/27/

这里是重现此代码所需的所有代码:

HTML:

<header>
<div id="headercirclecont" style="text-align:center;">
<svg id="headerwhitecircle" preserverAspectRatio="none">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#7c3495;stop-opacity:1" />
<stop offset="100%" style="stop-color:#f3366a;stop-opacity:1" />
</linearGradient>
<clipPath id="circleView">
<circle cx="50vw" cy="-20vh" r="790px"/>
</clipPath>
</defs>

<circle cx="50vw" cy="-20vh" r="800px" fill="white" />
<circle cx="50vw" cy="-20vh" r="790px" fill="url(#grad1)" />
<image id="circleflimage" width="100vw" opacity="0.1" xlink:href="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Phinizy_swamp_nature_park_floodplain_in_hdr.jpg/1200px-Phinizy_swamp_nature_park_floodplain_in_hdr.jpg" clip-path="url(#circleView)"/>
</svg>
</div>

<div id="headercontent">
<div id="headerparent">
<div>
<h1 id="logo" class="whitetext">
Test
</h1>
</div>
<br>
<div id="headsocials">
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
</div>
</div>

</div>
</header>

CSS:

html{
margin: 0 !important;
padding: 0 !important;
height: 100%;
width: 100%;
}

body{
background: #161925;
height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: "moon2reg", "latolight", "calibri", sans-serif;
font-weight: normal;
font-size: 17px;
}

.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
height: 100%;
display: block;
}

header {
height: 700px;
max-height: 700px;
width: 100%;
position: relative;
margin: 0 auto;
display: flex;
justify-content:center;
align-items:center;
flex-wrap: wrap;
flex-direction: row;
}

#headerwhitecircle {
display: block;
margin: 0 auto;
text-align: center;
height: 100%;
max-height: 700px;
z-index: -1;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin-left:auto; margin-right:auto;
width: 100%;
}

#headercirclecont {
display: flex;
justify-content: center;
align-items: center;
}

#circleflimage {
margin: 0 auto;
text-align: center;
max-width: 100vw;
max-height: 700px;
}

#headercontent {
width: 100%;
max-width: 600px;
height: 100%;
max-height: 700px;
z-index: 1;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: 0 auto;
position: absolute;
display: flex;
flex-wrap: wrap;
flex-direction: row;
align-items:center;

}

#headerparent {
margin: 0 auto;
}

#logo {
width: 100%;
max-width: 600px;
z-index: 1;
}

#headsocials {
width: 100%;
height: 40px;
display: flex;
}

p.svgsocials {
position: relative;
display: inline-block;
width: 100%;
margin: 0 auto;
}

p.svgsocials:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}

h1 {
color: #161925;
margin: 0;
font-size: 80px;
font-weight: 100;
font-family: moon2reg calibri;
}

p {
color: #ffffff;
font-size: 30px;
margin: 5px;
}

.whitetext {
color: #ffffff;
}

.centertext {
text-align: center;
}

#titleTxt {
height: 100%;
max-height: 60px;
}

最佳答案

我认为您可能会遇到复杂的事情,因为您尝试使用 vwvh 等单位来控制 SVG 的行为,而不是使用 SVG viewBox 并利用 SVG 的内置响应功能。

当您切换到 viewBox 时,一切都会变得更加简单和容易。

在这里 fiddle :https://jsfiddle.net/150dr2bb/58/

@charset "UTF-8";
html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}button,[type="button"],[type="reset"],[type="submit"]{-webkit-appearance:button}button::-moz-focus-inner,[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}

html{
margin: 0 !important;
padding: 0 !important;
height: 100%;
width: 100%;
}

body{
background: #161925;
height: 100%;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: "moon2reg", "latolight", "calibri", sans-serif;
font-weight: normal;
font-size: 17px;
}

header {
width: 100%;
max-width: 1600px;
position: relative;
margin: 0 auto;
display: flex;
justify-content:center;
align-items:center;
flex-wrap: wrap;
flex-direction: row;
}

#headercirclecont {
display: absolute;
top: 0;
width: 100%;
height: 100%;
}

#headerwhitecircle {
width: 100%;
height: 100%;
min-height: 250px;
max-height: 700px;
}

#headercontent {
position: absolute;
top: 0;
height: 100%;
display: flex;
align-items: center;
}

#headerparent {
margin: 0 auto;
}

#logo {
width: 100%;
max-width: 600px;
z-index: 1;
}

#headsocials {
width: 100%;
height: 40px;
display: flex;
}

p.svgsocials {
position: relative;
display: inline-block;
width: 100%;
margin: 0 auto;
}

p.svgsocials:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}

h1 {
color: #161925;
margin: 0;
font-size: 80px;
font-weight: 100;
font-family: moon2reg calibri;
}

p {
color: #ffffff;
font-size: 30px;
margin: 5px;
}

.whitetext {
color: #ffffff;
}

.centertext {
text-align: center;
}

#titleTxt {
height: 100%;
max-height: 60px;
}
<header>
<div id="headercirclecont" style="text-align:center;">
<svg id="headerwhitecircle" viewBox="0 0 1600 700" preserveAspectRatio="xMidYMin slice">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:#7c3495;stop-opacity:1" />
<stop offset="100%" style="stop-color:#f3366a;stop-opacity:1" />
</linearGradient>
<clipPath id="circleView">
<circle cx="800" cy="-100" r="790px"/>
</clipPath>
</defs>

<circle cx="800" cy="-100" r="800px" fill="white" />
<circle cx="800" cy="-100" r="790px" fill="url(#grad1)" />
<image id="circleflimage" width="1600" height="700" preserveAspectRatio="xMidYMin slice"
opacity="0.1" xlink:href="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Phinizy_swamp_nature_park_floodplain_in_hdr.jpg/1200px-Phinizy_swamp_nature_park_floodplain_in_hdr.jpg" clip-path="url(#circleView)"/>
</svg>
</div>

<div id="headercontent">
<div id="headerparent">
<div>
<h1 id="logo" class="whitetext">
Test
</h1>
</div>
<br>
<div id="headsocials">
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
<p class="svgsocials">a</p>
</div>
</div>

</div>
</header>

关于html - 使用 SVG 形状创建响应式圆形标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49831522/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com