как собрать эти коробки вместе - PullRequest
0 голосов
/ 25 февраля 2020

enter image description here

Вот чего я хочу.

enter image description here

	.incisor-group{
		height: 50px;
	}
 <svg  class="incisor-group"
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink" width="300px" height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
        <!-- upper right 1 -->
        <g id="incisor-group">
            <rect x="75" y="75" stroke="black" id="incisal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
            <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 112.5 75 112.5" fill="white" />    
            <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 187.5 226 112.5" fill="white" />
            <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 187.5 225 187.5" fill="white" />
            <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 112.5 75 187.5" fill="white" />
        </g>
    </svg>
    <svg class="incisor-group"
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="300px" viewBox="0 0 400 300" preserveAspectRatio="xMidYMid meet">
        <!-- upper right 8 -->
        <g id="molar-group" class="molar">
            <rect x="75" y="75" stroke="black" id="disto-occlusal" style="stroke-width: 5px;" width="125" height="150" fill="white"/>
            <rect x="200" y="75" stroke="black" id="mesio-occlusal" style="stroke-width: 5px;" width="125" height="150" fill="white"/>
    
            <polygon stroke="black" id="disto-buccal" style="stroke-width: 5px;" points="0 0 200 0 200 75 75 75" fill="white" />
            <polygon stroke="black" id="mesio-buccal" style="stroke-width: 5px;" points="200 0 400 0 325 75 200 75" fill="white" />
    
            <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="400 0 400 300 325 225 325 75" fill="white" />
    
            <polygon stroke="black" id="mesio-palatal" style="stroke-width: 5px;" points="400 300 200 300 200 225 325 225" fill="white" />
            <polygon stroke="black" id="disto-palatal" style="stroke-width: 5px;" points="200 300 0 300 75 225 200 225" fill="white" />
    
            <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 75 75 225" fill="white" />
        </g>
    </svg>
    <svg class="incisor-group"
        xmlns="http://www.w3.org/2000/svg" 
        xmlns:xlink="http://www.w3.org/1999/xlink" width="300px" height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
        <!-- upper right 5 -->
        <g id="premolar-group">
            <rect x="75" y="75" stroke="black" id="occlusal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
            <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 75 75 75" fill="white" />
            <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 225 225 75" fill="white" />
            <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 225 225 225" fill="white" />
            <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 75 75 225" fill="white" />
        </g>
    </svg>

как собрать эти коробки вместе. Первая картина, которую я на самом деле сделал. Второе изображение - это вдохновляющее изображение, которое я хочу имитировать ....................................... .

Ответы [ 4 ]

2 голосов
/ 25 февраля 2020

Ваши <svg> элементы имеют атрибут фиксированной ширины, установленный на них, имеют более широкий контейнер, чем содержимое svg в пределах.

Установка width: auto; и разрешение высоты автоматически увеличиваться до максимума получат эти выстроились лучше.

.incisor-group {
   width: auto;
   max-height: 50px;
}
<svg  class="incisor-group"
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" width="300px" height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
    <!-- upper right 1 -->
    <g id="incisor-group">
        <rect x="75" y="75" stroke="black" id="incisal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
        <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 112.5 75 112.5" fill="white" />    
        <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 187.5 226 112.5" fill="white" />
        <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 187.5 225 187.5" fill="white" />
        <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 112.5 75 187.5" fill="white" />
    </g>
</svg>
<svg class="incisor-group"
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" width="400px" height="300px" viewBox="0 0 400 300" preserveAspectRatio="xMidYMid meet">
    <!-- upper right 8 -->
    <g id="molar-group" class="molar">
        <rect x="75" y="75" stroke="black" id="disto-occlusal" style="stroke-width: 5px;" width="125" height="150" fill="white"/>
        <rect x="200" y="75" stroke="black" id="mesio-occlusal" style="stroke-width: 5px;" width="125" height="150" fill="white"/>

        <polygon stroke="black" id="disto-buccal" style="stroke-width: 5px;" points="0 0 200 0 200 75 75 75" fill="white" />
        <polygon stroke="black" id="mesio-buccal" style="stroke-width: 5px;" points="200 0 400 0 325 75 200 75" fill="white" />

        <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="400 0 400 300 325 225 325 75" fill="white" />

        <polygon stroke="black" id="mesio-palatal" style="stroke-width: 5px;" points="400 300 200 300 200 225 325 225" fill="white" />
        <polygon stroke="black" id="disto-palatal" style="stroke-width: 5px;" points="200 300 0 300 75 225 200 225" fill="white" />

        <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 75 75 225" fill="white" />
    </g>
</svg>
<svg class="incisor-group"
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" width="300px" height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
    <!-- upper right 5 -->
    <g id="premolar-group">
        <rect x="75" y="75" stroke="black" id="occlusal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
        <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 75 75 75" fill="white" />
        <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 225 225 75" fill="white" />
        <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 225 225 225" fill="white" />
        <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 75 75 225" fill="white" />
    </g>
</svg>
0 голосов
/ 25 февраля 2020

Вот как бы я это сделал: у вас есть резцы, моляры и премоляры. Вам нужно будет повторить это несколько раз. Поэтому я создаю группу для каждого и помещаю ее в элемент <defs>. У каждой группы есть идентификатор, и вы можете использовать его с элементом <use>. Хорошая вещь об элементе <use> состоит в том, что вы можете задать ему позицию (x, y) и разместить ее там, где вам нужно.

Также я поместил полигоны в <defs>, думая, что, возможно, они понадобятся вам позже, чтобы отметить красные пятна (как в предыдущем вопросе)

Наблюдение: с svg точно так же, как с другими элементами DOM, вы должны сохранить уникальные id s.

Надеюсь, это поможет.

svg {
  border: solid;
}
svg polygon {
  stroke-width: 5px;
  stroke: black;
  fill: white;
  stroke-linejoin: round;
}
<svg viewBox="-10 -10 1040 320">
   <defs>
        <rect id="incisal" width="150" height="150" />
        <polygon id="buccal"  points="0 0 300 0 225 112.5 75 112.5" />    
        <polygon id="mesial"  points="300 0 300 300 225 187.5 226 112.5" />
        <polygon id="palatal" points="300 300 0 300 75 187.5 225 187.5"  />
        <polygon id="distal"  points="0 300 0 0 75 112.5 75 187.5"  />
        <rect id="disto-occlusal" width="125" height="150" />
        <rect id="mesio-occlusal" width="125" height="150" />
        <polygon id="disto-buccal" points="0 0 200 0 200 75 75 75" />
        <polygon id="mesio-buccal" points="200 0 400 0 325 75 200 75" />
        <polygon id="disto-palatal"  points="200 300 0 300 75 225 200 225" />
        <polygon id="mesio-palatal"  points="400 300 200 300 200 225 325 225" />
     
        <polygon id="distal_1" points="0 300 0 0 75 75 75 225" />
        <polygon id="mesial_1" points="400 0 400 300 325 225 325 75" />

        <rect id="disto-occlusal" width="125" height="150" />
        <rect id="mesio-occlusal" width="125" height="150" />
     
     
        <polygon id="buccal2"  points="0 0 300 0 225 75 75 75" />
        <polygon id="mesial2"  points="300 0 300 300 225 225 225 75"  />
        <polygon id="palatal2" points="300 300 0 300 75 225 225 225"  />
        <polygon id="distal2"  points="0 300 0 0 75 75 75 225"  />
     
     <g id="incisor-group">        
        <use xlink:href="#buccal" />    
        <use xlink:href="#mesial" />
        <use xlink:href="#palatal"  />
        <use xlink:href="#distal" />
    </g>
     
     <g id="molar-group" class="molar">
        <use xlink:href="#disto-buccal"  />
        <use xlink:href="#mesio-buccal"  />
        <use xlink:href="#mesial_1" />
        <use xlink:href="#mesio-palatal"  />
        <use xlink:href="#disto-palatal" />
        <use xlink:href="#distal_1" />
     </g>
     
     
     
     <g id="premolar-group">       
        <use xlink:href="#buccal2"  points="0 0 300 0 225 75 75 75" />
        <use xlink:href="#mesial2"  points="300 0 300 300 225 225 225 75"  />
        <use xlink:href="#palatal2" points="300 300 0 300 75 225 225 225"  />
        <use xlink:href="#distal2"  points="0 300 0 0 75 75 75 225"  />
    </g>
   </defs>
   
   
   
   
    <use xlink:href="#incisor-group"/>
    <use x="310" xlink:href="#molar-group"/>
    <use x="720" xlink:href="#premolar-group"/>

   
   </svg>
0 голосов
/ 25 февраля 2020

удалить атрибут ширины из всех тегов svg

.incisor-group{
  height: 50px;
}
<svg  class="incisor-group"
      xmlns="http://www.w3.org/2000/svg"
      style="margin: 2px"
      xmlns:xlink="http://www.w3.org/1999/xlink"  height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
  <!-- upper right 1 -->
  <g id="incisor-group">
    <rect x="75" y="75" stroke="black" id="incisal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
    <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 112.5 75 112.5" fill="white" />
    <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 187.5 226 112.5" fill="white" />
    <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 187.5 225 187.5" fill="white" />
    <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 112.5 75 187.5" fill="white" />
  </g>
</svg>
<svg  class="incisor-group"
      xmlns="http://www.w3.org/2000/svg"
      style="margin: 2px"
      xmlns:xlink="http://www.w3.org/1999/xlink"  height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
  <!-- upper right 1 -->
  <g id="incisor-group">
    <rect x="75" y="75" stroke="black" id="incisal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
    <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 112.5 75 112.5" fill="white" />
    <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 187.5 226 112.5" fill="white" />
    <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 187.5 225 187.5" fill="white" />
    <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 112.5 75 187.5" fill="white" />
  </g>
</svg>
<svg  class="incisor-group"
      xmlns="http://www.w3.org/2000/svg"
      style="margin: 2px"
      xmlns:xlink="http://www.w3.org/1999/xlink"  height="300px" viewBox="0 0 300 300" preserveAspectRatio="xMidYMid meet">
  <!-- upper right 1 -->
  <g id="incisor-group">
    <rect x="75" y="75" stroke="black" id="incisal" style="stroke-width: 5px;" width="150" height="150" fill="white"/>
    <polygon stroke="black" id="buccal" style="stroke-width: 5px;" points="0 0 300 0 225 112.5 75 112.5" fill="white" />
    <polygon stroke="black" id="mesial" style="stroke-width: 5px;" points="300 0 300 300 225 187.5 226 112.5" fill="white" />
    <polygon stroke="black" id="palatal" style="stroke-width: 5px;" points="300 300 0 300 75 187.5 225 187.5" fill="white" />
    <polygon stroke="black" id="distal" style="stroke-width: 5px;" points="0 300 0 0 75 112.5 75 187.5" fill="white" />
  </g>
</svg>
0 голосов
/ 25 февраля 2020

вы можете поставить width: auto в .incisor-group класс

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...